통계 > 적합성 모델 > 일반화 선형 모델...
Statistics > Fit models > Generalized linear model...

MASS 패키지에 있는 birthwt 데이터셋을 활용하자. https://rcmdr.tistory.com/149
birthwt 데이터셋
MASS > birthwt data(birthwt, package="MASS") birthwt 데이터셋이 활성화된 후, <데이터셋 보기> 버튼을 누르면 아래와 같이 내부 구성을 볼 수 있다: help("birthwt")
rcmdr.kr
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")

'Statistics > Fit models' 카테고리의 다른 글
5. Ordinal regression model... (0) | 2022.06.24 |
---|---|
6. Linear mixed model... (0) | 2022.06.23 |
4. Multinomial logit model... (0) | 2022.03.09 |
2. Linear model... (0) | 2022.03.07 |
1. Linear regression... (0) | 2022.03.07 |