Tuesday, November 24, 2009

lme - lmer mixed models

Dear Kim,

first of all, please use lmer() from library "lme4", instead of lme. I think that is currently better maintained and developed than the "nlme" library.
The model you suggest is a random regression per individual (obs_nr)?
The syntax would become

library(lme4)
cocon_mixed<-lmer(MiWi~host_spec*ins_spec+(date|obs_nr),data=cocon_nash)

It should work provided there are several observations of MiWi for each level of obs_nr, which seems to be the case given your explanation of the data.

Cheers, Tom

Mixed effects models

Hi,

I am currently trying the exercises of Crawley on mixed effects model (ex. 7). I remade the example on page 33/34 and am currently trying tho do this analysis with my own data. I have a response variable (size=MiWi), measured at different dates (date) on the same individual (obs_nr = random variable). Further more I have insects species (ins_spec) and host species (host_spec) as fixed variables. When I run it I get the error message:

cocon_mixed<-lme(fixed=MiWi~host_spec*ins_spec,data=cocon_nash,random=~date|obs_nr) Error in lme.formula(fixed = MiWi ~ host_spec * ins_spec, data = cocon_nash, :
nlminb problem, convergence error code = 1
message = iteration limit reached without convergence (9)

What is going wrong?

Kim

Thursday, November 12, 2009

Course GLM Groningen

Hi,
I just returned from the glm course in Groningen. I will invite all participants to this blog in the coming days. Meanwhile, I already add a link to a page with several simple scripts:

http://tomvandooren.eu/tuto.html

As you will see, these files haven't been updated at all.
If things in them have become obsolete, please let me know.

Cheers, Tom

Saturday, April 07, 2007

random effects

Dear Tom,
my apologies for the long delay between you request and this answer.
First of all, why not include precipitation ("Precip") as a main effect too?

Using libray "nlme" and lme():
Random intercepts per station:
random= ~1|station
Don't forget the vertical bar!
Including random slope:
random= ~Precip|station
or
random= ~1+Precip|station

Make sure that all stations have different names, otherwise you run the risk that stations with identical names at different distances will be considered as a single station.

You could also consider to use the updated library now called "lme4".
Then the random effects are simply included as extra terms in the model statement.

Cheers, Tom

Wednesday, February 21, 2007

random components of lme-model

Hi everyone,

I'm currently analysing a large dataset with measurements of nutrients in the Dutch marine systems in R. I have a variable "OffshoreDist" representing the distance from the sampling location to the coast. I also calculated the total amount of precipitation over The Netherlands and called this variable "Precip".What I want to do is link mean annual dissolved inorganic nitrogen (DIN) to the amount of precipitation. I expect that this relationship is dependent on the offshore distance. Distance classes can contain 1 or more sampling stations.

That's why I propose these two models with different random components:
model1 <- lme(log(DIN) ~ Precip:factor(OffshoreDist) + factor(OffshoreDist),
random= ~1station)
model2 <- lme(log(DIN) ~ Precip:factor(OffshoreDist) + factor(OffshoreDist),
random= ~Precipstation)

Are these the right models for random intercepts per station (model1) and random slope+intercept per station (model2)? Or should this be something like:

random = ~ factor(OffshoreDist) -1 station (model 1)
and
random = ~ Precip:factor(OffshoreDist)station (model 2)

I've read Pinheiro & Bates, 2000 which is a good reference, but explanation of the formulae only by means of examples does not seem to work for me.

Thanks in advance.

Cheers,

Tom Van Engeland