Goto Lab: | #0 | #1 | #2 | #3 | #4 | #5 | #6 |
This assignment contains homework problems out of the text as well as a lab portion.
d1_pollution$city - pollution$rural bad_is.na(d1) d1_d1[!bad]Above, bad is a vector of T's or F's - T where d1 is NA, and F where d1 is a valid number. I can delete these NA's by selecting the components of d1 that not T's. The ! operator reverses the T's and F's in bad.
n_length(d1) bootmean_rep(NA,1000) for(i in 1:1000){ ib_sample(1:n,n,replace=T) bootmean[i]_mean(d1[ib]) } par(mfrow=c(1,1)) hist(bootmean,xlab="bootstrapped means") points(mean(d1),0,cex=2,pch=16) ci95_quantile(bootmean,c(.025,.975)) text(ci95,c(0,0),c("[","]"))Now ci95 is a vector of length 2 holding the upper and lower ends of the confidence interval.
d1_shoe$B - shoe$A n_length(d1)
pdif_rep(NA,1000) for(i in 1:1000){ isgn_sample(c(1,-1),n,replace=T) pdif[i]_mean(isgn*abs(d1)) }
par(mfrow=c(1,1)) hist(pdif,xlab="permutation means") points(mean(d1),0,cex=2,pch=16) text(0.2,154,paste("pval =",round(mean(pdif>=mean(d1)),2)),cex=2)