[R] getResponse(model.lme) yields incorrect number of dimensions error

2009-01-04 Thread Ullrich Ecker
Dear R experts,

I would like to get an R^2 - like value for a multilevel regression using lme.

I followed an archived suggestion by José 
Pinheiro to use the squared correlation between 
fitted and observed values, i.e.,

(cor(fitted(model.lme), getResponse(model.lme))^2

but getResponse returns the error message

Error in val[, level] : incorrect number of dimensions


The same happens with residuals(model.lme) and 
summary(model.lme) but not other generic 
functions such as predict, coef, or fitted, which (seem to) work fine.

I have searched the archives but could not find a 
solution--I don't really understand what dimensions R is referring to.

Any comments or suggestions would be greatly appreciated!

Thanks for your time, and happy new year,

Ullrich



Below is part of the dataframe and the code:


 > WMUCTrim
 Subj Cond   Acc S R T
1  11 0.667 1 1 1
2  12 0.8095238 1 0 1
4  14 1.000 1 0 0
6  16 0.9523810 0 0 1
7  17 0.8571429 0 1 0
8  18 1.000 0 0 0
20921 0.3809524 1 1 1
21022 0.9047619 1 0 1
21224 1.000 1 0 0
21426 0.8571429 0 0 1
21527 0.667 0 1 0
21628 1.000 0 0 0

 > mlr2 <- summary(lme(Acc ~ R + T + S, random = ~1 | Subj))
 > mlr2
Linear mixed-effects model fit by REML
  Data: NULL
 AIC   BIC   logLik
   -1140.414 -1113.778 576.2068

Random effects:
  Formula: ~1 | Subj
 (Intercept)   Residual
StdDev:  0.07069723 0.08233792

Fixed effects: Acc ~ R + T + S
  Value   Std.Error  DF   t-value p-value
(Intercept)  0.9843537 0.008937809 522 110.13367  0.
R1  -0.1139456 0.006958824 522 -16.37426  0.
T1  -0.1012472 0.006958824 522 -14.54946  0.
S1  -0.0137188 0.006958824 522  -1.97143  0.0492
  Correlation:
(Intr) R1 T1
R1 -0.260
T1 -0.260  0.000
S1 -0.260  0.000 -0.333

Standardized Within-Group Residuals:
 Min  Q1 Med  Q3 Max
-4.21190127 -0.46318153  0.02715579  0.58591808  2.57708969

Number of Observations: 630
Number of Groups: 105
 > class(mlr2)
[1] "summary.lme" "lme"
 > cor(fitted(mlr2), getResponse(mlr2))^2
Error in val[, level] : incorrect number of dimensions



Dr Ullrich Ecker | Postdoctoral Research Fellow | 
Cognitive Science Laboratories | Room 211 Sanders Building |

* School of Psychology | M304 | The University of 
Western Australia | 35 Stirling Highway | Crawley WA 6009 | Australia |
( 08 6488 3266 | Ê 08 6488 1006 | À 04 5822 0072 
| @ ullrich.ec...@uwa.edu.au | i www.cogsciwa.com |  
[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


Re: [R] Tukey HSD (or other post hoc tests) following repeated measures ANOVA

2008-05-30 Thread Ullrich Ecker
Great, thanks a lot, guys!

Only thing is I now have two working versions, that yield *slightly* 
different results.


ACCaov <- aov(Acc ~ Cond + Error(Subj/Cond), WMU3C)
ACClme <- lme(Acc ~ Cond, random = ~1 | Subj/Cond, WMU3C) # what does 
'~1 | Subj/Cond' mean?
summary(glht(ACClme, linfct=mcp(Cond="Tukey")))

yielding

Linear Hypotheses:
Estimate Std. Error z value p value
2 - 1 == 0 0.392560   0.027210  14.427  <1e-05 ***
3 - 1 == 0 0.400372   0.027210  14.714  <1e-05 ***
3 - 2 == 0 0.007812   0.025442   0.3070.95


and


ACCaov <- aov(Acc ~ Cond + Error(Subj/Cond), WMU3C)
ACCaov2 <- aov(terms(Acc ~ Subj + Cond, WMU3C))  # gives same result 
as 1st aov, but yields aov not aovlist
ACCtukey <- TukeyHSD(ACCaov2, "Cond"); ACCtukey

yielding

$Cond
  diff lwrupr p adj
2-1 0.3637756  0.29889404 0.42865721 0.000
3-1 0.3715881  0.30670654 0.43646971 0.000
3-2 0.0078125 -0.05329192 0.06891692 0.9504659


I am trying to work my way through this (so I'm one of the good guys, 
at least I'm trying to understand my stats... ;-)), but any hint to 
what solution may be more appropriate to my problem would be much appreciated.

Cheers,

Ullrich



At 03:16 PM 30/05/2008, you wrote:

>Hi Ullrich,
>
> >> The model is
> >> RT.aov <- aov(RT~Cond + Error(Subj/Cond), WMU3C)
> >> I understand that TukeyHSD only works with an aov object, but that
> >> RT.aov is an aovlist object.
>
>You want to use lme() in package nlme, then glht() in the multcomp package.
>This will give you multiplicity adjusted p-values and confidence intervals.
>
>## Example
>require(MASS) ## for oats data set
>require(nlme) ## for lme()
>require(multcomp)  ## for multiple comparison stuff
>
>Aov.mod <- aov(Y ~ N + V + Error(B/V), data = oats)
>Lme.mod <- lme(Y ~ N + V, random = ~1 | B/V, data = oats)
>
>summary(Aov.mod)
>anova(Lme.mod)
>
>summary(Lme.mod)
>summary(glht(Lme.mod, linfct=mcp(V="Tukey")))
>
>HTH, Mark.
>
>
>Ullrich Ecker wrote:
> >
> > Hi everyone,
> >
> > I am fairly new to R, and I am aware that others have had this
> > problem before, but I have failed to solve the problem from previous
> > replies I found in the archives.
> >
> > As this is such a standard procedure in psychological science, there
> > must be an elegant solution to this...I think.
> >
> > I would much appreciate a solution that even I could understand... ;-)
> >
> >
> > Now, I want to calculate a post-hoc test following up a within-subjects
> > ANOVA.
> >
> > The dv is reaction time (RT), there is a 3-level Condition factor
> > (Cond; within-subjects), a number of subjects (Subj), and the
> > dataframe is called WMU3C.
> >
> > The model is
> >
> >  > RT.aov <- aov(RT~Cond + Error(Subj/Cond), WMU3C)
> >
> > I understand that TukeyHSD only works with an aov object, but that
> > RT.aov is an aovlist object.
> >
> >  > class(RT.aov)
> > [1] "aovlist" "listof"
> >
> > I've tried to work around it using the "maiz" example in the MMC
> > documentation of the HH package (a solution previously recommended),
> > but I couldn't get it to work: My best shot was to calculate another
> > aov avoiding the error term (I don't see how this could be a feasible
> > approach, but that's how I understood the MMC example) and a contrast
> > vector (contrasting conditions 2 and 3):
> >
> > I have to admit that I don't quite understand what I'm doing here
> > (not that you couldn't tell)
> >
> >  > RT2.aov <- aov(terms(RT~Subj*Cond, WMU3C))
> >  > Cond.lmat <- c(0,1,-1)
> >  > Tukey <- glht.mmc(RT2.aov, focus = "Cond", focus.lmat = Cond.lmat)
> >
> > yielding
> >
> > Error in mvt(lower = carg$lower, upper = carg$upper, df = df, corr =
> > carg$corr,  :
> >NA/NaN/Inf in foreign function call (arg 6)
> > In addition: Warning message:
> > In cov2cor(covm) : diagonal has non-finite entries
> >
> >  > Tukey
> >height
> >
> >
> >
> > Thank you very much for your help!
> >
> > Ullrich
> >
> >
> > Dr Ullrich Ecker
> > Postdoctoral Research Associate
> > Cognitive Science Laboratories
> > School of Psychology (Mailbag M304)
> > Room 211 Sanders Building
> > University of Western Australia
> > 35 Stirling Hwy
> > Crawley WA 6009
> > Australia
> > Office: +61 8 6488 3266
> > Mobile: +61 4 5822 0072
> 

Re: [R] Tukey HSD (or other post hoc tests) following repeated measures ANOVA

2008-05-29 Thread Ullrich Ecker

Thanks, Dieter,

but as far as I understand,  'glht' does not support objects of class 
'aovlist' either. I mean, I know there is a "TukeyHSD" function out 
there, but that's the problem: repeated measures ANOVA yields an 
aovlist object, and TukeyHSD calls for an aov object.


And I don't know if confidence intervals are "certainly much better 
than p-values". What I do know is that most journals of psychology 
(and medicine, neuroscience, ...for that matter) usually require 
p-values be reported.



Still hope someone can help...

Ullrich


At 06:31 PM 28/05/2008, you wrote:

Ullrich Ecker  uwa.edu.au> writes:

> I am fairly new to R, and I am aware that others have had this
> problem before, but I have failed to solve the problem from previous
> replies I found in the archives.
>
> Now, I want to calculate a post-hoc test following up a 
within-subjects ANOVA.



Probably the best is package multcomp. By default, it gives confidence
intervals, which is certainly much better than p-values. Haven't tried if you
can get p-values.

Dieter


library(multcomp)
amod <- aov(breaks ~ wool + tension, data = warpbreaks)
wht <- glht(amod, linfct = mcp(tension = "Tukey"))

__
R-help@r-project.org 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.


__
R-help@r-project.org 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.


[R] Tukey HSD (or other post hoc tests) following repeated measures ANOVA

2008-05-28 Thread Ullrich Ecker
Hi everyone,

I am fairly new to R, and I am aware that others have had this 
problem before, but I have failed to solve the problem from previous 
replies I found in the archives.

As this is such a standard procedure in psychological science, there 
must be an elegant solution to this...I think.

I would much appreciate a solution that even I could understand... ;-)


Now, I want to calculate a post-hoc test following up a within-subjects ANOVA.

The dv is reaction time (RT), there is a 3-level Condition factor 
(Cond; within-subjects), a number of subjects (Subj), and the 
dataframe is called WMU3C.

The model is

 > RT.aov <- aov(RT~Cond + Error(Subj/Cond), WMU3C)

I understand that TukeyHSD only works with an aov object, but that 
RT.aov is an aovlist object.

 > class(RT.aov)
[1] "aovlist" "listof"

I've tried to work around it using the "maiz" example in the MMC 
documentation of the HH package (a solution previously recommended), 
but I couldn't get it to work: My best shot was to calculate another 
aov avoiding the error term (I don't see how this could be a feasible 
approach, but that's how I understood the MMC example) and a contrast 
vector (contrasting conditions 2 and 3):

I have to admit that I don't quite understand what I'm doing here 
(not that you couldn't tell)

 > RT2.aov <- aov(terms(RT~Subj*Cond, WMU3C))
 > Cond.lmat <- c(0,1,-1)
 > Tukey <- glht.mmc(RT2.aov, focus = "Cond", focus.lmat = Cond.lmat)

yielding

Error in mvt(lower = carg$lower, upper = carg$upper, df = df, corr = 
carg$corr,  :
   NA/NaN/Inf in foreign function call (arg 6)
In addition: Warning message:
In cov2cor(covm) : diagonal has non-finite entries

 > Tukey
   height



Thank you very much for your help!

Ullrich


Dr Ullrich Ecker
Postdoctoral Research Associate
Cognitive Science Laboratories
School of Psychology (Mailbag M304)
Room 211 Sanders Building
University of Western Australia
35 Stirling Hwy
Crawley WA 6009
Australia
Office: +61 8 6488 3266
Mobile: +61 4 5822 0072
Fax: +61 8 6488 1006
E-mail: [EMAIL PROTECTED]
Web: www.cogsciwa.com  
[[alternative HTML version deleted]]

__
R-help@r-project.org 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.