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
收件人: 岳赟
抄送: 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, 岳赟 <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 


        [[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.

Reply via email to