You are using the `scale` function which subtracts the mean and divides by the standard deviation, but the `glm` function does not do the same thing by default, so that is the likely reason that you are seeing a difference. Try doing it without the call to `scale` and see if that gives you what you are expecting.
On Sat, Sep 21, 2013 at 11:53 PM, ÔÀÚS <yue...@139.com> wrote: > Dear Greg Snow**** > > I mean in the help documentation of predict.glm, the arguments of ¡°type¡± > wrote that ¡°The "terms" option returns a matrix giving the fitted values > of each term in the model formula on the linear predictor scale.¡± But I > can¡¯t get the same result of the function if I computed like the > documatation said! I just want to know if you can get the same result of > the ¡°predict.glm(,¡°terms¡±)¡± if you compute by yourself? Thank you very > much!!!**** > > ** ** > > *·¢¼þÈË:* Greg Snow [mailto:538...@gmail.com] > *·¢ËÍʱ¼ä:* 2013Äê9ÔÂ19ÈÕ 0:20 > *ÊÕ¼þÈË:* ÔÀÚS > *³ËÍ:* r-help > *Ö÷Ìâ:* Re: [R] the values of predict( , type = "terms", )**** > > ** ** > > What do you get with:**** > > ** ** > > sample$x * coef(s_model)[-1]**** > > ** ** > > ** ** > > ** ** > > ** ** > > On Tue, Sep 17, 2013 at 3:09 AM, ÔÀÚS <yue...@139.com> wrote:**** > > hello all > > I am really confusing that how predict(,type = "terms",) gets the desired > result. For example, > > sample <- matrix(nrow = 10, ncol = 2) > > colnames(sample) <- c("y","x") > > sample[,1] <- c(rep(1,times = 5), rep(0,times = 5)) > > sample[,2] <- c(1,1,0,1,1,0,1,0,0,1) > > sample <- as.data.frame(sample) > > s_model <- glm(y~x, data = sample, family = binomial(link = "logit")) > > s_pred <- predict(s_model, type = "terms", sample) > > print(s_pred) > > x > > 1 0.7167038 > > 2 0.7167038 > > 3 -1.0750557 > > 4 0.7167038 > > 5 0.7167038 > > 6 -1.0750557 > > 7 0.7167038 > > 8 -1.0750557 > > 9 -1.0750557 > > 10 0.7167038 > > attr(,"constant") > > [1] -0.02355661 > > > > But, if i compute it by myself, i can't get the same result. Is the formula > like this: > > scale(sample$x)*coef(s_model)[-1] > > [,1] > > [1,] 1.387891 > > [2,] 1.387891 > > [3,] -2.081836 > > [4,] 1.387891 > > [5,] 1.387891 > > [6,] -2.081836 > > [7,] 1.387891 > > [8,] -2.081836 > > [9,] -2.081836 > > [10,] 1.387891 > > attr(,"scaled:center") > > [1] 0.6 > > attr(,"scaled:scale") > > [1] 0.5163978 > > > > Can someone help me? Thank you! > > > > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@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.**** > > > > **** > > ** ** > > -- > Gregory (Greg) L. Snow Ph.D. > 538...@gmail.com **** > -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com [[alternative HTML version deleted]]
______________________________________________ R-help@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.