简体   繁体   中英

How do i do a nested model in R or glm and ANOVA?

I've been struggling with this for a bit but I'm currently trying to analyse my data and I have this code so far:

data2 <- read.table("B.txt",header=T)

attach(data2)

Sex <- as.factor(Sex)

Class <- as.factor(Class)

Order <- as.factor(Order)

Envi <- as.factor(Environment)

model1 <- glm(LS~Sex*Class*Envi)

model2 <- glm(LS~Sex*Class)

model3 <- glm(LS~Sex)

model4 <- glm(LS~Class)

model5 <- glm(LS~Envi)

But I've been told that I will have to nest Order within class as with my dataset my degrees of freedom will be my class and an interaction test might not be the best way to go. The class is a fixed effect with order being random. How would I nest order within class so that I would be testing lifespan against Sex with class? And is there a better way to test this?

I understand from the description of the problem that order is a random effect nested in Class . Mixed models can be implemented from several packages, in example:

library(lme4)
glmer(LS~Sex*Class +(1|Order:Class), data=data2)

We estimate Sex:Class interaction and order random effect in the same model

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM