You are here

Group Exercise: Hypothesis Testing

# ANES2012<-read.csv("http://www.courseserve.info/files/ANES2012r.csv")
# ANES2016<-read.csv("http://www.shortell.nyc/online/files/anes_timeseries_2016.csv")

In 2012, the mean favorability toward the Democratic Party was 54.9 degrees. We can use this to formulate a hypothesis about favorability toward the Democrats in 2016.

H0: muDems = 54.9
H1: muDems =/= 54.9

We compute the test in R:
t.test(V161095, mu=54.9) # The value for mu comes from our hypotheses

We can interpret the results in terms of how favorability toward Democrats changed in the intervening four years.

Group Exercise
Select a numeric variable from ANES 2016 and perform the hypothesis test. (You can use the middle of the scale as the value of mu.) Interpret the results. Paste your R code below your interpretation.

Comments

H0: muLiberals=50
H1: muLiberals=/=50

> t.test(V162097, mu=50)

One Sample t-test

data: V162097
t = 5.4009, df = 3607, p-value = 7.058e-08
alternative hypothesis: true mean is not equal to 50
95 percent confidence interval:
54.30282 59.20716
sample estimates:
mean of x
56.75499

The null hypotheses is rejected, I'm 95% confident that the mean of the population is between 54.3 and 59.2 degrees of people who favor liberals.

> t.test(V162099,mu=50)

One Sample t-test

data: V162099
t = 35.837, df = 3595, p-value <
2.2e-16
alternative hypothesis: true mean is not equal to 50
95 percent confidence interval:
72.40913 75.00300
sample estimates:
mean of x
73.70606

We reject the null hypothesis of the population mean being equal to 50 and therefore, we are 95% confident that the mean of favorability of poor people is between 72.4 and 75 degrees.

> t.test(v162085, mu=54.9)
Error in t.test(v162085, mu = 54.9) : object 'v162085' not found
> t.test(V162085,mu=54.9)

One Sample t-test

data: V162085
t = 12.661, df = 2394, p-value < 2.2e-16
alternative hypothesis: true mean is not equal to 54.9
95 percent confidence interval:
106.0154 124.7503
sample estimates:
mean of x
115.3829
Result: We are rejecting the null hypothesis. I am 95 percent confident that the mean favor ability towards senate democratic Canaanites falls between 106.0 and 124.8

> t.test(v162085, mu=54.9)
Error in t.test(v162085, mu = 54.9) : object 'v162085' not found
> t.test(V162085,mu=54.9)

One Sample t-test

data: V162085
t = 12.661, df = 2394, p-value < 2.2e-16
alternative hypothesis: true mean is not equal to 54.9
95 percent confidence interval:
106.0154 124.7503
sample estimates:
mean of x
115.3829
Result: We are rejecting the null hypothesis. I am 95 percent confident that the mean favor ability towards senate democratic Canaanites falls between 106.0 and 124.8

data: V162113
t = 4.1892, df = 3620, p-value = 2.866e-05
alternative hypothesis: true mean is not equal to 50
95 percent confidence interval:
53.45266 59.52773
sample estimates:
mean of x
56.4902
We reject null hypothesis. I am 95% confident that the mean favorability towards Black Lives Matter falls between 53.5 and 59.5.

H0:MU PASSPREZ =50
H1:MU PASSPREZ=/=50
> t.test(V161092,mu=50)

One Sample t-test

data: V161092
t = 5.478, df = 4249, p-value = 4.551e-08
alternative hypothesis: true mean is not equal to 50
95 percent confidence interval:
51.97226 54.17080
sample estimates:
mean of x
53.07153
The null hypothesis is rejected we are 95% confident that the mean population os betwwen 51.97 and 54.17 degrees of people who favor the previous president.

H0: muPoorPeople=50
H1: muPoorPeople=/=50

> t.test(V162099, mu=50)

One Sample t-test

data: V162099
t = 35.837, df = 3595, p-value < 2.2e-16
alternative hypothesis: true mean is not equal to 50
95 percent confidence interval:
72.40913 75.00300
sample estimates:
mean of x
73.70606

We have to reject the null hypothesis because p is less than .05. It is 95% possible that the mean of the population is 72.4 and 75.

> t.test(V161086)

One Sample t-test

data: V161086
t = 80.124, df = 4232, p-value < 2.2e-16
alternative hypothesis: true mean is not equal to 0
95 percent confidence interval:
41.12004 43.18282
sample estimates:
mean of x
42.15143
HO: democra Candidate= 50
H1: democra candidate > 50

H0= muD=muR
H0=muD=/=muR

> t.test(V162100[V161019==1],V162100[V161019==2])

Welch Two Sample t-test

data: V162100[V161019 == 1] and V162100[V161019 == 2]
t = -3.1064, df = 1351.3, p-value = 0.001933
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-14.767162 -3.335396
sample estimates:
mean of x mean of y
49.09706 58.14834

>
> t.test(V162100[V161019==1]
+ )

One Sample t-test

data: V162100[V161019 == 1]
t = 21.762, df = 782, p-value < 2.2e-16
alternative hypothesis: true mean is not equal to 0
95 percent confidence interval:
44.66841 53.52572
sample estimates:
mean of x
49.09706

> t.test(V162100[V161019==2])

One Sample t-test

data: V162100[V161019 == 2]
t = 31.536, df = 572, p-value < 2.2e-16
alternative hypothesis: true mean is not equal to 0
95 percent confidence interval:
54.52675 61.76994
sample estimates:
mean of x
58.14834

Null Hypothesis is rejected. Im 95% confident that the mean favorability towards big business by democrats is between 44.7 and 53.5 degrees. And im 95% confident that the mean favorability towards big business by republicans is between 54.5 and 61.8 degrees.

> t.test(V162099[V161342==1],V162099[V161342==2])

Welch Two Sample t-test

data: V162099[V161342 == 1] and V162099[V161342 == 2]
t = -3.9762, df = 3237.4, p-value = 7.155e-05
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-7.736803 -2.626557
sample estimates:
mean of x mean of y
70.95275 76.13443

> t.test(V162099[V161342==1], mu=50)

One Sample t-test

data: V162099[V161342 == 1]
t = 28.654, df = 1671, p-value < 2.2e-16
alternative hypothesis: true mean is not equal to 50
95 percent confidence interval:
69.51851 72.38699
sample estimates:
mean of x
70.95275

> t.test(V162099[V161342==2], mu=50)

One Sample t-test

data: V162099[V161342 == 2]
t = 24.228, df = 1881, p-value < 2.2e-16
alternative hypothesis: true mean is not equal to 50
95 percent confidence interval:
74.01890 78.24996
sample estimates:
mean of x
76.13443

We reject the null hypothesis, men and women do not have the same favorability towards poor people. It is 95% certain men favor poor people 69.5 to 72.4 degrees, while women favor poor people 74 to 78.2 degrees.

> t.test(V161093[V161002 == 1],V161093[V161002 == 2])

Welch Two Sample t-test

data: V161093[V161002 == 1] and V161093[V161002 == 2]
t = -1.0992, df = 1161.7, p-value = 0.2719
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-5.494746 1.548753
sample estimates:
mean of x mean of y
48.37814 50.35113

Reject the null hypthesis

> t.test(V161093[V161002 == 1], mu=50)

One Sample t-test

data: V161093[V161002 == 1]
t = -1.2461, df = 557, p-value = 0.2133
alternative hypothesis: true mean is not equal to 50
95 percent confidence interval:
45.82153 50.93475
sample estimates:
mean of x
48.37814
I am 95% confident that the mean favorability of men towards Bill Clinton is between 45.8 and 50.9 degrees.

> t.test(V161093[V161002 == 2], mu= 50)

One Sample t-test

data: V161093[V161002 == 2]
t = 0.28408, df = 617, p-value = 0.7764
alternative hypothesis: true mean is not equal to 50
95 percent confidence interval:
47.92377 52.77850
sample estimates:
mean of x
50.35113
I am 95% confident that the mean favorability of women towards Bill Clinton is between 47.9 and 57.7 degrees