6.6 2010 Healthcare Law

6.12 Legalization of marijuana, Part I.

se <-  sqrt((.5)*.5/1259)
paste("Se= ",round(se,3))
## [1] "Se=  0.014"
upper <- .48+ 1.96*se
lower <- .48-1.96*se
paste("our confidence interval is",lower,"-",upper)
## [1] "our confidence interval is 0.452380665449998 - 0.507619334550002"

6.20 Legalize Marijuana, Part II

\(N= Z^2*.48*.52/ ME^2\)

n=1.96^2*.48*.52/.02^2
paste (n)
## [1] "2397.1584"

6.28 Sleep deprivation, CA vs. OR, Part I.

N_1= 11545
P_1=.08
N_2= 4691
P_2= .088
z=1.96

se <-  sqrt( ((.08)*(1-.08)/11545)+((.088)*(1-.088)/4691))
upper <- .008+ 1.96*se
lower <- .008-1.96*se
paste("our confidence interval is",round(lower*100,3),"% to",round(upper*100,3),"%")
## [1] "our confidence interval is -0.15 % to 1.75 %"

6.44 Barking Deer

type Woods grass Deciduous Other
actual count 4 16 67 345
null pct 4.8 14.7 39.6 40.9
null count 20 63 169 174
percents <- c(.048,.147,.396,(1-.048-.147-.396))
null <- round(percents*426,0)
print (null)
## [1]  20  63 169 174

C. conditions are as follows

percents <- c(.048,.147,.396,(1-.048-.147-.396))
actual <- c(4,16,67,345)
null <- round(percents*426,0)
deers = as.data.frame(rbind(actual, null))
names(deers) = c('Woods','grass','Deciduous','Other') 
short_hand_x_squared <- chisq.test(deers,correct = TRUE)

long_hand_x_squared <- sum((actual-null)^2/null)

paste("with predefined function",short_hand_x_squared[1], " chi^2 by hand", long_hand_x_squared)
## [1] "with predefined function 139.019318509426  chi^2 by hand 277.477346378938"

6.48 Coffee and Depression

\(H_A\) there is an association between coffee intake and depression

2607/50739
## [1] 0.05138059
expected <- 6617*.0513
actual <- 373

chi_sq <- (actual-expected)^2/expected

paste("expected value count is ",expected," the chi square value is ",chi_sq)
## [1] "expected value count is  339.4521  the chi square value is  3.31552402948752"
C <- 5
R <- 2

df <- (R-1)*(C-1)
chi2 <- 20.93

p_value <- 1 - pchisq(chi2, df)