In: Statistics and Probability
1)Using R, construct one plot of the density function for a uniformly distributed continuous random variable defined between 0 and 6.
Make sure you include a main title, label both axis correctly and include a legend in your figure.
The main title needs to include your last name, also include your R code with your answer.
2) Using R, construct one plot of the density function for a Chi-square distributed random variable.
The plots should contain six lines corresponding to the following degrees of freedom1, 2, 3, 4, 6, 10.
Make sure you include a main title, label both axiscorrectlyand include a legend in your figure.
The main title needs to include your last name, also include your R code with your answer.
1) Let
R code for the plot is
#part 1) Uniform distribution
curve(dunif(x,0,6),from=0,to=6,main="Density of Uniform(0,6)
distribution:Your name",ylab="Density")
legend("topright",c("Uniform(0,6)"),lty=1,col=1)
# get this
2) Chi-square distribution for , where df is the degrees of freedom
R code with a legend
#part 2)
#plot chisquare(1)
curve(dchisq(x,1),from=0,to=10,ylim=c(0,0.5),main="Density of
Chi-Square distribution:Your name",ylab="Density")
#add other graphs to the same plot
for (df in c(2, 3, 4, 6, 10)) {
curve(dchisq(x,df),from=0,to=10,add=TRUE,col=df,lty=df)
}
legend("topright",c(paste("df=",c(1,2, 3, 4, 6, 10))),col=c(1,2, 3,
4, 6, 10),lty=c(1,2, 3, 4, 6, 10))
# get this
all code together
----
#part 1) Uniform distribution
curve(dunif(x,0,6),from=0,to=6,main="Density of Uniform(0,6)
distribution:Your name",ylab="Density")
legend("topright",c("Uniform(0,6)"),lty=1,col=1)
#part 2)
#plot chisquare(1)
curve(dchisq(x,1),from=0,to=10,ylim=c(0,0.5),main="Density of
Chi-Square distribution:Your name",ylab="Density")
#add other graphs to the same plot
for (df in c(2, 3, 4, 6, 10)) {
curve(dchisq(x,df),from=0,to=10,add=TRUE,col=df,lty=df)
}
legend("topright",c(paste("df=",c(1,2, 3, 4, 6, 10))),col=c(1,2, 3,
4, 6, 10),lty=c(1,2, 3, 4, 6, 10))
-----------------