PJ3a <- read.csv("/Users/Lorraine/Desktop/Project3a.csv")
library(car)
## Loading required package: carData
library(sjstats)
## Registered S3 methods overwritten by 'lme4':
## method from
## cooks.distance.influence.merMod car
## influence.merMod car
## dfbeta.influence.merMod car
## dfbetas.influence.merMod car
library(pastecs)
library(psych)
##
## Attaching package: 'psych'
## The following objects are masked from 'package:sjstats':
##
## pca, phi
## The following object is masked from 'package:car':
##
## logit
library(lme4)
## Loading required package: Matrix
library(ggplot2)
##
## Attaching package: 'ggplot2'
## The following objects are masked from 'package:psych':
##
## %+%, alpha
library(compute.es)
library(FSA)
## ## FSA v0.8.27. See citation('FSA') if used in publication.
## ## Run fishR() for related website and fishR('IFAR') for related book.
##
## Attaching package: 'FSA'
## The following object is masked from 'package:psych':
##
## headtail
## The following object is masked from 'package:sjstats':
##
## se
## The following object is masked from 'package:car':
##
## bootCase
library(phia)
library(multcomp)
## Loading required package: mvtnorm
## Loading required package: survival
## Loading required package: TH.data
## Loading required package: MASS
##
## Attaching package: 'TH.data'
## The following object is masked from 'package:MASS':
##
## geyser
#Changing integers to factors
PJ3a$group <- factor(PJ3a$group, levels = c(1, 2, 3), labels = c("Social_Science", "Business", "Engineering"))
par(mfrow=c(1,2))
plot(iq ~ group, data=PJ3a)
leveneTest(PJ3a$iq, PJ3a$group)
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 2 2.7285 0.0769 .
## 42
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Leven test is not significant, assumption is met.
ANOVA1 <- aov(iq~group, data = PJ3a)
summary(ANOVA1)
## Df Sum Sq Mean Sq F value Pr(>F)
## group 2 1529 764.7 20.02 7.84e-07 ***
## Residuals 42 1604 38.2
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
eta_sq(ANOVA1)
## term etasq
## 1 group 0.488
omega_sq(ANOVA1)
## term omegasq
## 1 group 0.458
postHocs <- glht(ANOVA1, linfct = mcp(group = "Tukey"))
summary(postHocs)
##
## Simultaneous Tests for General Linear Hypotheses
##
## Multiple Comparisons of Means: Tukey Contrasts
##
##
## Fit: aov(formula = iq ~ group, data = PJ3a)
##
## Linear Hypotheses:
## Estimate Std. Error t value Pr(>|t|)
## Business - Social_Science == 0 0.06667 2.25694 0.030 1
## Engineering - Social_Science == 0 12.40000 2.25694 5.494 <1e-05 ***
## Engineering - Business == 0 12.33333 2.25694 5.465 <1e-05 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## (Adjusted p values reported -- single-step method)
#1a. The one-way ANOVA test revealed a significant difference bewteen the subjects’ discipline in terms of their IQ scores, F(2,42) = 20.02, p < 0.05.
#1b. The eta-squared result suggedted that discipline explained 48.8% of the variance seen in IQ scores (eta-squared = 0.488). On the other hand, the less biased omega-squared suggested that discipline explained 45.8% of the variance seen in IQ scores (omega-sq = 0.458).
#1c. A Tukey Post Hoc test was ran becuase there were same number of subjects in each group.
#1d. The Tukey Post hoc test suggested that students in Enginering discipline has a significantly higher IQ than students in Social Science (t = 5.494, p<.05) and Business discipline (t = 5.465, p<.05).
#Checking for independence between IV and covariate
summary(aov(age~group, data = PJ3a))
## Df Sum Sq Mean Sq F value Pr(>F)
## group 2 7456 3728 235.9 <2e-16 ***
## Residuals 42 664 16
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
The result is significant, the IV and covariate are NOT independent.
ANCOVA <- aov(iq ~ age + group, data = PJ3a)
Anova(ANCOVA, type = "III")
## Anova Table (Type III tests)
##
## Response: iq
## Sum Sq Df F value Pr(>F)
## (Intercept) 2575.68 1 65.8256 4.636e-10 ***
## age 0.25 1 0.0064 0.9367
## group 114.82 2 1.4672 0.2424
## Residuals 1604.28 41
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#2a. The ANCOVA test revealed that when controlling for student age, (F(1,41) = 0.0064, p >.05), there was no significant differences between disciplines and IQ scores, F(2, 41) = 1.4672, p >.05.
#2b. Since there is not a significant interaction, the assumption of the homogeneity of regression slopes is not violated.
#2c. An analysis of variance test and an analysis of covariate test were conducted to examine whether there is a significant differences of IQ scores of the students in different disciplines (Engineering, Social Science, and Business). The assumptions were checked before running the analysis. All assumptions were met except for the assumption of the independence between the IV (disciplain groups) and the covariate (student age), (F(2,42) = 235.9, p < 0.05). A one-way ANOVA test revealed a significant difference bewteen the subjects’ discipline in terms of their IQ scores, F(2,42) = 20.02, p < 0.05. The eta-squared result suggedted that discipline explained 48.8% of the variance seen in IQ scores (eta-squared = 0.488). On the other hand, the less biased omega-squared suggested that discipline explained 45.8% of the variance seen in IQ scores (omega-sq = 0.458). The Tukey Post hoc test suggested that students in Enginering discipline has a significantly higher IQ than students in Social Science (t = 5.494, p<.05) and Business discipline (t = 5.465, p<.05), but there was no significant difference between students in Business and Social Science (t = 0.030, p > .05). The ANCOVA test revealed that the covariate, age, was not significantly associated with IQ scores, F(1,41) = 0.0064, p > .05. There was either a significant effect of the disciplain on IQ scores after controlling for the effect of student age, F(2,41) = 1.4672, p > .05.
library(haven)
PJ3b <- read_sav("/Users/Lorraine/Desktop/Project3b.sav")
PJ3b$reinfor<-factor(PJ3b$reinfor, levels = c(1,2,3), labels = c("Token", "Money", "Food"))
PJ3b$schedule<-factor(PJ3b$schedule, levels = c(1,2), labels = c("Random", "Spaced"))
par(mfrow=c(1,2))
plot(test ~ reinfor + schedule, data=PJ3b)
leveneTest(test~reinfor*schedule,data = PJ3b)
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 5 1.1418 0.3484
## 60
Levene test is not significant, assumption is met.
ANOVA2 <- aov(test ~ reinfor*schedule, data = PJ3b)
summary(ANOVA2)
## Df Sum Sq Mean Sq F value Pr(>F)
## reinfor 2 1249.2 624.6 31.857 3.73e-10 ***
## schedule 1 490.9 490.9 25.039 5.21e-06 ***
## reinfor:schedule 2 187.4 93.7 4.778 0.0119 *
## Residuals 60 1176.4 19.6
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
MR <- PJ3b[which(PJ3b$schedule == "Random" & PJ3b$reinfor == "Money"), ]
describe(MR)
## vars n mean sd median trimmed mad min max range skew
## reinfor* 1 11 2.00 0.00 2 2.00 0.00 2 2 0 NaN
## schedule* 2 11 1.00 0.00 1 1.00 0.00 1 1 0 NaN
## test 3 11 28.27 4.76 28 27.78 5.93 23 38 15 0.65
## kurtosis se
## reinfor* NaN 0.00
## schedule* NaN 0.00
## test -0.84 1.43
eta_sq(ANOVA2)
## term etasq
## 1 reinfor 0.402
## 2 schedule 0.158
## 3 reinfor:schedule 0.060
eta_sq(ANOVA2, partial = TRUE)
## term partial.etasq
## 1 reinfor 0.515
## 2 schedule 0.294
## 3 reinfor:schedule 0.137
omega_sq(ANOVA2)
## term omegasq
## 1 reinfor 0.387
## 2 schedule 0.151
## 3 reinfor:schedule 0.047
TukeyHSD(ANOVA2)
## Tukey multiple comparisons of means
## 95% family-wise confidence level
##
## Fit: aov(formula = test ~ reinfor * schedule, data = PJ3b)
##
## $reinfor
## diff lwr upr p adj
## Money-Token 9.5909091 6.382485 12.799333 0.0000000
## Food-Token 8.8181818 5.609758 12.026605 0.0000000
## Food-Money -0.7727273 -3.981151 2.435696 0.8319355
##
## $schedule
## diff lwr upr p adj
## Spaced-Random 5.454545 3.274087 7.635004 5.2e-06
##
## $`reinfor:schedule`
## diff lwr upr p adj
## Money:Random-Token:Random 8.6363636 3.0783192 14.1944081 0.0003404
## Food:Random-Token:Random 11.8181818 6.2601374 17.3762263 0.0000007
## Token:Spaced-Token:Random 6.8181818 1.2601374 12.3762263 0.0078370
## Money:Spaced-Token:Random 17.3636364 11.8055919 22.9216808 0.0000000
## Food:Spaced-Token:Random 12.6363636 7.0783192 18.1944081 0.0000001
## Food:Random-Money:Random 3.1818182 -2.3762263 8.7398626 0.5467172
## Token:Spaced-Money:Random -1.8181818 -7.3762263 3.7398626 0.9277297
## Money:Spaced-Money:Random 8.7272727 3.1692283 14.2853172 0.0002879
## Food:Spaced-Money:Random 4.0000000 -1.5580444 9.5580444 0.2919226
## Token:Spaced-Food:Random -5.0000000 -10.5580444 0.5580444 0.1015272
## Money:Spaced-Food:Random 5.5454545 -0.0125899 11.1034990 0.0508480
## Food:Spaced-Food:Random 0.8181818 -4.7398626 6.3762263 0.9979663
## Money:Spaced-Token:Spaced 10.5454545 4.9874101 16.1034990 0.0000087
## Food:Spaced-Token:Spaced 5.8181818 0.2601374 11.3762263 0.0350374
## Food:Spaced-Money:Spaced -4.7272727 -10.2853172 0.8307717 0.1393655
FR<- PJ3b[which(PJ3b$schedule == "Random" & PJ3b$reinfor == "Food"), ]
TR<- PJ3b[which(PJ3b$schedule == "Random" & PJ3b$reinfor == "Token"), ]
TS<- PJ3b[which(PJ3b$schedule == "Spaced" & PJ3b$reinfor == "Token"), ]
MS<- PJ3b[which(PJ3b$schedule == "Spaced" & PJ3b$reinfor == "Money"), ]
FS<- PJ3b[which(PJ3b$schedule == "Spaced" & PJ3b$reinfor == "Food"), ]
describe(FR)
## vars n mean sd median trimmed mad min max range skew
## reinfor* 1 11 3.00 0.00 3 3.00 0.00 3 3 0 NaN
## schedule* 2 11 1.00 0.00 1 1.00 0.00 1 1 0 NaN
## test 3 11 31.45 5.28 33 31.56 7.41 23 39 16 -0.15
## kurtosis se
## reinfor* NaN 0.00
## schedule* NaN 0.00
## test -1.59 1.59
describe(TR)
## vars n mean sd median trimmed mad min max range skew
## reinfor* 1 11 1.00 0.00 1 1.00 0.00 1 1 0 NaN
## schedule* 2 11 1.00 0.00 1 1.00 0.00 1 1 0 NaN
## test 3 11 19.64 5.03 20 19.78 5.93 12 26 14 0.01
## kurtosis se
## reinfor* NaN 0.00
## schedule* NaN 0.00
## test -1.68 1.52
describe(TS)
## vars n mean sd median trimmed mad min max range skew
## reinfor* 1 11 1.00 0.00 1 1.00 0.00 1 1 0 NaN
## schedule* 2 11 2.00 0.00 2 2.00 0.00 2 2 0 NaN
## test 3 11 26.45 4.01 25 26.33 2.97 21 33 12 0.37
## kurtosis se
## reinfor* NaN 0.00
## schedule* NaN 0.00
## test -1.39 1.21
describe(MS)
## vars n mean sd median trimmed mad min max range skew
## reinfor* 1 11 2 0.00 2 2.00 0.00 2 2 0 NaN
## schedule* 2 11 2 0.00 2 2.00 0.00 2 2 0 NaN
## test 3 11 37 4.31 37 36.89 4.45 30 45 15 0.31
## kurtosis se
## reinfor* NaN 0.0
## schedule* NaN 0.0
## test -0.84 1.3
describe(FS)
## vars n mean sd median trimmed mad min max range skew
## reinfor* 1 11 3.00 0.00 3 3.00 0.00 3 3 0 NaN
## schedule* 2 11 2.00 0.00 2 2.00 0.00 2 2 0 NaN
## test 3 11 32.27 2.69 32 32.11 4.45 29 37 8 0.19
## kurtosis se
## reinfor* NaN 0.00
## schedule* NaN 0.00
## test -1.33 0.81
#1ai: F value for the main effects of the reinforcer: F(2,60) = 31.857, p < 0.05; F value for the main effects of the reinforcement schedule: F(1,60) = 25.038, p < 0.05.
#1aii:The mean GPA for a random schedule and a money reinforcer was M = 28.27. #1aiii: Eta-squared = 0.060; Eta-squared partial = 0.137; Omega-squared = 0.047
#1c: A 2 (reinforcement schedules: random or spaced) x 3 (type of reinforcer: Token, Money, Food) ANOVA revealed significant main effects on test scores for both types of reinforcer [F(2,60) = 31.857, p < 0.05, partial eta-square = 0.515] and reinforcement schedule [F(1,60) = 25.039, p < 0.05, partial eta-square = 0.294]. Importantly, there was a significant interaction between types of reinforcement schedule and types of reinforcer [F(2,60) = 4.778, p < 0.05, partial eta-square = 0.137]. Specifically, the reinforcement schedules were affected differently by the types of reinforcer. In detail, with the Token reinforcer, test scores for the spaced schedule (M = 26.45, SD = 4.01) were significantly higher than tests scores in the Random schedule (M = 19.64; SD = 5.03). Similarly, with the Money reinforcer, test scores for the spaced schedule (M = 37.00, SD = 4.31) were significantly higher than test scores in the random schedule (M = 28.27, SD = 4.76). However, the mean test scores for random and spaced reinforcement schedules were not significantly different in the food reinforcer(random, M = 31.45, SD = 5.28; spaced, M = 32.27, SD = 2.69).
library(dplyr)
##
## Attaching package: 'dplyr'
## The following object is masked from 'package:MASS':
##
## select
## The following objects are masked from 'package:pastecs':
##
## first, last
## The following object is masked from 'package:car':
##
## recode
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
PJ3b %>%
ggplot() +
aes(x = reinfor, y = test, color = schedule, group = schedule) +
stat_summary(fun.y = mean, geom = "point") +
stat_summary(fun.y = mean, geom = "line")