path_to_file = "/Users/nickvohra/Documents/ExpDesign/2019 Class/Workshop1_basics/BulbarRedness.xlsx"
data = read_excel(path_to_file)
Patient = data$Patient
Age = data$Age
Observer = data$Observer
Gender = data$Gender
Temporal = data$`Bulbar Redness-Temporal`
Superior = data$`Bulbar Redness-Superior`
Question 1 - Was there a relationship between redness and age?
#First, lets visualize it
par(mfrow = c(2,1))
plot(Age, Superior, type = 'p', main = 'Age vs Superior Redness')
plot(Age, Temporal, type = 'p', main = 'Age vs Temporal Redness')
#It look like there is no correlation, but lets try a normilization curve
qqplot(Age,Superior)
qqplot(Age, Temporal)
It look like there is no correlation between Age and Redness Question 2 - was there a difference in redness between genders
Conduct a t test and an ANOVA test
#Alright, so we have vectors for genders and redness.Lets sombine so we get data for each gender.
Gender1Data = c(Gender1SuperiorRedness, Gender1TemporalRedness)
Gender2Data = c(Gender2SuperiorRedness, Gender2TemporalRedness)
#o a two sample t test and ANOVA test
t.test(Gender1Data, Gender2Data)
##
## Welch Two Sample t-test
##
## data: Gender1Data and Gender2Data
## t = 0.42399, df = 237.22, p-value = 0.672
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -0.1076849 0.1667492
## sample estimates:
## mean of x mean of y
## 1.868421 1.838889
#ANOVA test
combinedGender = data.frame(cbind(Gender1Data, Gender2Data))
## Warning in cbind(Gender1Data, Gender2Data): number of rows of result is not
## a multiple of vector length (arg 1)
StackedGender = stack(combinedGender)
AnovaRsults = aov(values ~ ind, data = StackedGender)
summary(AnovaRsults)
## Df Sum Sq Mean Sq F value Pr(>F)
## ind 1 0.00 0.00254 0.009 0.925
## Residuals 250 72.14 0.28854
You’ll notice that the confidence interval in the t test crosses zero and the P-value in the ANOVA test show that there is NO significance. Question 3 Was there a difference in redness based on Observers? Below is an example of the code that sets us up to run the tests
#Same deal as before, instead of gender we do observer.
Observer1TemporalRedness = c()
Observer2TemporalRedness = c()
Observer1SuperiorRedness = c()
Observer2SuperiorRedness = c()
for (i in 1:length(Observer)){
if (Observer[i] == 1){
Observer1SuperiorRedness[i] = Superior[i]
Observer1TemporalRedness[i] = Temporal[i]
}
else{
Observer2SuperiorRedness[i] = Superior[i]
Observer2TemporalRedness[i] = Temporal[i]
}
}
# Same deal as before,get rid of the NA's
Observer1TemporalRedness = na.omit(Observer1TemporalRedness)
Observer2TemporalRedness = na.omit(Observer2TemporalRedness)
Observer1SuperiorRedness = na.omit(Observer1SuperiorRedness)
Observer2SuperiorRedness = na.omit(Observer2SuperiorRedness)
Observer1 = c(Observer1TemporalRedness,Observer1SuperiorRedness)
Observer2 = c(Observer2TemporalRedness,Observer2SuperiorRedness)
# Statistics on the Observer Different
t.test(Observer1, Observer2)
##
## Welch Two Sample t-test
##
## data: Observer1 and Observer2
## t = 0.031956, df = 221.3, p-value = 0.9745
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -0.1335056 0.1379067
## sample estimates:
## mean of x mean of y
## 1.854255 1.852055
combinedObserver = data.frame(cbind(Observer1, Observer2))
## Warning in cbind(Observer1, Observer2): number of rows of result is not a
## multiple of vector length (arg 1)
StackedObserver = stack(combinedObserver)
AnovaResults = aov(values ~ ind, data = StackedObserver)
summary(AnovaRsults)
## Df Sum Sq Mean Sq F value Pr(>F)
## ind 1 0.00 0.00254 0.009 0.925
## Residuals 250 72.14 0.28854
No, there was no difference as the confidence interval crosses zero (just like Gender), the p value in the ANOVA supports this ####Question 4 - was there a difference betwen temporal and superior redness within groups Gender 1 Data
#Do a two sample t test
t.test(Gender1SuperiorRedness, Gender1TemporalRedness)
##
## Welch Two Sample t-test
##
## data: Gender1SuperiorRedness and Gender1TemporalRedness
## t = -5.0515, df = 106.05, p-value = 1.835e-06
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -0.6302764 -0.2749867
## sample estimates:
## mean of x mean of y
## 1.642105 2.094737
#Do an ANOVA Test;
Combined = data.frame(cbind(Gender1SuperiorRedness, Gender1TemporalRedness))
StackedDATA = stack(Combined)
AnovaResults = aov(values ~ ind, data = StackedDATA)
summary(AnovaResults)
## Df Sum Sq Mean Sq F value Pr(>F)
## ind 1 5.839 5.839 25.52 1.72e-06 ***
## Residuals 112 25.627 0.229
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Gender2 Data
#Do a two sample t test
t.test(Gender2SuperiorRedness, Gender2TemporalRedness)
##
## Welch Two Sample t-test
##
## data: Gender2SuperiorRedness and Gender2TemporalRedness
## t = -3.1645, df = 123.94, p-value = 0.001955
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -0.4876395 -0.1123605
## sample estimates:
## mean of x mean of y
## 1.688889 1.988889
#Do an ANOVA Test;
Combined2 = data.frame(cbind(Gender2SuperiorRedness, Gender2TemporalRedness))
StackedDATA2 = stack(Combined2)
AnovaResults2 = aov(values ~ ind, data = StackedDATA2)
summary(AnovaResults2)
## Df Sum Sq Mean Sq F value Pr(>F)
## ind 1 2.84 2.8350 10.01 0.00195 **
## Residuals 124 35.10 0.2831
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Yes there was significance within both groups.