[R] interpreting GLM results and plotting fits
Ista Zahn
istazahn at gmail.com
Mon Jul 1 00:11:01 CEST 2013
Hi Robert,
On Sun, Jun 30, 2013 at 1:40 AM, Robert Lynch <robert.b.lynch at gmail.com> wrote:
> I am trying to interpret the output of GLM and I am not sure how it is
> treating the factor GENDER with levels G-M and G-F.
Probably using dummy codes (or "treatment contrasts" as useRs refer to
them) unless you've changed the defaults. See
getOption("contrasts")
contr.treatment
contrasts(master1$Gender)
>
> Below is the output of summary(GPA.lm)
>
>
> Call:
> glm(formula = zGPA ~ Units.Bfr.7A * GENDER, data = Master1)
>
> Deviance Residuals:
> Min 1Q Median 3Q Max
> -1.1432 -0.3285 -0.1061 0.2283 1.8286
>
> Coefficients:
> Estimate Std. Error t value Pr(>|t|)
> (Intercept) -2.513e-01 2.238e-02 -11.230 < 2e-16 ***
> Units.Bfr.7A 2.297e-05 2.851e-04 0.081 0.936
> GENDERG-M 3.183e-01 4.536e-02 7.018 2.56e-12 ***
> Units.Bfr.7A:GENDERG-M -3.073e-03 5.975e-04 -5.142 2.82e-07 ***
> ---
> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
>
> (Dispersion parameter for gaussian family taken to be 0.2432662)
>
> Null deviance: 1204.2 on 4875 degrees of freedom
> Residual deviance: 1185.2 on 4872 degrees of freedom
> (106 observations deleted due to missingness)
> AIC: 6950.8
>
> Number of Fisher Scoring iterations: 2
>
>
>
> second I would like to draw two lines w/ confidince intervals on the
> scatter plot. One for G-M and the other for G-F
>
> I think I am doing this with
> stat_smooth(aes(group=GENDER), method="glm", fullrange=TRUE)
> but again am not sure quite what is being outputted.
I think this runs separate regressions for each level of group. That's
probably not quite what you want, though it may be close enough. A
better option would be to calculate predicted values and standard
errors from the model. You can do this several ways; here are two of
them:
## Option 1: create a data.frame containing the x values for which you
want predictions, and calculate predicted falues using predict()
m1PredData <- expand.grid(GENDER=levels(Master1$GENDER),
Units.Bfr.7A = with(Master1, {
seq(min(Units.Bfr.7A),
max(Units.Bfr.7A),
by=1)
}))
m1PredData <- cbind(m1PredData,
predict(GPA.lm,
se.fit=TRUE,
newdata=m1PredData))
## Option 2: Use the effects package:
library(effects)
m1Effects <- effect("Units.Bfr.7A:GENDER", GPA.lm, se=TRUE)
plot(m1Effects)
Hope this helps,
Ista
>
> [[alternative HTML version deleted]]
>
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
More information about the R-help
mailing list