|
49 | 49 | paste("Sample size 5: mean = ", |
50 | 50 | round(mean(t1$meancol)), |
51 | 51 | "; stdev = ", |
52 | | - round(sqrt(var(t1$meancol))),sep="")->lab |
| 52 | + round(sd(t1$meancol)),sep="")->lab |
53 | 53 | p+annotate("text",x=450,y=0.030,label=lab,colour="blue")->p |
54 | 54 | p |
55 | 55 |
|
|
67 | 67 | paste("Sample size 20: mean = ", |
68 | 68 | round(mean(t0$meancol)), |
69 | 69 | "; stdev = ", |
70 | | - round(sqrt(var(t0$meancol))),sep="")->lab |
| 70 | + round(sd(t0$meancol)),sep="")->lab |
71 | 71 | p+annotate("text",x=450,y=0.033,label=lab,colour="darkolivegreen")->p |
72 | 72 | p |
73 | 73 |
|
|
85 | 85 | paste("Sample size 50: mean = ", |
86 | 86 | round(mean(t$meancol)), |
87 | 87 | "; stdev = ", |
88 | | - round(sqrt(var(t$meancol))),sep="")->lab |
| 88 | + round(sd(t$meancol)),sep="")->lab |
89 | 89 | p+annotate("text",x=450,y=0.036,label=lab,colour="red")->p |
90 | 90 | p |
91 | 91 |
|
|
103 | 103 | paste("Sample size 200: mean = ", |
104 | 104 | round(mean(t4$meancol)), |
105 | 105 | "; stdev = ", |
106 | | - round(sqrt(var(t4$meancol))),sep="")->lab |
| 106 | + round(sd(t4$meancol)),sep="")->lab |
107 | 107 | p+annotate("text",x=450,y=0.039,label=lab,colour="pink")->p |
108 | 108 | p |
109 | 109 | #+end_src |
|
113 | 113 | + $Standard.error = \frac{\sigma}{\sqrt{mean}}$ |
114 | 114 |
|
115 | 115 |
|
116 | | - |
117 | | -| Standard deviation of population ($\sigma$) | 130 | |
118 | | -| Standard errors of samples of size | | |
119 | | -| 5 | 58 | |
120 | | -| 20 | 29 | |
121 | | -| 50 | 18 | |
122 | | -| 200 | 9 | |
| 116 | +| Variable | Value | |
| 117 | +|---------------------------------------------+-------| |
| 118 | +| Standard deviation of population ($\sigma$) | 130 | |
| 119 | +| Standard errors of samples of size | | |
| 120 | +| 5 | 58 | |
| 121 | +| 20 | 29 | |
| 122 | +| 50 | 18 | |
| 123 | +| 200 | 9 | |
123 | 124 |
|
124 | 125 |
|
125 | 126 |
|
|
140 | 141 | library(ggplot2) |
141 | 142 |
|
142 | 143 | worker->t9 |
143 | | - (t9$wage-mean(t9$wage))/sqrt(var(t9$wage))->t9$wage |
| 144 | + (t9$wage-mean(t9$wage))/sd(t9$wage)->t9$wage |
144 | 145 | ggplot(t9,aes(wage))+geom_density(colour="black",size=1)->p |
145 | 146 | p+scale_y_continuous(limits=c(0,0.75))->p |
146 | 147 | p+scale_x_continuous(limits=c(-15,15) |
|
159 | 160 | c(t1,mean(s1$wage))->t1 |
160 | 161 | } |
161 | 162 |
|
162 | | - data.frame(sno=c(1:10000),meancol=(t1-mean(worker$wage))/sqrt(var(t1)))->t1 |
| 163 | + data.frame(sno=c(1:10000),meancol=(t1-mean(worker$wage))/sd(t1))->t1 |
163 | 164 | p+geom_density(data=t1,aes(meancol),colour="blue",size=1)-> p |
164 | 165 | p |
165 | 166 |
|
|
172 | 173 | c(t0,mean(s1$wage))->t0 |
173 | 174 | } |
174 | 175 |
|
175 | | - data.frame(sno=c(1:10000),meancol=(t0-mean(worker$wage))/sqrt(var(t0)))->t0 |
| 176 | + data.frame(sno=c(1:10000),meancol=(t0-mean(worker$wage))/sd(t0))->t0 |
176 | 177 | p+geom_density(data=t0,aes(meancol),colour="darkolivegreen",size=1)-> p |
177 | 178 | p |
178 | 179 |
|
|
185 | 186 | c(t,mean(s1$wage))->t |
186 | 187 | } |
187 | 188 |
|
188 | | - data.frame(sno=c(1:10000),meancol=(t-mean(worker$wage))/sqrt(var(t)))->t |
| 189 | + data.frame(sno=c(1:10000),meancol=(t-mean(worker$wage))/sd(t))->t |
189 | 190 | p+geom_density(data=t,aes(meancol),colour="red",size=1)-> p |
190 | 191 | p |
191 | 192 |
|
|
198 | 199 | c(t4,mean(s1$wage))->t4 |
199 | 200 | } |
200 | 201 |
|
201 | | - data.frame(sno=c(1:10000),meancol=(t4-mean(worker$wage))/sqrt(var(t4)))->t4 |
| 202 | + data.frame(sno=c(1:10000),meancol=(t4-mean(worker$wage))/sd(t4))->t4 |
202 | 203 | p+geom_density(data=t4,aes(meancol),colour="pink",size=1)-> p |
203 | 204 | p |
204 | 205 | #+end_src |
|
220 | 221 | worker[sex!=3,]->worker |
221 | 222 |
|
222 | 223 | worker->t9 |
223 | | - (t9$wage-mean(t9$wage))/sqrt(var(t9$wage))->t9$wage |
| 224 | + (t9$wage-mean(t9$wage))/sd(t9$wage)->t9$wage |
224 | 225 | ggplot(t9,aes(wage))+geom_density(colour="black",size=1)->p |
225 | 226 | p+scale_y_continuous(limits=c(0,0.75))->p |
226 | 227 | p+scale_x_continuous(limits=c(-15,15) |
|
236 | 237 | rbind(t4,data.frame( |
237 | 238 | sno=i, |
238 | 239 | meancol=mean(s1$wage), |
239 | | - sterr=sqrt(var(s1$wage))/sqrt(samplesize) |
| 240 | + sterr=sd(s1$wage)/sqrt(samplesize) |
240 | 241 | ) |
241 | 242 | )->t4 |
242 | 243 | } |
243 | 244 |
|
244 | 245 | (t4$meancol)/t4$sterr->t4$teststat |
245 | | - (t4$meancol)/sqrt(var(t4$meancol))->t4$teststat2 |
| 246 | + (t4$meancol)/sd(t4$meancol)->t4$teststat2 |
246 | 247 | data.frame(modelt=rt(200000,samplesize-1,ncp=mean(t4$teststat)),modelnorm=rnorm(200000,mean=mean(t4$teststat2)))->m |
247 | 248 |
|
248 | | - var(t4$teststat) |
249 | | - var(m$modelt) |
250 | | - var(m$modelnorm) |
251 | | - var(t4$teststat2) |
| 249 | + sd(t4$teststat) |
| 250 | + sd(m$modelt) |
| 251 | + sd(m$modelnorm) |
| 252 | + sd(t4$teststat2) |
252 | 253 | mean(t4$teststat) |
253 | 254 | mean(m$modelt) |
254 | 255 | mean(m$modelnorm) |
|
260 | 261 | p+geom_density(data=t4,aes(teststat),colour="blue",size=1)-> p |
261 | 262 | p+geom_density(data=m,aes(modelt),colour="darkolivegreen",size=1)->p |
262 | 263 | p+annotate("text",x=-30,y=0.42, |
263 | | - label=paste("Normal distribution, with standard deviation",round(sqrt(var(m$modelnorm)),2)), |
| 264 | + label=paste("Normal distribution, with standard deviation",round(sd(m$modelnorm),2)), |
264 | 265 | colour="black",hjust=0)->p |
265 | 266 | p+annotate("text",x=-30,y=0.40, |
266 | 267 | label=paste("Statistic with known population variance, standard error =", |
267 | | - round(sqrt(var(t4$teststat2)),2)), |
| 268 | + round(sd(t4$teststat2),2)), |
268 | 269 | colour="red",hjust=0)->p |
269 | 270 | p+annotate("text",x=-30,y=0.38, |
270 | | - label=paste("t distribution, with standard deviation =",round(sqrt(var(m$modelt)),2)), |
| 271 | + label=paste("t distribution, with standard deviation =",round(sd(m$modelt),2)), |
271 | 272 | colour="darkolivegreen",hjust=0)->p |
272 | 273 | p+annotate("text",x=-30,y=0.36, |
273 | 274 | label=paste("Statistic with unknown population variance, standard error =", |
274 | | - round(sqrt(var(t4$teststat)),2)), |
| 275 | + round(sd(t4$teststat),2)), |
275 | 276 | colour="blue",hjust=0)->p |
276 | 277 | p+scale_x_continuous(limits=c(-30,30))+theme_bw()->p |
277 | 278 | p |
|
0 commit comments