eval(predvars,data,env)中的错误:找不到对象“下水道”

时间:2018-08-25 20:21:34

标签: r

我有一组包含物种名称和编号(spp_data)的数据,我正在尝试测试物种如何受到不同参数(例如pH,电导率以及下水道位置)的影响(上游/下游)({env_data1)。 当我尝试运行lm()时,出现以下错误:

lm1 <- lm(specnumber ~ Sewer + pH + Conductivity, data=spp_data,env_data1)
  

eval(predvars,data,env)中的错误:找不到对象“下水道”

是因为列Sewer是非数字的吗? 我还尝试排除该列并运行lm(),但它不起作用。

物种数据

summary(spp_data)
    Pisidium        G_pulex         C_pseudo        A_aquatic          V_pisc       
 Min.   :0.000   Min.   : 0.00   Min.   : 0.000   Min.   :0.0000   Min.   :0.00000  
 1st Qu.:0.000   1st Qu.: 3.00   1st Qu.: 0.000   1st Qu.:0.0000   1st Qu.:0.00000  
 Median :0.000   Median : 8.00   Median : 3.000   Median :0.0000   Median :0.00000  
 Mean   :1.429   Mean   :16.86   Mean   : 4.476   Mean   :0.5714   Mean   :0.04762  
 3rd Qu.:2.000   3rd Qu.:20.00   3rd Qu.:10.000   3rd Qu.:0.0000   3rd Qu.:0.00000  
 Max.   :7.000   Max.   :68.00   Max.   :16.000   Max.   :4.0000   Max.   :1.00000  

    Taeniopt          Rhyacoph         Hydropsy        Lepidost        Glossos     
 Min.   :0.00000   Min.   :0.0000   Min.   :0.000   Min.   :0.000   Min.   : 0.00  
 1st Qu.:0.00000   1st Qu.:0.0000   1st Qu.:0.000   1st Qu.:0.000   1st Qu.: 0.00  
 Median :0.00000   Median :0.0000   Median :0.000   Median :0.000   Median : 0.00  
 Mean   :0.09524   Mean   :0.2381   Mean   :1.286   Mean   :1.238   Mean   : 1.81  
 3rd Qu.:0.00000   3rd Qu.:0.0000   3rd Qu.:3.000   3rd Qu.:2.000   3rd Qu.: 1.00  
 Max.   :2.00000   Max.   :2.0000   Max.   :5.000   Max.   :7.000   Max.   :14.00  
    Agapetus         Hydroptil          Limneph         S_person           Tipula 
 Min.   : 0.0000   Min.   :0.00000   Min.   :0.000   Min.   :0.00000   Min.   :0  
 1st Qu.: 0.0000   1st Qu.:0.00000   1st Qu.:0.000   1st Qu.:0.00000   1st Qu.:0  
 Median : 0.0000   Median :0.00000   Median :0.000   Median :0.00000   Median :0  
 Mean   : 0.5714   Mean   :0.04762   Mean   :0.381   Mean   :0.09524   Mean   :0  
 3rd Qu.: 0.0000   3rd Qu.:0.00000   3rd Qu.:1.000   3rd Qu.:0.00000   3rd Qu.:0  
 Max.   :12.0000   Max.   :1.00000   Max.   :2.000   Max.   :2.00000   Max.   :0  
    Culicida         Ceratopo     Simuliid          Chrinomi         Chrnomus     
 Min.   :0.0000   Min.   : 0   Min.   : 0.0000   Min.   : 0.000   Min.   : 0.000  
 1st Qu.:0.0000   1st Qu.: 0   1st Qu.: 0.0000   1st Qu.: 0.000   1st Qu.: 1.000  
 Median :0.0000   Median : 1   Median : 0.0000   Median : 2.000   Median : 3.000  
 Mean   :0.5714   Mean   : 7   Mean   : 0.5238   Mean   : 7.286   Mean   : 6.095  
 3rd Qu.:0.0000   3rd Qu.: 8   3rd Qu.: 0.0000   3rd Qu.: 8.000   3rd Qu.: 6.000  
 Max.   :5.0000   Max.   :31   Max.   :10.0000   Max.   :67.000   Max.   :41.000  

环境数据

summary(env_data)
    Sample             Sewer                 pH        Conductivity      
 Length:21          Length:21          Min.   :7.780   Length:21         
 Class :character   Class :character   1st Qu.:7.850   Class :character  
 Mode  :character   Mode  :character   Median :8.100   Mode  :character  
                                       Mean   :8.044                     
                                       3rd Qu.:8.270                     
                                       Max.   :8.280                     
     Depth           %rock            %mud      %sand,,         
 Min.   : 7.00   Min.   :10.00   Min.   : 0   Length:21         
 1st Qu.: 8.00   1st Qu.:10.00   1st Qu.:20   Class :character  
 Median :11.00   Median :70.00   Median :30   Mode  :character  
 Mean   :17.14   Mean   :57.14   Mean   :40                     
 3rd Qu.:28.00   3rd Qu.:80.00   3rd Qu.:90                     
 Max.   :40.00   Max.   :90.00   Max.   :90

1 个答案:

答案 0 :(得分:2)

假设您spp_data的行与您的环境数据的行匹配...我想您可以

lm1 <- lm(as.matrix(spp_data) ~ Sewer + pH + Conductivity, 
        data=env_data1)

您将获得运行44个单独的线性模型的结果,每个物种一个。 (请注意:使用44个回归和仅21个观察值,您可能需要进行多次比较校正,以免夸大您的结论。)

有用于更复杂的多物种分析的R包,例如mvabundgllvm,但它们可能不适用于如此大小的数据集...