
R version 3.6.2 (2019-12-12) -- "Dark and Stormy Night"
Copyright (C) 2019 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> zz <- file.path("U:","My Documents")
> 
> File.Location <- file.path(zz,"BALANCED.sav")
> library(foreign)
> y <- read.spss(File.Location)
> y <- data.frame(y)
> attach(y)
> regout <- lm(score ~ task*group,data=y)
> anova(regout)
Analysis of Variance Table

Response: score
           Df Sum Sq Mean Sq F value    Pr(>F)    
task        3 127.38   42.46  15.120 4.650e-07 ***
group       2 640.03  320.02 113.953 < 2.2e-16 ***
task:group  6 486.77   81.13  28.888 2.388e-14 ***
Residuals  48 134.80    2.81                      
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> 
> # group means
> 
> install.packages("plyr")
Installing package into ‘C:/Users/peterw/Documents/R/win-library/3.6’
(as ‘lib’ is unspecified)
--- Please select a CRAN mirror for use in this session ---
Error in contrib.url(repos, "source") : 
  trying to use CRAN without setting a mirror
> library(plyr)
Warning message:
package ‘plyr’ was built under R version 3.6.3 
> ddply(y,.(group),summarise,mean=mean(score),sd=sd(score))
            group  mean       sd
1 PATIENT GROUP 1 15.05 3.456116
2 PATIENT GROUP 2 11.00 3.145590
3        CONTROLS 19.00 4.192726
> 
> # unpacking interactions as simple effects
> 
> install.packages("emmeans")
Installing package into ‘C:/Users/peterw/Documents/R/win-library/3.6’
(as ‘lib’ is unspecified)
--- Please select a CRAN mirror for use in this session ---
Error in contrib.url(repos, "source") : 
  trying to use CRAN without setting a mirror
> library(emmeans)
Warning message:
package ‘emmeans’ was built under R version 3.6.3 
> emcatcat <- emmeans(regout, ~ task*group, data=y)
> contrast(emcatcat, "revpairwise",by="group",adjust="none")
group = PATIENT GROUP 1:
 contrast            estimate   SE df t.ratio p.value
 OBJECTS - ANIMALS        0.8 1.06 48  0.755  0.4541 
 PLANTS - ANIMALS         2.8 1.06 48  2.642  0.0111 
 PLANTS - OBJECTS         2.0 1.06 48  1.887  0.0652 
 COUNTRIES - ANIMALS      7.8 1.06 48  7.359  <.0001 
 COUNTRIES - OBJECTS      7.0 1.06 48  6.605  <.0001 
 COUNTRIES - PLANTS       5.0 1.06 48  4.718  <.0001 

group = PATIENT GROUP 2:
 contrast            estimate   SE df t.ratio p.value
 OBJECTS - ANIMALS       -1.0 1.06 48 -0.944  0.3501 
 PLANTS - ANIMALS         3.0 1.06 48  2.831  0.0068 
 PLANTS - OBJECTS         4.0 1.06 48  3.774  0.0004 
 COUNTRIES - ANIMALS      6.0 1.06 48  5.661  <.0001 
 COUNTRIES - OBJECTS      7.0 1.06 48  6.605  <.0001 
 COUNTRIES - PLANTS       3.0 1.06 48  2.831  0.0068 

group = CONTROLS:
 contrast            estimate   SE df t.ratio p.value
 OBJECTS - ANIMALS       -8.0 1.06 48 -7.548  <.0001 
 PLANTS - ANIMALS        -6.0 1.06 48 -5.661  <.0001 
 PLANTS - OBJECTS         2.0 1.06 48  1.887  0.0652 
 COUNTRIES - ANIMALS    -10.0 1.06 48 -9.435  <.0001 
 COUNTRIES - OBJECTS     -2.0 1.06 48 -1.887  0.0652 
 COUNTRIES - PLANTS      -4.0 1.06 48 -3.774  0.0004 

> > emcatcat
 task      group           emmean    SE df lower.CL upper.CL
 ANIMALS   PATIENT GROUP 1   12.2 0.749 48    10.69    13.71
 OBJECTS   PATIENT GROUP 1   13.0 0.749 48    11.49    14.51
 PLANTS    PATIENT GROUP 1   15.0 0.749 48    13.49    16.51
 COUNTRIES PATIENT GROUP 1   20.0 0.749 48    18.49    21.51
 ANIMALS   PATIENT GROUP 2    9.0 0.749 48     7.49    10.51
 OBJECTS   PATIENT GROUP 2    8.0 0.749 48     6.49     9.51
 PLANTS    PATIENT GROUP 2   12.0 0.749 48    10.49    13.51
 COUNTRIES PATIENT GROUP 2   15.0 0.749 48    13.49    16.51
 ANIMALS   CONTROLS          25.0 0.749 48    23.49    26.51
 OBJECTS   CONTROLS          17.0 0.749 48    15.49    18.51
 PLANTS    CONTROLS          19.0 0.749 48    17.49    20.51
 COUNTRIES CONTROLS          15.0 0.749 48    13.49    16.51

Confidence level used: 0.95 

> model <- aov(score~as.factor(group), data=y)
> summary(model)
                 Df Sum Sq Mean Sq F value   Pr(>F)    
as.factor(group)  2    640   320.0   24.36 2.26e-08 ***
Residuals        57    749    13.1                     
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> TukeyHSD(model, conf.level=.95)
  Tukey multiple comparisons of means
    95% family-wise confidence level

Fit: aov(formula = score ~ as.factor(group), data = y)

$`as.factor(group)`
     diff       lwr       upr     p adj
2-1 -4.05 -6.808418 -1.291582 0.0023363
3-1  3.95  1.191582  6.708418 0.0030423
3-2  8.00  5.241582 10.758418 0.0000000

> 
> mdat <- y[y$group==1,]
> model <- aov(score~as.factor(task), data=mdat)
> summary(model)
                Df Sum Sq Mean Sq F value   Pr(>F)    
as.factor(task)  3  184.2   61.38   22.95 4.87e-06 ***
Residuals       16   42.8    2.67                     
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> TukeyHSD(model, conf.level=.95)
  Tukey multiple comparisons of means
    95% family-wise confidence level

Fit: aov(formula = score ~ as.factor(task), data = mdat)

$`as.factor(task)`
    diff        lwr       upr     p adj
2-1  0.8 -2.1594619  3.759462 0.8652812
3-1  2.8 -0.1594619  5.759462 0.0669826
4-1  7.8  4.8405381 10.759462 0.0000065
3-2  2.0 -0.9594619  4.959462 0.2536386
4-2  7.0  4.0405381  9.959462 0.0000245
4-3  5.0  2.0405381  7.959462 0.0009491

> 

