Statistics/Fit models
3. Generalized linear model...
modernity4Rcmdr
2022. 3. 9. 14:42
통계 > 적합성 모델 > 일반화 선형 모델...
Statistics > Fit models > Generalized linear model...
MASS 패키지에 있는 birthwt 데이터셋을 활용하자. https://rcmdr.tistory.com/149
birthwt 데이터셋을 <일반화 선형 모델> 분석을 위하여 변형시켜서 bwt라는 데이터셋으로 만들자.
bwt <- with(birthwt, {
race <- factor(race, labels = c("white", "black", "other"))
ptd <- factor(ptl > 0)
ftv <- factor(ftv)
levels(ftv)[-(1:2)] <- "2+"
data.frame(low = factor(low), age, lwt, race, smoke = (smoke > 0),
ptd, ht = (ht > 0), ui = (ui > 0), ftv)
})
options(contrasts = c("contr.treatment", "contr.poly"))
bwt 데이터셋을 활성화시키자.
GLM.3 <- glm(low ~ ., family=binomial(logit), data=bwt)
summary(GLM.3)
exp(coef(GLM.3)) # Exponentiated coefficients ("odds ratios")
## an example with offsets from Venables & Ripley (2002, p.189)
utils::data(anorexia, package = "MASS")
GLM.2 <- glm(Postwt ~ Prewt + Treat + offset(Prewt),
family=gaussian(identity), data=anorexia)
summary(GLM.2)
data(Cowles, package="carData")
GLM.1 <- glm(volunteer ~ sex + neuroticism*extraversion, family=binomial(logit), data=Cowles)
summary(GLM.1)
exp(coef(GLM.1)) # Exponentiated coefficients ("odds ratios")