|
|
|
@ -278,69 +278,3 @@
|
|
|
|
|
#+end_src
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
** Introduction to the t distribution :ignore:
|
|
|
|
|
|
|
|
|
|
#+RESULTS: sampling4
|
|
|
|
|
[[file:bsample4.png]]
|
|
|
|
|
|
|
|
|
|
#+NAME: sampling4
|
|
|
|
|
#+BEGIN_SRC R :results output graphics :exports results :file bsample4.png :width 2500 :height 2000 :res 300
|
|
|
|
|
library(data.table)
|
|
|
|
|
library(ggplot2)
|
|
|
|
|
options(scipen=9999)
|
|
|
|
|
readRDS("plfsdata/plfsacjdata.rds")->worker
|
|
|
|
|
worker$standardwage->worker$wage
|
|
|
|
|
c(1:nrow(worker))->worker$SamplingFrameOrder
|
|
|
|
|
worker[sex!=3,]->worker
|
|
|
|
|
|
|
|
|
|
worker->t9
|
|
|
|
|
(t9$wage-mean(t9$wage))/sqrt(var(t9$wage))->t9$wage
|
|
|
|
|
ggplot(t9,aes(wage))+geom_density(colour="black",size=1)->p
|
|
|
|
|
p+scale_y_continuous(limits=c(0,0.75))->p
|
|
|
|
|
p+scale_x_continuous(limits=c(-15,15)
|
|
|
|
|
,breaks=c(-15,0,round(mean(worker$wage)),15))->p
|
|
|
|
|
p+theme_bw()->p
|
|
|
|
|
p
|
|
|
|
|
|
|
|
|
|
data.frame(sno=c(),meancol=c(),sterr=c())->t4
|
|
|
|
|
samplesize=50
|
|
|
|
|
for (i in c(1:20000)) {
|
|
|
|
|
sample(1:nrow(worker),samplesize, replace=FALSE)->a1
|
|
|
|
|
worker[a1,]->s1
|
|
|
|
|
rbind(t4,data.frame(
|
|
|
|
|
sno=i,
|
|
|
|
|
meancol=mean(s1$wage),
|
|
|
|
|
sterr=sqrt(var(s1$wage))/sqrt(samplesize)))->t4
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
(t4$meancol-mean(t4$meancol))/t4$sterr->t4$teststat
|
|
|
|
|
(t4$meancol-mean(t4$meancol))/sqrt(var(t4$meancol))->t4$teststat2
|
|
|
|
|
data.frame(modelt=rt(20000,29))->m
|
|
|
|
|
|
|
|
|
|
var(t4$teststat)
|
|
|
|
|
var(m$modelt)
|
|
|
|
|
var(t4$teststat2)
|
|
|
|
|
|
|
|
|
|
ggplot()->p
|
|
|
|
|
p+geom_density(data=t4,aes(teststat),colour="blue",size=1)-> p
|
|
|
|
|
p+geom_density(data=m,aes(modelt),colour="darkolivegreen",size=1)->p
|
|
|
|
|
p+geom_density(data=t4,aes(teststat2),colour="red",size=1)-> p
|
|
|
|
|
p+annotate("text",x=3,y=0.4,
|
|
|
|
|
label=paste("Var of statistic with unknown variance:",
|
|
|
|
|
round(var(t4$teststat),2)),
|
|
|
|
|
colour="blue")->p
|
|
|
|
|
p+annotate("text",x=3,y=0.39,
|
|
|
|
|
label=paste("Var of statistic with known variance:",
|
|
|
|
|
round(var(t4$teststat2),2)),
|
|
|
|
|
colour="red")->p
|
|
|
|
|
p+annotate("text",x=3,y=0.38,
|
|
|
|
|
label=paste("Var of t-distribution:",round(var(m$modelt),2)),
|
|
|
|
|
colour="darkolivegreen")->p
|
|
|
|
|
p
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#+end_src
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|