Chapter 6. Sampling#
Figure 6.1: Sampling and Inference#
suppressPackageStartupMessages(library(spatstat))
suppressPackageStartupMessages(library(diagram))
plot.new()
plot.window(c(-8.5,5),c(-5,5))
W1 <- ellipse(a=2.5,b=2,centre=c(-6,0),phi=0,npoly=1024)
plot(W1,add=TRUE)
W2 <- ellipse(a=2.5,b=2,centre=c(3,0),phi=0,npoly=1024)
plot(W2,add=TRUE)
text(-6.5,-1,"a",cex=.6)
text(-7,1.1,"b",cex=.6)
text(-5,1.2,"c",cex=.6)
text(-4,0,"d",cex=.6)
text(-6,-1.5,"e",cex=.6)
text(-6.5,0.5,"f",cex=.6)
text(-8.2,.5,"g",cex=.6)
text(-5,0.6,"h",cex=.6)
text(-6.2,1.2,"i",cex=.6)
text(-7,1.5,"j",cex=.6)
text(-8,-.5,"k",cex=.6)
text(-5.8,0.8,"l",cex=.6)
text(-7,-1.1,"m",cex=.6)
text(-7.5,1,"n",cex=.6)
text(-5,-1,"o",cex=.6)
text(-6.8,-.3,"p",cex=.6)
text(-5.5,-.2,"q",cex=.6)
text(-4.7,-.8,"r",cex=.6)
text(-6.2,1.8,"s",cex=.6)
text(-7.5,.2,"t",cex=.6)
text(-4.3,.5,"u",cex=.6)
text(-4.5,-.2,"v",cex=.6)
text(-4.3,-.7,"w",cex=.6)
text(-5.3,1.5,"x",cex=.6)
text(-6.3,-.1,"y",cex=.6)
text(-6.1,-.6,"z",cex=.6)
text(2,1.1,"b",cex=.6)
text(3,-1.5,"e",cex=.6)
text(4,0.6,"h",cex=.6)
text(2,-1.1,"m",cex=.6)
text(5.7,.5,"u",cex=.6)
text(3.7,1.5,"x",cex=.6)
arrows(-3.5,1,0.5,1,angle=20,length=.1)
arrows(0.5,-1,-3.5,-1,angle=20,length=.1)
text(-6,3,"Population",cex=.75)
text(3,3,"Sample",cex=.75)
text(-1.6,1.3,"Sampling",cex=.75)
text(-1.4,-1.3,"Inference",cex=.75)
Table 6.1 Table 6.1: Observations From CPS Data Set#
dat <- read.table("cps09mar.txt")
experience <- dat[,1]-dat[,4]-6
mbf <- (dat[,11]==2)&(dat[,12]<=2)&(dat[,2]==1)&(experience==12)
dat1 <- dat[mbf,]
wage <- as.matrix(dat1[,5]/(dat1[,6]*dat1[,7]))
lwage <- log(wage)
education <- dat1[,4]
n <- length(wage)
df <- data.frame(wage, education)
print(df)
wage education
1 37.92735 18
2 40.86538 18
3 14.18269 13
4 16.82692 16
5 33.17308 16
6 29.80769 18
7 54.61538 16
8 43.07692 18
9 14.42308 12
10 14.90385 16
11 21.63462 18
12 11.09467 16
13 10.00000 13
14 31.73077 14
15 11.05769 12
16 18.75000 16
17 27.35043 14
18 24.03846 16
19 36.05769 18
20 23.07692 16
Other Empirical Illustrations in Chapter 6#
mwage <- mean(wage)
mlwage <- mean(lwage)
meducation <- mean(education)
vwage <- mean((wage-mwage)^2)
vlwage <- mean((lwage-mlwage)^2)
veducation <- mean((education-meducation)^2)
swage <- sqrt(vwage)
slwage <- sqrt(vlwage)
seducation <- sqrt(veducation)
uswage <- sd(wage)
uslwage <- sd(lwage)
useducation <- sd(education)
sewage <- uswage/sqrt(n)
seeducation <- useducation/sqrt(n)
c <- cov(wage,education)
corr <- c/uswage/useducation
gmean <- exp(mlwage)
medwage <- median(wage)
cat("Sample size, mean wage, mean log(wage), mean education \n")
print(n)
print(mwage)
print(mlwage)
print(meducation)
Sample size, mean wage, mean log(wage), mean education
[1] 20
[1] 25.72968
[1] 3.131925
[1] 15.7
cat("Standard deviation: wage, log(wage), education \n")
print(swage)
print(slwage)
print(seducation)
Standard deviation: wage, log(wage), education
[1] 12.1252
[1] 0.4901793
[1] 2.002498
cat("Geometric mean, median\n")
print(gmean)
print(medwage)
Geometric mean, median
[1] 22.91806
[1] 23.55769
cat("Unbiased Standard deviation: wage, log(wage), education \n")
print(uswage)
print(uslwage)
print(useducation)
Unbiased Standard deviation: wage, log(wage), education
[1] 12.4402
[1] 0.5029133
[1] 2.05452
cat("s.e. of mean estimator: wage, education \n")
print(sewage)
print(seeducation)
s.e. of mean estimator: wage, education
[1] 2.781713
[1] 0.4594046
cat("covariance,correlation \n")
print(c)
print(corr)
covariance,correlation
[,1]
[1,] 14.76231
[,1]
[1,] 0.5775859