R中的GLM,理解为什么忽略系数

时间:2017-03-22 00:39:53

标签: r glm

我正在使用R为蚜虫和寄生虫数据创建glm。 这是我正在使用的模型

Aphid_glm.full8 = glm(Field.Abundance~Region-1+Total_Rainfall+Species+GS+Date, family=gaussian())

我得到以下输出

Aphid_glm.full8 = glm(Field.Abundance~Region-1+Total_Rainfall+Species+GS+Date, family=gaussian())
Error in eval(expr, envir, enclos) : object 'Field.Abundance' not found
> summary(Aphid_glm.full8)

Call:
glm(formula = Field.Abundance ~ Region + Date + Total_Rainfall + 
    Species + GS, family = gaussian())

Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-61.947   -8.323    0.085    4.574  164.910  

Coefficients: (3 not defined because of singularities)
                            Estimate Std. Error t value Pr(>|t|)    
(Intercept)                  65.5787    17.7445   3.696 0.000284 ***
RegionTarlee                -12.9239    10.8321  -1.193 0.234251    
RegionWalkers Flat           20.2769    12.6896   1.598 0.111655    
Date13/09/2016               -7.0521    13.6629  -0.516 0.606329    
Date13/10/2016               -9.4719    10.3875  -0.912 0.362956    
Date15/09/2016                9.8287    10.3489   0.950 0.343405    
Date16/11/2016               29.6553    14.9223   1.987 0.048266 *  
Date17/11/2016               16.2882    11.9715   1.361 0.175194    
Date19/10/2016               21.8028    13.2087   1.651 0.100398    
Date2/12/2016                18.5352    16.1257   1.149 0.251770    
Date21/09/2016               33.2361    10.2939   3.229 0.001456 ** 
Date25/10/2016                4.9734    10.4278   0.477 0.633932    
Date26/08/2016                2.4930    11.6788   0.213 0.831188    
Date26/10/2016               -2.0381    10.1118  -0.202 0.840473    
Date3/11/2016                31.8712    15.4324   2.065 0.040206 *  
Date3/12/2016                24.8508    26.6299   0.933 0.351858    
Date30/09/2016              -23.8682    12.9022  -1.850 0.065814 .  
Date31/08/2016               23.7204    15.4324   1.537 0.125878    
Date4/12/2016                22.6700    26.6299   0.851 0.395633    
Date5/10/2016                 8.8952    10.9998   0.809 0.419677    
Date7/09/2016                34.4688    11.2740   3.057 0.002541 ** 
Date7/10/2016                     NA         NA      NA       NA    
Date9/11/2016                     NA         NA      NA       NA    
Total_Rainfall                    NA         NA      NA       NA    
SpeciesRhopalosiphum_maidis -11.5408     4.0173  -2.873 0.004512 ** 
SpeciesRhopalosiphum_padi    -9.3599     4.0173  -2.330 0.020817 *  
GS                           -0.8864     0.2699  -3.284 0.001212 ** 
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for gaussian family taken to be 592.0688)

    Null deviance: 221574  on 221  degrees of freedom
Residual deviance: 117230  on 198  degrees of freedom
AIC: 2071.8

Number of Fisher Scoring iterations: 2

然而,在'地区'我应该得到3个变量,但我只得到两个,对于' Species'

我的问题是:为什么我没有在分析输出中获得Region和Species的三个输出?只是它没有识别出这些变量吗?



https://1drv.ms/u/s!Ao4jj6OKiTAYgQmlpCxh1GiylZkx




1 个答案:

答案 0 :(得分:0)

使用以下代码,我得到三个系数区域,我几乎没有改变你的代码。

library(data.table) # to read data
data_in <- fread("FYPT.csv")
# remove spaces from column names
colnames(data_in) <- gsub("[[:space:]]", "_", colnames(data_in))

# run glm model
Aphid_glm.full8 = glm(Field_Abundance ~ Region-1+Total_Rainfall+Species+GS+Date, data = data_in, family=gaussian())

输出

> Aphid_glm.full8

Call:  glm(formula = Field_Abundance ~ Region - 1 + Total_Rainfall + 
Species + GS + Date, family = gaussian(), data = data_in)

Coefficients:
          RegionMundulla                 RegionTarlee           RegionWalkers Flat               Total_Rainfall  SpeciesRhopalosiphum_maidis  
               107.8518                      76.7179                      85.9857                      -0.6504                     -11.5408  
 SpeciesRhopalosiphum_padi                           GS               Date13/09/2016               Date13/10/2016               Date15/09/2016  
                -9.3599                      -0.8864                       6.3452                      -0.4970                      27.3883  
         Date16/11/2016               Date17/11/2016               Date19/10/2016                Date2/12/2016               Date21/09/2016  
                12.6160                      -8.4253                      14.6489                     -22.5672                      30.1144  
         Date25/10/2016               Date26/08/2016               Date26/10/2016                Date3/11/2016                Date3/12/2016  
                -5.0420                     -15.1967                       4.0753                      18.0837                     -16.2516  
         Date30/09/2016               Date31/08/2016                Date4/12/2016                Date5/10/2016                Date7/10/2016  
                26.4692                      30.0939                     -18.4325                      25.1540                           NA  
           Date7/9/2016                Date9/11/2016  
                     NA                           NA  

Degrees of Freedom: 222 Total (i.e. Null);  198 Residual
Null Deviance:      261500 
Residual Deviance: 117200   AIC: 2072