Load packages & data

library(effectsize)
library(WebPower)
## Loading required package: MASS
## Loading required package: lme4
## Loading required package: Matrix
## Loading required package: lavaan
## This is lavaan 0.7-3
## lavaan is FREE software! Please report any bugs.
## Loading required package: parallel
## Loading required package: PearsonDS
library(exact2x2)
## Loading required package: exactci
## Loading required package: ssanv
## Loading required package: testthat
library(pwr)

ColaData <- read.csv("~/Rmd_Files/ColaData.csv", stringsAsFactors=TRUE)

Problem Set 1

1A

str(ColaData)
## 'data.frame':    2800 obs. of  2 variables:
##  $ Person: int  1 2 3 4 5 6 7 8 9 10 ...
##  $ Choice: Factor w/ 3 levels "Classic Coke",..: 1 1 1 1 1 1 1 1 1 1 ...
table(ColaData$Choice)
## 
## Classic Coke    Coke Zero Vanilla Coke 
##         1206         1094          500
sum(table(ColaData$Choice))
## [1] 2800
sum(table(ColaData$Choice))/3
## [1] 933.3333

The expected values per cell are 933.33

###1B The data assumptions for \(/chi\)2 Goodness of Fit test are valid because each cell has a value above 5. The method assumptions are also valid. The variables are nominal.

###1C

chisq.test(table(ColaData$Choice))
## 
##  Chi-squared test for given probabilities
## 
## data:  table(ColaData$Choice)
## X-squared = 308.51, df = 2, p-value < 2.2e-16

Yes. p <.001

###1D Sample size matters because the effect size estimation of squaring values creates more extremity even though it keeps the same proportions. (it is not the difference of squares, but the difference squared)

###1E Using a chi-square GOF test, there is was a significance in the people who preferred Classic Coke (1206) to those who preferred Coke Zero (1094) to those who preferred Vanilla Coke (500). \(/chi\)2 = 308.51, df = 2, P <.001 w = .33

###1F

cohens_w(chisq.test(table(ColaData$Choice)))
## Cohen's w |       95% CI
## ------------------------
## 0.33      | [0.30, 1.41]
## 
## - One-sided CIs: upper bound fixed at [1.41~].
w = sqrt(2)*.254

wp.anova.count(k=3, V=.254, alpha = .05, power = .82)
## One-way Analogous ANOVA with Count Data
## 
##     k        n     V alpha power
##     3 78.37876 0.254  0.05  0.82
## 
## NOTE: n is the total sample size
## URL: http://psychstat.org/anovacount

The a priori power analysis test shows a required sample size is 79.

Problem Set 2

###2A

CancerMice <- read.csv("~/Rmd_Files/CancerMice.csv", header=TRUE, stringsAsFactors=TRUE)

table(CancerMice [c(3,2)])
##            Time1
## Time2       Active Remission
##   Active        36         4
##   Remission     19        60

There are no data assumptions about McNemar test. There are method assumptions which state it only works in a repeated measures design and since individuals fit into only one cell, this is satisfied.

###2B

mcnemar.exact(CancerMice$Time2,CancerMice$Time1)
## 
##  Exact McNemar test (with central confidence intervals)
## 
## data:  CancerMice$Time2 and CancerMice$Time1
## b = 4, c = 19, p-value = 0.002599
## alternative hypothesis: true odds ratio is not equal to 1
## 95 percent confidence interval:
##  0.05208632 0.63348484
## sample estimates:
## odds ratio 
##  0.2105263

There is a statistically significant asymmetrical change P = .002599

###2C A McNemar exact test found significant change in cancer mice over time (n = 119), p = .002599. Examining those who changed from active to remission time-1 to time-2 (15.96% [n=19]) than those who changed from remission to active time-1 to time-2 (3.36% [n = 4]), OR = 0.2105263.”

Problem Set 3

###3A

ExerciseClub <- read.csv("~/Rmd_Files/ExerciseClub.csv", stringsAsFactors=TRUE)

str(ExerciseClub)
## 'data.frame':    1585 obs. of  3 variables:
##  $ ApplicantID: int  1 2 3 4 5 6 7 8 9 10 ...
##  $ Ethnicity  : Factor w/ 2 levels "African-American",..: 2 2 2 2 2 2 2 2 2 2 ...
##  $ Decision   : Factor w/ 2 levels "Accepted","Rejected": 2 2 2 2 2 2 2 2 2 2 ...
table(ExerciseClub[c(2,3)])
##                    Decision
## Ethnicity           Accepted Rejected
##   African-American         1       30
##   European-American      275     1279

The methods were not violated, but the minimum cell size assumptions were violated and we will use Fisher’s exact test to complete the problem set.

###3B

fisher.exact(ExerciseClub$Ethnicity, ExerciseClub$Decision)
## 
##  Two-sided Fisher's Exact Test (usual method using minimum likelihood)
## 
## data:  ExerciseClub$Ethnicity and ExerciseClub$Decision
## p-value = 0.03074
## alternative hypothesis: true odds ratio is not equal to 1
## 95 percent confidence interval:
##  0.0077 0.8872
## sample estimates:
## odds ratio 
##  0.1551288

###3C With a p-value of .03074 we can assume that the pattern probably is not reasonably random. The OR= 0.64462 and this means that there is a 6.5 times higher likelihood that European-Americans are accepted than rejected compared to the likelihood that African-Americans are accepted verses rejected.

###3D “A Fisher’s exact test found a significant association[/interaction] between between ethnic identity (i.e., European-American, African American) and the membership status of the gym (i.e., accepted vs. rejected) (n= 1585), p= .03074, OR= 0.64462. Specifically, European-American gym applicants are 6.5 times more likely to be accepted versus rejected compared to the African-American gym applicants who are 1.6 times more likely to be accepted versus rejected.”