Task 1

getwd()
## [1] "C:/Users/Caleb/Documents/Civil Engineering degree coursework/Applied Statistical Methods/Labs/Lab 6"

Task 2

layout(matrix(1:4, nr=2,nc=2))

curve(dnorm(x, mean=10,sd=4),xlim=c(10-3*4,10+3*4))

curve(dnorm(x, mean=10,sd=2),xlim=c(10-3*2,10+3*2))

curve(dnorm(x, mean=5,sd=10),xlim=c(5-3*10,5+3*10))

curve(dnorm(x, mean=5,sd=0.5),xlim=c(5-3*0.5,5+3*0.5))

curve(dnorm(x,0,1), xlim=c(0-3*1, 0+3*1))
xcurve=seq(0-3*1,2,length=1000)
ycurve=dnorm(xcurve,0,1)
polygon(c(0-3*1,xcurve,2),c(0,ycurve,0),col="Red")
area=pnorm(2,0,1)
areap=round(area,4)
text(0,0.5*dnorm(0,0,1),paste0("Area= ",areap))

curve(dnorm(x,4,2), xlim=c(4-3*2, 4+3*2))
xcurve=seq(1,5,length=1000)
ycurve=dnorm(xcurve,4,2)
polygon(c(1,xcurve,5),c(0,ycurve,0),col="Red")
area=pnorm(5,4,2)-pnorm(1,4,2)
areap=round(area,4)
text(4,0.5*dnorm(4,4,2),paste0("Area= ",areap))

curve(dnorm(x,10,4), xlim=c(10-3*4, 10+3*4))
xcurve=seq(10-3*4,10,length=1000)
ycurve=dnorm(xcurve,10,4)
polygon(c(10-3*4,xcurve,10),c(0,ycurve,0),col="Red")
area=pnorm(10,10,4)
areap=round(area,4)
text(10,0.5*dnorm(10,10,4),paste0("Area= ",areap))

curve(dnorm(x,-2,0.5), xlim=c(-2-3*0.5, -2+3*0.5))
xcurve=seq(-3,-2,length=1000)
ycurve=dnorm(xcurve,-2,0.5)
polygon(c(-3,xcurve,-2),c(0,ycurve,0),col="Red")
area=pnorm(-2,-2,0.5)-pnorm(-3,-2,0.5)
areap=round(area,4)
text(-2,0.5*dnorm(-2,-2,0.5),paste0("Area= ",areap))

Task 3

curve(dgamma(x,shape=1,scale=1),xlim=c(-0.5,10),ylim=c(0,1),col="Red",lwd=2,
ylab="Gamma density", main="Beta=1")
text(1.5,0.8,paste("alpha=",1))
curve(dgamma(x,shape=3,scale=1),xlim=c(-0.5,10),ylim=c(0,1),add=TRUE,lwd=2)
text(2.5,0.35,paste("alpha=",3))
curve(dgamma(x,shape=5,scale=1),xlim=c(-0.5,10),ylim=c(0,1),add=TRUE, col="Blue",lwd=2)
text(5.2,0.28,paste("alpha=",5))

curve(dgamma(x,shape=3,scale=2),xlim=c(-0.5,20))
xcurve=seq(2,5,length=1000)
ycurve=dgamma(xcurve,shape=3,scale=2)
polygon(c(2,xcurve,5),c(0,ycurve,0),col="Red")
area=pgamma(5,shape=3,scale=2)-pgamma(2,shape=3,scale=2)
areap=round(area,4)
text(10,0.5*dgamma(3,shape=3,scale=2),paste0("Area= ",areap))

curve(dgamma(x,shape=6,scale=3),xlim=c(-0.5,10))
xcurve=seq(1,4,length=1000)
ycurve=dgamma(xcurve,shape=6,scale=3)
polygon(c(1,xcurve,4),c(0,ycurve,0),col="Red")
area=pgamma(4,shape=6,scale=3)-pgamma(1,shape=6,scale=3)
areap=round(area,4)
text(5,0.75*dgamma(6,shape=6,scale=3),paste0("Area= ",areap))

curve(dgamma(x,shape=2,scale=4),xlim=c(-0.5,20))
xcurve=seq(3,6,length=1000)
ycurve=dgamma(xcurve,shape=2,scale=4)
polygon(c(3,xcurve,6),c(0,ycurve,0),col="Red")
area=pgamma(6,shape=2,scale=4)-pgamma(3,shape=2,scale=4)
areap=round(area,4)
text(10,0.25*dgamma(2,shape=2,scale=4),paste0("Area= ",areap))

Task 4

layout(matrix(1:4, nr=2,nc=2))
curve(dchisq(x,df=1),xlim=c(0,10),ylab="Chisq density", main="df=1")

curve(dchisq(x,df=2),xlim=c(0,10),ylab="Chisq density", main="df=2")

curve(dchisq(x,df=4),xlim=c(0,15),ylab="Chisq density", main="df=4")

curve(dchisq(x,df=20),xlim=c(7,35),ylab="Chisq density", main="df=20")

curve(dchisq(x,df=2),xlim=c(-0.5,20))
xcurve=seq(2,4,length=1000)
ycurve=dchisq(xcurve,df=2)
polygon(c(2,xcurve,4),c(0,ycurve,0),col="Red")
area=pchisq(4,df=2)-pchisq(2,df=2)
areap=round(area,4)
text(10,0.5*dchisq(2,df=2),paste0("Area= ",areap))

curve(dchisq(x,df=3),xlim=c(-0.5,20))
xcurve=seq(3,5,length=1000)
ycurve=dchisq(xcurve,df=3)
polygon(c(3,xcurve,5),c(0,ycurve,0),col="Red")
area=pchisq(5,df=3)-pchisq(3,df=3)
areap=round(area,4)
text(10,0.5*dchisq(3,df=3),paste0("Area= ",areap))

curve(dchisq(x,df=20),xlim=c(0,35))
xcurve=seq(10,21,length=1000)
ycurve=dchisq(xcurve,df=20)
polygon(c(10,xcurve,21),c(0,ycurve,0),col="Red")
area=pchisq(21,df=20)-pchisq(10,df=20)
areap=round(area,4)
text(10,0.5*dchisq(20,df=20),paste0("Area= ",areap))

Task 5

layout(matrix(1:4, nr=2,nc=2))

curve(dweibull(x, shape=10,scale=4),xlim=c(0,5))

curve(dweibull(x, shape=10,scale=2),xlim=c(0,3))

curve(dweibull(x, shape=5,scale=10),xlim=c(0,15))

curve(dweibull(x,shape=5,scale=0.5),xlim=c(0,1))

curve(dweibull(x,shape=1,scale=1), xlim=c(-0.5, 1+3*1))
xcurve=seq(1-3*1,2,length=1000)
ycurve=dweibull(xcurve,shape=1,scale=1)
polygon(c(1-3*1,xcurve,2),c(0,ycurve,0),col="Red")
area=pweibull(2,shape=1,scale=1)
areap=round(area,4)
text(0.5,0.5*dweibull(1,shape=1,scale=1),paste0("Area= ",areap))

curve(dweibull(x,shape=4,scale=2), xlim=c(0, 4))
xcurve=seq(1,5,length=1000)
ycurve=dweibull(xcurve,shape=4,scale=2)
polygon(c(1,xcurve,5),c(0,ycurve,0),col="Red")
area=pweibull(5,shape=4,scale=2)-pweibull(1,shape=4,scale=2)
areap=round(area,4)
text(1.5,0.3,paste0("Area= ",areap))

curve(dweibull(x,shape=2,scale=1), xlim=c(-1, 4))
xcurve=seq(0,1.5,length=1000)
ycurve=dweibull(xcurve,shape=2,scale=1)
polygon(c(0,xcurve,1.5),c(0,ycurve,0),col="Red")
area=pweibull(1.5,shape=2,scale=1)-pweibull(0,shape=2,scale=1)
areap=round(area,4)
text(1,0.5*dnorm(-2,-2,0.5),paste0("Area= ",areap))

Task 6

layout(matrix(1:4, nr=2,nc=2))

curve(dbeta(x, 10,4),xlim=c(0,1))

curve(dbeta(x, 10,2),xlim=c(0,1))

curve(dbeta(x, 5,10),xlim=c(0,1))

curve(dbeta(x,5,0.5),xlim=c(0,1))

curve(dbeta(x,1,1), xlim=c(-0.5, 1.5))
xcurve=seq(0.7,0.83,length=1000)
ycurve=dbeta(xcurve,1,1)
polygon(c(0.7,xcurve,0.83),c(0,ycurve,0),col="Red")
area=pbeta(0.83,1,1)-pbeta(0.7,1,1)
areap=round(area,4)
text(0.3,0.5*dbeta(1,1,1),paste0("Area= ",areap))

curve(dbeta(x,4,2), xlim=c(0, 1.5))
xcurve=seq(0,0.3,length=1000)
ycurve=dbeta(xcurve,4,2)
polygon(c(0,xcurve,0.3),c(0,ycurve,0),col="Red")
area=pbeta(0.3,4,2)-pbeta(0,4,2)
areap=round(area,4)
text(0.6,0.4,paste0("Area= ",areap))

curve(dbeta(x,2,1), xlim=c(0, 1.5))
xcurve=seq(0.2,0.5,length=1000)
ycurve=dbeta(xcurve,2,1)
polygon(c(0.2,xcurve,0.5),c(0,ycurve,0),col="Red")
area=pbeta(0.5,2,1)-pbeta(0.2,2,1)
areap=round(area,4)
text(0.75,0.5,paste0("Area= ",areap))

Task 7

MATH4753GRAY::myncurve(10,5,6)

## [[1]]
## [1] 0.2118554