n <- 1259
p <- 0.48
SE <- sqrt((p * (1-p))/n)
me <- 1.96 * SE
me
## [1] 0.02759723
uppertail <- p + me
lowertail <- p - me
c(uppertail,lowertail)
## [1] 0.5075972 0.4524028
We are 95 percent confident that people who think Marijuana should be legalized are somewhere between 0.45 and 0.50
p <- 0.48
me <- 0.02
# ME <- 1.96 x SE
SE <- me / 1.96
# SE <- sqrt((p*(1-p))/n)
# SE^2 <- p*(1-p)/n
# n <- p*(1-p)/SE^2
n <- (p*(1-p)/SE^2)
n
## [1] 2397.158
We need at least 2398 respondents to get 2 percent of margin or error
p_cal <- 0.08
p_org <- 0.088
p <- p_cal - p_org
p
## [1] -0.008
n_cal <- 11545
n_org <- 4691
se_cal <- (p_cal * (1-p_cal)) / n_cal
se_org <- (p_org * (1-p_org)) / n_org
se <- sqrt(se_cal + se_org)
me_28 <- 1.96 * se
me_28
## [1] 0.009498128
uppertail2 <- p + me_28
lowertail2 <- p - me_28
c(uppertail2, lowertail2)
## [1] 0.001498128 -0.017498128
Since the confidence interval contains 0 so we fail to reject Ho and sleep deprivation for california and oregonian residents might be same.
w <- round(426*0.48,1)
c <- round(426*0.147,1)
d <- round(426*0.396,1)
o <- round(426*0.409,1)
proportions=c(w,c,d,o)
proportions
## [1] 204.5 62.6 168.7 174.2
Sample size for each cases have more than 5 so we fulfill all the assumptions for chi-square test.
x = c(4,16,67,345)
k = 4
dF = 3
chi = 0
for(biome in 1:4){
chi = chi + ((x[biome]-proportions[biome])^2/proportions[biome])
}
p = pchisq(chi,dF,lower.tail = FALSE)
p
## [1] 2.173304e-99
We reject the Ho and hence barking deers prefers certain habitats to forage.
dep_women <- 2607 / 50739
nodep_women <- 48132 / 50739
c(dep_women,nodep_women)*100
## [1] 5.138059 94.861941
5.13 percent women are depressed while 94.86 percent women are not depressed
group <- 5
df <- 3
expected <- dep_women*6617
cell <- (373 - expected)^2/expected
cell
## [1] 3.205914
k <-5
df <- 5-1
pval <- pchisq(20.93,df, lower.tail=FALSE)
pval
## [1] 0.0003269507