통계 > 적합성 모델 > 일반화 선형 혼합 모델... Statistics > Fit models > Generalized linear mixed model...
'도구 > 패키지 적재하기...' 메뉴 기능을 이용하여 lme4 패키지를 찾아서 적재하자. lme4 패키지에는 일반화 선형 혼합 모델을 만들고 분석하는데 필요한 glmer()와 예제 데이터셋 cbpp가 포함되어 있다.
'데이터 > 패키지에 있는 데이터 > 첨부된 패키지에서 데이터셋 읽기...' 메뉴 기능을 통하여 lme4 패키지에 있는 cbpp 데이터셋을 찾아서 선택하자. 그러면 R Commander의 상단에 있는 <활성 데이터셋 없음>이 'cbpp'로 활성화될 것이다. https://rcmdr.tistory.com/240
require(lme4)
data(cbpp, package="lme4")
GLMM.1 <- glmer(incidence / size ~ period + (1 | herd ), family=binomial(logit), data=cbpp,
weights=size)
summary(GLMM.1)
exp(coef(GLMM.1)) # Exponentiated coefficients ("odds ratios")
Anova(GLMM.1) # period 변수의 영향 여부 검정
## response as a matrix
(m1 <- glmer(cbind(incidence, size - incidence) ~ period + (1 | herd),
family = binomial, data = cbpp))
## response as a vector of probabilities and usage of argument "weights"
m1p <- glmer(incidence / size ~ period + (1 | herd), weights = size,
family = binomial, data = cbpp)
## Confirm that these are equivalent:
stopifnot(all.equal(fixef(m1), fixef(m1p), tolerance = 1e-5),
all.equal(ranef(m1), ranef(m1p), tolerance = 1e-5))
## GLMM with individual-level variability (accounting for overdispersion)
cbpp$obs <- 1:nrow(cbpp)
(m2 <- glmer(cbind(incidence, size - incidence) ~ period + (1 | herd) + (1|obs),
family = binomial, data = cbpp))
m1 <- glmer(cbind(incidence, size - incidence) ~ period + (1 | herd),
family = binomial, data = cbpp)
summary(m1)
Anova(m1)
m1p <- glmer(incidence / size ~ period + (1 | herd), weights = size,
family = binomial, data = cbpp)
summary(m1p)
Anova(m1p)
## GLMM with individual-level variability (accounting for overdispersion)
cbpp$obs <- 1:nrow(cbpp)
m2 <- glmer(cbind(incidence, size - incidence) ~ period + (1 | herd) + (1|obs),
family = binomial, data = cbpp)
summary(m2)
Anova(m2)
anova(m1, m2)