logistic regression - R glm object and prediction using offsets -
so i'm using r logistic regression, i'm using offsets.
mylogit <- glm(y ~ x1 + offset(0.2*x2) + offset(0.4*x3), data = test, family = "binomial") the output, shows single coefficient, intercept , 1 of predictors, x1.
coefficients: (intercept) x1 0.5250748 0.0157259 my question: how raw prediction each observation model? more specifically, if use predict function, include features , coefficients, though model coefficients listed containing intercept , x1?
prob = predict(mylogit,test,type=c("response")) do have use predict function? "mylogit" object contain can compute directly from? (yes looked @ documentation on glm, still confused).
thank patients.
i can report results of experiments glm , offset(). not appear (at least experiment) call predict give results take offset account. rather seems summary.glm needed purpose. started rather mangled modification of 1st example in ?glm ( , more pertinent concerns if did provide data, because play around more newdata argument need "test".)
counts <- c(18,17,15,20,10,20,25,13,12) outcome <- gl(3,1,9) treatment <- gl(3,3) print(d.ad <- data.frame(treatment, outcome, counts)) glm.d93 <- glm(counts ~ outcome + treatment + offset(1:9), family = poisson()) glm.d93d <- glm(counts ~ outcome + treatment , family = poisson()) > predict(glm.d93d, type="response") 1 2 3 4 5 6 7 8 9 21.00000 13.33333 15.66667 21.00000 13.33333 15.66667 21.00000 13.33333 15.66667 > predict(glm.d93, type="response") 1 2 3 4 5 6 7 8 9 21.00000 13.33333 15.66667 21.00000 13.33333 15.66667 21.00000 13.33333 15.66667 as far can tell offset apparent when comparisons of estimated coefficients made null estimate (usually 0) purposes of statistical inference. done summary.glm:
> summary(glm.d93)$coef estimate std. error z value pr(>|z|) (intercept) 2.044522 0.1708987 11.963362 5.527764e-33 outcome2 -1.454255 0.2021708 -7.193203 6.328878e-13 outcome3 -2.292987 0.1927423 -11.896644 1.232021e-32 treatment2 -3.000000 0.2000000 -15.000000 7.341915e-51 treatment3 -6.000000 0.2000000 -30.000000 9.813361e-198 > summary(glm.d93d)$coef estimate std. error z value pr(>|z|) (intercept) 3.044522e+00 0.1708987 1.781478e+01 5.426767e-71 outcome2 -4.542553e-01 0.2021708 -2.246889e+00 2.464711e-02 outcome3 -2.929871e-01 0.1927423 -1.520097e+00 1.284865e-01 treatment2 1.337909e-15 0.2000000 6.689547e-15 1.000000e+00 treatment3 1.421085e-15 0.2000000 7.105427e-15 1.000000e+00 the offset changing reference levels (with bizarre changes in mangled example) while fitting of $linear.predictors , $fitted data not affected. didn't see comment in glm affects there comment in ?lm : "offsets specified offset not included in predictions predict.lm, whereas specified offset term in formula be." admit got little insight reading ?model.offset.
Comments
Post a Comment