R中的泊松模型预测

时间:2019-03-14 14:01:16

标签: r model prediction data-fitting poisson

我正在安装[1,2,3,4]模型:

glm

其中X是5列的矩阵,由于内部数据非常大,因此已应用对数转换(model_poisson<- glm(y~X, family="poisson")。

X<- log(X+0.0001)

如何读取估计的系数?

我还需要通过预测访问此模型,我必须将模型拟合80%的数据,并在其他20%的数据上进行测试。

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

因此我的模型是:

 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)

如何使用测试仪?

0 个答案:

没有答案