Getting Sphericity Tests for Within Subject Repeated Measure Anova (using "car" package) (Adjusted Dataset)

4 messages Options
Embed this post
Permalink
unl-neuropsych

Getting Sphericity Tests for Within Subject Repeated Measure Anova (using "car" package) (Adjusted Dataset)

Reply Threaded More More options
Print post
Permalink
[corrected dataset below]


Hello everyone,

I am trying to do within subjects repeated measures anova followed by the
test of sphericity (sample dataset below).
I am able to get either mixed model or linear model anova and TukeyHSD, but
have no luck with Repeated-Measures Assuming Sphericity or Separate
Sphericity Tests.
I am trying to follow example from "car" package, but it seems that I am not
getting something right.

> Dataset$Sessn <- as.factor(Dataset$Sessn)

> LinearModel.1 <- lm(Response ~ Sessn*Trtmt, data=Dataset)

> summary(LinearModel.1)

All, good so far, but I have problem understanding "idata=" and "idesign="
functions pertaining to my example.  Session is my repeated measure (Sessn 1
and Sessn 2 = two sessions, in reality I have more) and it is already
stacked. Any help or guidance on this matter.

Thank you, my mock dataset is below.  Each subject has two levels of
treatment throughout four calendar days which are recoded to Session 1 and
Session 2 in order to compare treatments by the first and subsequent days of
exposure (Treatment x Session; my DV is Response; Session is repeated).

Subj      Trtmt      Sessn      Response
1     N     1     5
1     D     1     6
1     N     2     4
1     D     2     7
2     N     1     8
2     D     1     9
2     N     2     2
2     D     2     1
3     N     1     4
3     D     1     5
3     N     2     6
3     D     2     2
4     N     1     5
4     D     1     6
4     N     2     4
4     D     2     7
5     N     1     8
5     D     1     9
5     N     2     2
5     D     2     1
6     N     1     4
6     D     1     5
6     N     2     6
6     D     2     2



Sincerely,

Sergios Charntikov (Sergey), MA

Behavioral Neuropharmacology Lab
Department of Psychology
University of Nebraska-Lincoln
Lincoln, NE 68588-0308  USA

sergioschr-at-gmail-dot-com

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
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.
John Fox

Re: Getting Sphericity Tests for Within Subject Repeated Measure Anova (using "car" package) (Adjusted Dataset)

Reply Threaded More More options
Print post
Permalink
Dear Segios,

For repeated-measures designs, the Anova() function requires a multivariate
linear model fit to the "wide" version of the data set, in which each of the
repeated measures appears as a separate variable. It is necessary that you
have the same occasions observed for all subjects. For your scaled-down
example, you'd have two response variables named, e.g., Sessn1 and Sessn2.
Then you'd fit the multivariate linear model as mod <- lm(cbind(Sessn1,
Sessn2) ~ Trtmnt, data=Dataset). The idata data frame could simply be idata
<- data.frame(Sessn=factor(1:2)). Then you could get the MANOVA and
repeated-measure ANOVA, including sphericity test, etc., as
summary(Anova(mod, idata=idata, idesign=~Sessn)).

I hope this helps,
 John

--------------------------------
John Fox
Senator William McMaster
  Professor of Social Statistics
Department of Sociology
McMaster University
Hamilton, Ontario, Canada
web: socserv.mcmaster.ca/jfox


> -----Original Message-----
> From: [hidden email] [mailto:[hidden email]]
On

> Behalf Of Sergios (Sergey) Charntikov
> Sent: November-09-09 1:18 PM
> To: [hidden email]
> Subject: [R] Getting Sphericity Tests for Within Subject Repeated Measure
> Anova (using "car" package) (Adjusted Dataset)
>
> [corrected dataset below]
>
>
> Hello everyone,
>
> I am trying to do within subjects repeated measures anova followed by the
> test of sphericity (sample dataset below).
> I am able to get either mixed model or linear model anova and TukeyHSD,
but
> have no luck with Repeated-Measures Assuming Sphericity or Separate
> Sphericity Tests.
> I am trying to follow example from "car" package, but it seems that I am
not

> getting something right.
>
> > Dataset$Sessn <- as.factor(Dataset$Sessn)
>
> > LinearModel.1 <- lm(Response ~ Sessn*Trtmt, data=Dataset)
>
> > summary(LinearModel.1)
>
> All, good so far, but I have problem understanding "idata=" and "idesign="
> functions pertaining to my example.  Session is my repeated measure (Sessn
1
> and Sessn 2 = two sessions, in reality I have more) and it is already
> stacked. Any help or guidance on this matter.
>
> Thank you, my mock dataset is below.  Each subject has two levels of
> treatment throughout four calendar days which are recoded to Session 1 and
> Session 2 in order to compare treatments by the first and subsequent days
of

> exposure (Treatment x Session; my DV is Response; Session is repeated).
>
> Subj      Trtmt      Sessn      Response
> 1     N     1     5
> 1     D     1     6
> 1     N     2     4
> 1     D     2     7
> 2     N     1     8
> 2     D     1     9
> 2     N     2     2
> 2     D     2     1
> 3     N     1     4
> 3     D     1     5
> 3     N     2     6
> 3     D     2     2
> 4     N     1     5
> 4     D     1     6
> 4     N     2     4
> 4     D     2     7
> 5     N     1     8
> 5     D     1     9
> 5     N     2     2
> 5     D     2     1
> 6     N     1     4
> 6     D     1     5
> 6     N     2     6
> 6     D     2     2
>
>
>
> Sincerely,
>
> Sergios Charntikov (Sergey), MA
>
> Behavioral Neuropharmacology Lab
> Department of Psychology
> University of Nebraska-Lincoln
> Lincoln, NE 68588-0308  USA
>
> sergioschr-at-gmail-dot-com
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> 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.

______________________________________________
[hidden email] mailing list
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.
unl-neuropsych

Re: Getting Sphericity Tests for Within Subject Repeated Measure Anova (using "car" package) (Adjusted Dataset)

Reply Threaded More More options
Print post
Permalink
Based on what you suggested I did the following:


1. Dataset$Sessn <- as.factor(Dataset$Sessn)
2. mod <- lm(cbind(Sessn=="1", Sessn=="2") ~ Trtmt, data=Dataset)
3. idata <- data.frame(Sessn=factor(1:2))
4. Anova(mod, idata=idata, idesign=~Sessn))
ERROR:  The error SSP matrix is apparently of deficient rank = 0 < 1

I have noticed that my DV (Response) is not in play in the coding above.
Then I have modified it to:

mod2 <- lm(*Response*~(cbind(Sessn=="1", Sessn=="2")) * Trtmt, data=Dataset)
idata2 <- data.frame(Sessn=factor(1:2))
Anova(mod, idata=idata2, idesign=~Sessn)
ERROR: The error SSP matrix is apparently of deficient rank = 0 < 1

Then I have modified it to:

mod2 <- lm(Response~(cbind(Sessn=="1", Sessn=="2")) * Trtmt, data=Dataset)
idata2 <- data.frame(Sessn=factor(1:2))
Anova(mod, idata=idata2, idesign=~*(cbind(Sessn=="1", Sessn=="2")) * Trtmt*)
ERROR:  object 'Trtmt' not found

Then I have modified it to:

mod2 <- lm(Response~(cbind(Sessn=="1", Sessn=="2")) * Trtmt, data=Dataset)
idata2 <- data.frame(Sessn=factor(1:2))
Anova(mod, idata=idata2, idesign=~(cbind(Sessn=="1", Sessn=="2")) * *
Dataset$Trtmt*)
ERROR:  variable lengths differ (found for 'Dataset$Trtmt') [THIS IS THE
ERROR THAT I HAVE BEEN
GETTING WITH MY ACTUAL DATASET FOLLOWING "CAR" PACKAGE RECOMMENDATIONS)

Any idea what am I doing wrong?  I have attached my mock data for
convenience in csv.


Sincerely,

Sergios Charntikov (Sergey), MA

Behavioral Neuropharmacology Lab
Department of Psychology
University of Nebraska-Lincoln
Lincoln, NE 68588-0308  USA

[hidden email]
www.unl.edu/psychoneuropharm/


On Mon, Nov 9, 2009 at 12:33 PM, John Fox <[hidden email]> wrote:

> Dear Segios,
>
> For repeated-measures designs, the Anova() function requires a multivariate
> linear model fit to the "wide" version of the data set, in which each of
> the
> repeated measures appears as a separate variable. It is necessary that you
> have the same occasions observed for all subjects. For your scaled-down
> example, you'd have two response variables named, e.g., Sessn1 and Sessn2.
> Then you'd fit the multivariate linear model as mod <- lm(cbind(Sessn1,
> Sessn2) ~ Trtmnt, data=Dataset). The idata data frame could simply be idata
> <- data.frame(Sessn=factor(1:2)). Then you could get the MANOVA and
> repeated-measure ANOVA, including sphericity test, etc., as
> summary(Anova(mod, idata=idata, idesign=~Sessn)).
>
> I hope this helps,
>  John
>
> --------------------------------
> John Fox
> Senator William McMaster
>  Professor of Social Statistics
> Department of Sociology
> McMaster University
> Hamilton, Ontario, Canada
> web: socserv.mcmaster.ca/jfox
>
>
> > -----Original Message-----
> > From: [hidden email] [mailto:[hidden email]]
> On
> > Behalf Of Sergios (Sergey) Charntikov
> > Sent: November-09-09 1:18 PM
> > To: [hidden email]
> > Subject: [R] Getting Sphericity Tests for Within Subject Repeated Measure
> > Anova (using "car" package) (Adjusted Dataset)
> >
> > [corrected dataset below]
> >
> >
> > Hello everyone,
> >
> > I am trying to do within subjects repeated measures anova followed by the
> > test of sphericity (sample dataset below).
> > I am able to get either mixed model or linear model anova and TukeyHSD,
> but
> > have no luck with Repeated-Measures Assuming Sphericity or Separate
> > Sphericity Tests.
> > I am trying to follow example from "car" package, but it seems that I am
> not
> > getting something right.
> >
> > > Dataset$Sessn <- as.factor(Dataset$Sessn)
> >
> > > LinearModel.1 <- lm(Response ~ Sessn*Trtmt, data=Dataset)
> >
> > > summary(LinearModel.1)
> >
> > All, good so far, but I have problem understanding "idata=" and
> "idesign="
> > functions pertaining to my example.  Session is my repeated measure
> (Sessn
> 1
> > and Sessn 2 = two sessions, in reality I have more) and it is already
> > stacked. Any help or guidance on this matter.
> >
> > Thank you, my mock dataset is below.  Each subject has two levels of
> > treatment throughout four calendar days which are recoded to Session 1
> and
> > Session 2 in order to compare treatments by the first and subsequent days
> of
> > exposure (Treatment x Session; my DV is Response; Session is repeated).
> >
> > Subj      Trtmt      Sessn      Response
> > 1     N     1     5
> > 1     D     1     6
> > 1     N     2     4
> > 1     D     2     7
> > 2     N     1     8
> > 2     D     1     9
> > 2     N     2     2
> > 2     D     2     1
> > 3     N     1     4
> > 3     D     1     5
> > 3     N     2     6
> > 3     D     2     2
> > 4     N     1     5
> > 4     D     1     6
> > 4     N     2     4
> > 4     D     2     7
> > 5     N     1     8
> > 5     D     1     9
> > 5     N     2     2
> > 5     D     2     1
> > 6     N     1     4
> > 6     D     1     5
> > 6     N     2     6
> > 6     D     2     2
> >
> >
> >
> > Sincerely,
> >
> > Sergios Charntikov (Sergey), MA
> >
> > Behavioral Neuropharmacology Lab
> > Department of Psychology
> > University of Nebraska-Lincoln
> > Lincoln, NE 68588-0308  USA
> >
> > sergioschr-at-gmail-dot-com
> >
> >       [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > [hidden email] mailing list
> > 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.
>
>
>

______________________________________________
[hidden email] mailing list
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

Re: Getting Sphericity Tests for Within Subject Repeated Measure Anova (using "car" package) (Adjusted Dataset)

Reply Threaded More More options
Print post
Permalink
Sergios (Sergey) Charntikov wrote:

> Based on what you suggested I did the following:
>
>
> 1. Dataset$Sessn <- as.factor(Dataset$Sessn)
> 2. mod <- lm(cbind(Sessn=="1", Sessn=="2") ~ Trtmt, data=Dataset)
> 3. idata <- data.frame(Sessn=factor(1:2))
> 4. Anova(mod, idata=idata, idesign=~Sessn))
> ERROR:  The error SSP matrix is apparently of deficient rank = 0 < 1
>
> I have noticed that my DV (Response) is not in play in the coding above.
> Then I have modified it to:
>
> mod2 <- lm(*Response*~(cbind(Sessn=="1", Sessn=="2")) * Trtmt, data=Dataset)
> idata2 <- data.frame(Sessn=factor(1:2))
> Anova(mod, idata=idata2, idesign=~Sessn)
> ERROR: The error SSP matrix is apparently of deficient rank = 0 < 1
>
> Then I have modified it to:
>
> mod2 <- lm(Response~(cbind(Sessn=="1", Sessn=="2")) * Trtmt, data=Dataset)
> idata2 <- data.frame(Sessn=factor(1:2))
> Anova(mod, idata=idata2, idesign=~*(cbind(Sessn=="1", Sessn=="2")) * Trtmt*)
> ERROR:  object 'Trtmt' not found
>
> Then I have modified it to:
>
> mod2 <- lm(Response~(cbind(Sessn=="1", Sessn=="2")) * Trtmt, data=Dataset)
> idata2 <- data.frame(Sessn=factor(1:2))
> Anova(mod, idata=idata2, idesign=~(cbind(Sessn=="1", Sessn=="2")) * *
> Dataset$Trtmt*)
> ERROR:  variable lengths differ (found for 'Dataset$Trtmt') [THIS IS THE
> ERROR THAT I HAVE BEEN
> GETTING WITH MY ACTUAL DATASET FOLLOWING "CAR" PACKAGE RECOMMENDATIONS)


> Any idea what am I doing wrong?  I have attached my mock data for
> convenience in csv.

Either you forgot, or your mailer did not say that it is a text file,
and the mailing list software consequently scrubbed it...

I think what you need is an analysis of 6 observations with a
2x2==4-dimensional response. You may want to look at my paper in R News
2007-2. The reacttime example used there is pretty similar. You're not
going to get much sphericity testing when all factors have only two
levels, though.

>
> Sincerely,
>
> Sergios Charntikov (Sergey), MA
>
> Behavioral Neuropharmacology Lab
> Department of Psychology
> University of Nebraska-Lincoln
> Lincoln, NE 68588-0308  USA
>
> [hidden email]
> www.unl.edu/psychoneuropharm/
>
>
> On Mon, Nov 9, 2009 at 12:33 PM, John Fox <[hidden email]> wrote:
>
>> Dear Segios,
>>
>> For repeated-measures designs, the Anova() function requires a multivariate
>> linear model fit to the "wide" version of the data set, in which each of
>> the
>> repeated measures appears as a separate variable. It is necessary that you
>> have the same occasions observed for all subjects. For your scaled-down
>> example, you'd have two response variables named, e.g., Sessn1 and Sessn2.
>> Then you'd fit the multivariate linear model as mod <- lm(cbind(Sessn1,
>> Sessn2) ~ Trtmnt, data=Dataset). The idata data frame could simply be idata
>> <- data.frame(Sessn=factor(1:2)). Then you could get the MANOVA and
>> repeated-measure ANOVA, including sphericity test, etc., as
>> summary(Anova(mod, idata=idata, idesign=~Sessn)).
>>
>> I hope this helps,
>>  John
>>
>> --------------------------------
>> John Fox
>> Senator William McMaster
>>  Professor of Social Statistics
>> Department of Sociology
>> McMaster University
>> Hamilton, Ontario, Canada
>> web: socserv.mcmaster.ca/jfox
>>
>>
>>> -----Original Message-----
>>> From: [hidden email] [mailto:[hidden email]]
>> On
>>> Behalf Of Sergios (Sergey) Charntikov
>>> Sent: November-09-09 1:18 PM
>>> To: [hidden email]
>>> Subject: [R] Getting Sphericity Tests for Within Subject Repeated Measure
>>> Anova (using "car" package) (Adjusted Dataset)
>>>
>>> [corrected dataset below]
>>>
>>>
>>> Hello everyone,
>>>
>>> I am trying to do within subjects repeated measures anova followed by the
>>> test of sphericity (sample dataset below).
>>> I am able to get either mixed model or linear model anova and TukeyHSD,
>> but
>>> have no luck with Repeated-Measures Assuming Sphericity or Separate
>>> Sphericity Tests.
>>> I am trying to follow example from "car" package, but it seems that I am
>> not
>>> getting something right.
>>>
>>>> Dataset$Sessn <- as.factor(Dataset$Sessn)
>>>> LinearModel.1 <- lm(Response ~ Sessn*Trtmt, data=Dataset)
>>>> summary(LinearModel.1)
>>> All, good so far, but I have problem understanding "idata=" and
>> "idesign="
>>> functions pertaining to my example.  Session is my repeated measure
>> (Sessn
>> 1
>>> and Sessn 2 = two sessions, in reality I have more) and it is already
>>> stacked. Any help or guidance on this matter.
>>>
>>> Thank you, my mock dataset is below.  Each subject has two levels of
>>> treatment throughout four calendar days which are recoded to Session 1
>> and
>>> Session 2 in order to compare treatments by the first and subsequent days
>> of
>>> exposure (Treatment x Session; my DV is Response; Session is repeated).
>>>
>>> Subj      Trtmt      Sessn      Response
>>> 1     N     1     5
>>> 1     D     1     6
>>> 1     N     2     4
>>> 1     D     2     7
>>> 2     N     1     8
>>> 2     D     1     9
>>> 2     N     2     2
>>> 2     D     2     1
>>> 3     N     1     4
>>> 3     D     1     5
>>> 3     N     2     6
>>> 3     D     2     2
>>> 4     N     1     5
>>> 4     D     1     6
>>> 4     N     2     4
>>> 4     D     2     7
>>> 5     N     1     8
>>> 5     D     1     9
>>> 5     N     2     2
>>> 5     D     2     1
>>> 6     N     1     4
>>> 6     D     1     5
>>> 6     N     2     6
>>> 6     D     2     2
>>>
>>>
>>>
>>> Sincerely,
>>>
>>> Sergios Charntikov (Sergey), MA
>>>
>>> Behavioral Neuropharmacology Lab
>>> Department of Psychology
>>> University of Nebraska-Lincoln
>>> Lincoln, NE 68588-0308  USA
>>>
>>> sergioschr-at-gmail-dot-com
>>>
>>>       [[alternative HTML version deleted]]
>>>
>>> ______________________________________________
>>> [hidden email] mailing list
>>> 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.
>>
>>
>>
>> ------------------------------------------------------------------------
>>
>> ______________________________________________
>> [hidden email] mailing list
>> 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.


--
    O__  ---- Peter Dalgaard             Ă˜ster Farimagsgade 5, Entr.B
   c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
  (*) \(*) -- University of Copenhagen   Denmark      Ph:  (+45) 35327918
~~~~~~~~~~ - ([hidden email])              FAX: (+45) 35327907

______________________________________________
[hidden email] mailing list
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.