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]]

