Question: R code help 5. Matching the sample and theoretical densities. Finally, let's see how well your random sample matches the theoretical density. A histogram of
R code help
5. Matching the sample and theoretical densities.
Finally, let's see how well your random sample matches the theoretical density. A histogram of your sample (with green bars and density scaling)
n<-100000 count<-0 x<-rnorm(n,16.1,0.5) for(i in 1:n){ if(x[i]>=16 && x[i]<=16.5) count=count+1 } count/n simNorm<-quantile(x,0.10) hist(simNorm, probability=TRUE, col="green") Now add the normal pdf on top. Range is plus/minus 4 stadnard deviations around mean.
xValues<- seq(16.1 - 4*.5, 16.1 + 4*.5, length.out=250) pdf<- dnorm(xValues, mean=16.1, sd=.5) lines(xValues, pdf, col="grey",lwd=2 ) # grey line twice the width Comment on how well your sample histogram tracks the density curve. Where does it do well? What does it miss?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
