Rob Forsyth
Rob Forsyth

Reputation: 155

specifying grouping factor in lme fixed effect formula

My dataset comprises two observations of a numeric score ("Participation") each at beginning and end of treatment for 70 individuals. The times are not constant between individuals but visual inspection of these shows the large majority rise over the period

sfa <- read.csv("SFAFinalData.csv", header = TRUE)
groupingFormula <- as.formula(paste(columnName,"~ TIME|ID")) 
dataSubset <- na.omit(sfa[,seq(1:6)])
inputData <- groupedData(groupingFormula, data=dataSubset, labels = list("Weeks post injury", columnName))
m1 <- lme(inputData)

Works as expected

> m1
Linear mixed-effects model fit by REML
Data: inputData 
Log-restricted-likelihood: -631.7963
Fixed: Participation ~ TIME 
(Intercept)        TIME 
18.7616485   0.4220891 

Random effects:
Formula: ~TIME | ID
Structure: General positive-definite
        StdDev     Corr  
(Intercept) 15.4985010 (Intr)
TIME         0.2192035 1     
Residual    13.2272350       

Number of Observations: 140
Number of Groups: 70 

I'm now trying to compare the analysis (i.e. participation as a function of time) in each of three subgroups ("TYPE": factor with three levels with 10, 29 and 31 individuals respectively) but

m2 <- update(m1, fixed = .~.*TYPE)

leads to an error

Warning message:
In lme.formula(fixed = Participation ~ TYPE, data = inputData) :
Fewer observations than random effects in all level 1 groups

Struggling to see what I'm doing wrong here: as far as I can see I have enough observations?

Upvotes: 2

Views: 2590

Answers (1)

Dieter Menne
Dieter Menne

Reputation: 10215

Try not to use groupedData. I know, the examples in the book use it very often, but I find it the most confusing part of lme. And avoid . in formulae, it can be very greedy might lead to the type of error messages.

With a lot of guessing (please at least post str(sfa)), I assume you want something like:

sfa <- read.csv("SFAFinalData.csv", header = TRUE)
# No grouped Data!
lme(Participation~TIME*TYPE,random=~1|ID,data=sfa)

Upvotes: 2

Related Questions