Prediction for poisson model in R

by Mary   Last Updated March 14, 2019 20:19 PM - source

I am fitting a glm model:

model_poisson<- glm(y~X, family="poisson")

Where X is a matrix of 5 coloums in which a log trasnformation has been applied (X<- log(X+0.0001)) since the data inside were extremely big.

Call:
glm(formula = y ~ X, family = "poisson")

Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-298.83   -44.30   -12.06    29.77  1195.29  

Coefficients:
                    Estimate Std. Error z value Pr(>|z|)    
(Intercept)        3.733e+00  5.894e-04  6333.9   <2e-16 ***
Xfemale            5.182e-01  7.667e-05  6759.6   <2e-16 ***
Xmale              9.882e-03  4.329e-05   228.3   <2e-16 ***
Xo                 2.170e-01  8.620e-05  2517.5   <2e-16 ***
Xs                 7.965e-02  4.736e-05  1681.8   <2e-16 ***
Xt                 3.994e-02  4.539e-05   880.1   <2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for poisson family taken to be 1)

    Null deviance: 170764926  on 4942  degrees of freedom
Residual deviance:  36935043  on 4937  degrees of freedom
AIC: 36982563

Number of Fisher Scoring iterations: 6

How can I read the estimated coefficients?

I need also to access this model throught prediction, I have to fit the model on 80% of the data and test it on the other 20%.

 ndata <- length(y)
    ntraining <- ceiling(0.8*ndata)
    ntest <- ndata-ntraining
    training_indices<- sample(1:ndata, ntraining, replace=FALSE)
    training_m <- m[training_indices]
    training_X<- X[training_indices, ]
    training_X<- log(training_X+0.00001)
    test_set <- m[-training_indices]
    test_X<- X[-training_indices, ]
    test_X<-as.data.frame(test_X)

Hence my model is:

model_poisson_training<- glm(training_m ~ training_X, family="poisson")
summary(model_poisson_training)
coef.poisson<-model_poisson_training$coefficients

How can I use the test set?

Tags : r model prediction


Related Questions