You are here

Group Exercise: Confidence Interval

Select a numeric variable from the ANES 2016. Write R code to compute the 95% confidence interval and interpret the results. Copy your R code below your interpretation.

Comments

> t.test(V161114x, mu=50)

One Sample t-test

data: V161114x
t = -1299.5, df = 4263, p-value < 2.2e-16
alternative hypothesis: true mean is not equal to 50
95 percent confidence interval:
4.155375 4.293499
sample estimates:
mean of x
4.224437

95% confident that the mean favorability of 2010 health care law for the whole population falls between 4.155 and 4.293 degrees.

> attach(ANES2016)
> t.test(V161093,mu=50)

One Sample t-test

data: V161093
t = -1.5473, df = 4234, p-value =
0.1219
alternative hypothesis: true mean is not equal to 50
95 percent confidence interval:
48.25003 50.20616
sample estimates:
mean of x
49.2281

Interpretation: I am 95% confident that the mean favorability of Bill Clinton for the whole population falls between 48.3 and 50.2 degrees.

> library(gmodels)
> ANES2016<-read.csv("http://www.shortell.nyc/online/files/anes_timeseries_2016.csv")
> attach(ANES2016)
> t.test(V162096, mu=50)

One Sample t-test

data: V162096
t = 9.2789, df = 3606, p-value < 2.2e-16
alternative hypothesis: true mean is not equal to 50
95 percent confidence interval:
60.56273 66.22241
sample estimates:
mean of x
63.39257

> t.test(V161496,mu=50)

One Sample t-test

data: V161496
t = -616.63, df = 4009, p-value < 2.2e-16
alternative hypothesis: true mean is not equal to 50
95 percent confidence interval:
1.345046 1.653458
sample estimates:
mean of x
1.499252

We are 95% confident that the number of guns owned in the population falls between 1.3 and 1.6 so it is approximately 1 gun and 1 and a half gun.