Discussion:
[R] Question Mixed-Design Anova in R
Lisa van der Burgh
2018-11-23 10:43:35 UTC
Permalink
Hi Everyone,



I have a question about Mixed-Design Anova in R. I want to obtain Mauchly’s test of Sphericity and the Greenhouse-Geisser correction. I have managed to do it in SPSS:



GLM Measure1 Measure2 Measure3 Measure4 Measure5 Measure6 BY Grouping

/WSFACTOR=Measure 6 Polynomial

/METHOD=SSTYPE(3)

/PLOT=PROFILE(Measure*Grouping)

/CRITERIA=ALPHA(.05)

/WSDESIGN=Measure

/DESIGN=Grouping.



I have tried to replicate this in R:

library("dplyr")

library("tidyr")

library("ggplot2")

library("ez")



PatientID <- c(1:10)

Measure1 <- c(3,5,7,4,NA,7,4,4,7,2)

Measure2 <- c(1,2,5,6,8,9,5,NA,6,7)

Measure3 <- c(3,3,5,7,NA,4,5,7,8,1)

Measure4 <- c(1,2,5,NA,3,NA,6,7,3,6)

Measure5 <- c(2,3,NA,8,3,5,6,3,6,4)

Measure6 <- c(1,2,4,6,8,3,5,6,NA,4)

Grouping <- c(1,0,1,1,1,0,0,1,1,0)

dataframe <- data.frame(PatientID, Measure1, Measure2, Measure3, Measure4, Measure5, Measure6, Grouping)

dataframe$Grouping <- as.factor(dataframe$Grouping)

dataframe



ezPrecis(dataframe)

glimpse(dataframe)



dataframe %>% count(PatientID)



dataframe %>% count(PatientID, Grouping, Measure1, Measure2, Measure3, Measure4, Measure5, Measure6) %>%

filter(PatientID %in% c(1:243)) %>%

print(n = 10)



# So, we have a mixed design with one between factor (Grouping) and 6 within factors (Measure 1 to 6).



dat_means <- dataframe %>%

group_by(Grouping, Measure1, Measure2, Measure3, Measure4, Measure5, Measure6) %>%

summarise(mRT = mean(c(Measure1, Measure2, Measure3, Measure4, Measure5, Measure6))) %>% ungroup()

View(dat_means)



ggplot(dat_means, aes(c(Measure1, Measure2, Measure3, Measure4, Measure5, Measure6), mRT, colour = Grouping)) +

geom_line(aes(group = Grouping)) +

geom_point(aes(shape = Grouping), size = 3) +

facet_wrap(~group)



ANOVA <- ezANOVA(dat, x, PatientID, within = .( c(Measure1, Measure2, Measure3, Measure4, Measure5, Measure6)),

between = Grouping, type = 3)



print(ANOVA)





However, this does not work. I know I am probably doing it completely wrong, but I do not know how to solve it. Besides that, I do not know what to fill in at the ‘x’.

Can somebody help me?



Thank you in advance.

Lisa


[[alternative HTML version deleted]]
peter dalgaard
2018-11-23 15:16:10 UTC
Permalink
You seem to be bringing in a ton of stuff without looking at features in base R...

Check

help(mauchly.test)
help(anova.mlm)

and examples therein. There are also options in the "car" package.

-pd

> On 23 Nov 2018, at 11:43 , Lisa van der Burgh <***@student.eur.nl> wrote:
>
> Hi Everyone,
>
>
>
> I have a question about Mixed-Design Anova in R. I want to obtain Mauchly�s test of Sphericity and the Greenhouse-Geisser correction. I have managed to do it in SPSS:
>
>
>
> GLM Measure1 Measure2 Measure3 Measure4 Measure5 Measure6 BY Grouping
>
> /WSFACTOR=Measure 6 Polynomial
>
> /METHOD=SSTYPE(3)
>
> /PLOT=PROFILE(Measure*Grouping)
>
> /CRITERIA=ALPHA(.05)
>
> /WSDESIGN=Measure
>
> /DESIGN=Grouping.
>
>
>
> I have tried to replicate this in R:
>
> library("dplyr")
>
> library("tidyr")
>
> library("ggplot2")
>
> library("ez")
>
>
>
> PatientID <- c(1:10)
>
> Measure1 <- c(3,5,7,4,NA,7,4,4,7,2)
>
> Measure2 <- c(1,2,5,6,8,9,5,NA,6,7)
>
> Measure3 <- c(3,3,5,7,NA,4,5,7,8,1)
>
> Measure4 <- c(1,2,5,NA,3,NA,6,7,3,6)
>
> Measure5 <- c(2,3,NA,8,3,5,6,3,6,4)
>
> Measure6 <- c(1,2,4,6,8,3,5,6,NA,4)
>
> Grouping <- c(1,0,1,1,1,0,0,1,1,0)
>
> dataframe <- data.frame(PatientID, Measure1, Measure2, Measure3, Measure4, Measure5, Measure6, Grouping)
>
> dataframe$Grouping <- as.factor(dataframe$Grouping)
>
> dataframe
>
>
>
> ezPrecis(dataframe)
>
> glimpse(dataframe)
>
>
>
> dataframe %>% count(PatientID)
>
>
>
> dataframe %>% count(PatientID, Grouping, Measure1, Measure2, Measure3, Measure4, Measure5, Measure6) %>%
>
> filter(PatientID %in% c(1:243)) %>%
>
> print(n = 10)
>
>
>
> # So, we have a mixed design with one between factor (Grouping) and 6 within factors (Measure 1 to 6).
>
>
>
> dat_means <- dataframe %>%
>
> group_by(Grouping, Measure1, Measure2, Measure3, Measure4, Measure5, Measure6) %>%
>
> summarise(mRT = mean(c(Measure1, Measure2, Measure3, Measure4, Measure5, Measure6))) %>% ungroup()
>
> View(dat_means)
>
>
>
> ggplot(dat_means, aes(c(Measure1, Measure2, Measure3, Measure4, Measure5, Measure6), mRT, colour = Grouping)) +
>
> geom_line(aes(group = Grouping)) +
>
> geom_point(aes(shape = Grouping), size = 3) +
>
> facet_wrap(~group)
>
>
>
> ANOVA <- ezANOVA(dat, x, PatientID, within = .( c(Measure1, Measure2, Measure3, Measure4, Measure5, Measure6)),
>
> between = Grouping, type = 3)
>
>
>
> print(ANOVA)
>
>
>
>
>
> However, this does not work. I know I am probably doing it completely wrong, but I do not know how to solve it. Besides that, I do not know what to fill in at the �x�.
>
> Can somebody help me?
>
>
>
> Thank you in advance.
>
> Lisa
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-***@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

--
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: ***@cbs.dk Priv: ***@gmail.com

______________________________________________
R-***@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Fox, John
2018-11-23 15:54:49 UTC
Permalink
Dear Lisa,

> -----Original Message-----
> From: R-help [mailto:r-help-***@r-project.org] On Behalf Of peter
> dalgaard
> Sent: Friday, November 23, 2018 10:16 AM
> To: Lisa van der Burgh <***@student.eur.nl>
> Cc: r-***@R-project.org
> Subject: Re: [R] Question Mixed-Design Anova in R
>
> You seem to be bringing in a ton of stuff without looking at features in base
> R...
>
> Check
>
> help(mauchly.test)
> help(anova.mlm)
>
> and examples therein. There are also options in the "car" package.

With respect to the latter, see in particular the O'Brien-Kaiser example in ?Anova.

I hope this helps,
John

-----------------------------------------------------------------
John Fox
Professor Emeritus
McMaster University
Hamilton, Ontario, Canada
Web: https://socialsciences.mcmaster.ca/jfox/


>
> -pd
>
> > On 23 Nov 2018, at 11:43 , Lisa van der Burgh <***@student.eur.nl>
> wrote:
> >
> > Hi Everyone,
> >
> >
> >
> > I have a question about Mixed-Design Anova in R. I want to obtain Mauchly s
> test of Sphericity and the Greenhouse-Geisser correction. I have managed to
> do it in SPSS:
> >
> >
> >
> > GLM Measure1 Measure2 Measure3 Measure4 Measure5 Measure6 BY
> Grouping
> >
> > /WSFACTOR=Measure 6 Polynomial
> >
> > /METHOD=SSTYPE(3)
> >
> > /PLOT=PROFILE(Measure*Grouping)
> >
> > /CRITERIA=ALPHA(.05)
> >
> > /WSDESIGN=Measure
> >
> > /DESIGN=Grouping.
> >
> >
> >
> > I have tried to replicate this in R:
> >
> > library("dplyr")
> >
> > library("tidyr")
> >
> > library("ggplot2")
> >
> > library("ez")
> >
> >
> >
> > PatientID <- c(1:10)
> >
> > Measure1 <- c(3,5,7,4,NA,7,4,4,7,2)
> >
> > Measure2 <- c(1,2,5,6,8,9,5,NA,6,7)
> >
> > Measure3 <- c(3,3,5,7,NA,4,5,7,8,1)
> >
> > Measure4 <- c(1,2,5,NA,3,NA,6,7,3,6)
> >
> > Measure5 <- c(2,3,NA,8,3,5,6,3,6,4)
> >
> > Measure6 <- c(1,2,4,6,8,3,5,6,NA,4)
> >
> > Grouping <- c(1,0,1,1,1,0,0,1,1,0)
> >
> > dataframe <- data.frame(PatientID, Measure1, Measure2, Measure3,
> > Measure4, Measure5, Measure6, Grouping)
> >
> > dataframe$Grouping <- as.factor(dataframe$Grouping)
> >
> > dataframe
> >
> >
> >
> > ezPrecis(dataframe)
> >
> > glimpse(dataframe)
> >
> >
> >
> > dataframe %>% count(PatientID)
> >
> >
> >
> > dataframe %>% count(PatientID, Grouping, Measure1, Measure2,
> Measure3,
> > Measure4, Measure5, Measure6) %>%
> >
> > filter(PatientID %in% c(1:243)) %>%
> >
> > print(n = 10)
> >
> >
> >
> > # So, we have a mixed design with one between factor (Grouping) and 6
> within factors (Measure 1 to 6).
> >
> >
> >
> > dat_means <- dataframe %>%
> >
> > group_by(Grouping, Measure1, Measure2, Measure3, Measure4,
> Measure5,
> > Measure6) %>%
> >
> > summarise(mRT = mean(c(Measure1, Measure2, Measure3, Measure4,
> > Measure5, Measure6))) %>% ungroup()
> >
> > View(dat_means)
> >
> >
> >
> > ggplot(dat_means, aes(c(Measure1, Measure2, Measure3, Measure4,
> > Measure5, Measure6), mRT, colour = Grouping)) +
> >
> > geom_line(aes(group = Grouping)) +
> >
> > geom_point(aes(shape = Grouping), size = 3) +
> >
> > facet_wrap(~group)
> >
> >
> >
> > ANOVA <- ezANOVA(dat, x, PatientID, within = .( c(Measure1, Measure2,
> > Measure3, Measure4, Measure5, Measure6)),
> >
> > between = Grouping, type = 3)
> >
> >
> >
> > print(ANOVA)
> >
> >
> >
> >
> >
> > However, this does not work. I know I am probably doing it completely
> wrong, but I do not know how to solve it. Besides that, I do not know what to
> fill in at the x .
> >
> > Can somebody help me?
> >
> >
> >
> > Thank you in advance.
> >
> > Lisa
> >
> >
> > [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-***@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> > http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
> --
> Peter Dalgaard, Professor,
> Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000
> Frederiksberg, Denmark
> Phone: (+45)38153501
> Office: A 4.23
> Email: ***@cbs.dk Priv: ***@gmail.com
>
> ______________________________________________
> R-***@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.
______________________________________________
R-***@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Lisa van der Burgh
2018-11-23 16:03:02 UTC
Permalink
Dear John and Peter,


Thank you both for your answers. I am going to try the solutions you gave me!


Thanks again,

Lisa

________________________________
From: Fox, John <***@mcmaster.ca>
Sent: 23 November 2018 16:54:49
To: Lisa van der Burgh
Cc: r-***@R-project.org; peter dalgaard
Subject: RE: [R] Question Mixed-Design Anova in R

Dear Lisa,

> -----Original Message-----
> From: R-help [mailto:r-help-***@r-project.org] On Behalf Of peter
> dalgaard
> Sent: Friday, November 23, 2018 10:16 AM
> To: Lisa van der Burgh <***@student.eur.nl>
> Cc: r-***@R-project.org
> Subject: Re: [R] Question Mixed-Design Anova in R
>
> You seem to be bringing in a ton of stuff without looking at features in base
> R...
>
> Check
>
> help(mauchly.test)
> help(anova.mlm)
>
> and examples therein. There are also options in the "car" package.

With respect to the latter, see in particular the O'Brien-Kaiser example in ?Anova.

I hope this helps,
John

-----------------------------------------------------------------
John Fox
Professor Emeritus
McMaster University
Hamilton, Ontario, Canada
Web: https://socialsciences.mcmaster.ca/jfox/


>
> -pd
>
> > On 23 Nov 2018, at 11:43 , Lisa van der Burgh <***@student.eur.nl>
> wrote:
> >
> > Hi Everyone,
> >
> >
> >
> > I have a question about Mixed-Design Anova in R. I want to obtain Mauchly s
> test of Sphericity and the Greenhouse-Geisser correction. I have managed to
> do it in SPSS:
> >
> >
> >
> > GLM Measure1 Measure2 Measure3 Measure4 Measure5 Measure6 BY
> Grouping
> >
> > /WSFACTOR=Measure 6 Polynomial
> >
> > /METHOD=SSTYPE(3)
> >
> > /PLOT=PROFILE(Measure*Grouping)
> >
> > /CRITERIA=ALPHA(.05)
> >
> > /WSDESIGN=Measure
> >
> > /DESIGN=Grouping.
> >
> >
> >
> > I have tried to replicate this in R:
> >
> > library("dplyr")
> >
> > library("tidyr")
> >
> > library("ggplot2")
> >
> > library("ez")
> >
> >
> >
> > PatientID <- c(1:10)
> >
> > Measure1 <- c(3,5,7,4,NA,7,4,4,7,2)
> >
> > Measure2 <- c(1,2,5,6,8,9,5,NA,6,7)
> >
> > Measure3 <- c(3,3,5,7,NA,4,5,7,8,1)
> >
> > Measure4 <- c(1,2,5,NA,3,NA,6,7,3,6)
> >
> > Measure5 <- c(2,3,NA,8,3,5,6,3,6,4)
> >
> > Measure6 <- c(1,2,4,6,8,3,5,6,NA,4)
> >
> > Grouping <- c(1,0,1,1,1,0,0,1,1,0)
> >
> > dataframe <- data.frame(PatientID, Measure1, Measure2, Measure3,
> > Measure4, Measure5, Measure6, Grouping)
> >
> > dataframe$Grouping <- as.factor(dataframe$Grouping)
> >
> > dataframe
> >
> >
> >
> > ezPrecis(dataframe)
> >
> > glimpse(dataframe)
> >
> >
> >
> > dataframe %>% count(PatientID)
> >
> >
> >
> > dataframe %>% count(PatientID, Grouping, Measure1, Measure2,
> Measure3,
> > Measure4, Measure5, Measure6) %>%
> >
> > filter(PatientID %in% c(1:243)) %>%
> >
> > print(n = 10)
> >
> >
> >
> > # So, we have a mixed design with one between factor (Grouping) and 6
> within factors (Measure 1 to 6).
> >
> >
> >
> > dat_means <- dataframe %>%
> >
> > group_by(Grouping, Measure1, Measure2, Measure3, Measure4,
> Measure5,
> > Measure6) %>%
> >
> > summarise(mRT = mean(c(Measure1, Measure2, Measure3, Measure4,
> > Measure5, Measure6))) %>% ungroup()
> >
> > View(dat_means)
> >
> >
> >
> > ggplot(dat_means, aes(c(Measure1, Measure2, Measure3, Measure4,
> > Measure5, Measure6), mRT, colour = Grouping)) +
> >
> > geom_line(aes(group = Grouping)) +
> >
> > geom_point(aes(shape = Grouping), size = 3) +
> >
> > facet_wrap(~group)
> >
> >
> >
> > ANOVA <- ezANOVA(dat, x, PatientID, within = .( c(Measure1, Measure2,
> > Measure3, Measure4, Measure5, Measure6)),
> >
> > between = Grouping, type = 3)
> >
> >
> >
> > print(ANOVA)
> >
> >
> >
> >
> >
> > However, this does not work. I know I am probably doing it completely
> wrong, but I do not know how to solve it. Besides that, I do not know what to
> fill in at the x .
> >
> > Can somebody help me?
> >
> >
> >
> > Thank you in advance.
> >
> > Lisa
> >
> >
> > [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-***@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> > http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
> --
> Peter Dalgaard, Professor,
> Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000
> Frederiksberg, Denmark
> Phone: (+45)38153501
> Office: A 4.23
> Email: ***@cbs.dk Priv: ***@gmail.com
>
> ______________________________________________
> R-***@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

[[alternative HTML version deleted]]

______________________________________________
R-***@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Loading...