glm()의 기본 lm() 함수

R에서 Generalized Linear Models

Richard Erickson

Instructor

모델 객체 다루기

  • 출력 결과와의 상호작용 허용
  • 기본 R 함수를 glm()에 적용
  • 유용한 단축 기능
R에서 Generalized Linear Models

모델 출력

  • print()가 일반적으로 기본값
print(poisson_out)
Call:  glm(formula = y ~ x, family = "poisson", data = dat)

Coefficients:
(Intercept)            x  
   -1.43036      0.05815  

Degrees of Freedom: 29 Total (i.e. Null);  28 Residual
Null Deviance:        35.63 
Residual Deviance: 30.92     AIC: 66.02
R에서 Generalized Linear Models

모델 요약

  • summary()는 더 자세한 정보를 제공합니다
summary(poisson_out)
#...
Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-1.6547  -0.9666  -0.7226   0.3830   2.3022

Coefficients: Estimate Std. Error z value Pr(>|z|) (Intercept) -1.43036 0.59004 -2.424 0.0153 * x 0.05815 0.02779 2.093 0.0364 *
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(Dispersion parameter for poisson family taken to be 1)
Null deviance: 35.627 on 29 degrees of freedom Residual deviance: 30.918 on 28 degrees of freedom AIC: 66.024
Number of Fisher Scoring iterations: 5
R에서 Generalized Linear Models

정돈된 출력

library(broom)
tidy(poisson_out)
         term    estimate  std.error statistic    p.value
1 (Intercept) -1.43035579 0.59003923 -2.424171 0.01534339
2           x  0.05814858 0.02778801  2.092578 0.03638686
R에서 Generalized Linear Models

회귀 계수

  • coef()는 회귀 계수를 출력합니다
coef(poisson_out)
(Intercept)           x 
-1.43035579  0.05814858
R에서 Generalized Linear Models

신뢰 구간

  • confint()는 신뢰 구간을 추정합니다
confint(poisson_out)
Waiting for profiling to be done...
               2.5 %     97.5 %
(Intercept) -2.725545344 -0.3897748
x            0.005500767  0.1155564
R에서 Generalized Linear Models

예측

  • predict(model, new_data)
  • new_data 인수:
    • 미지정: predict()는 모델 적합에 사용된 원본 데이터로 예측값을 반환합니다.
    • 지정: predict()new_data에 대한 예측값을 반환합니다.
R에서 Generalized Linear Models

화재 부상 데이터셋

  • 일별 민간인 부상
  • 켄터키주 루이빌
  • 계수 데이터, 다수의 0값

루이빌(KY)의 일별 화재 부상 현황

R에서 Generalized Linear Models

연습해 봅시다!

R에서 Generalized Linear Models

Preparing Video For Download...