<div dir="ltr"><div><div><div>Hi all,<br><br></div>My name is Daniel Moreno. I am working in forest regeneration and I am trying to explain the factors which involves the regeneration in a experiment composed by transects, plots and subplots. I have count data and I would like to fit a negative binomial with a log link function. Below, you can see the structure of the full data (excuse me for the Spanish code):<br>
<br><span style="color:rgb(255,0,0)"> str(todonava)</span><br><span style="color:rgb(56,118,29)">'data.frame': 170 obs. of 41 variables:<br> $ COD : int 9 10 11 12 13 14 15 16 17 18 ...<br> $ Subplot : Factor w/ 170 levels "1C5-3-1","1C5-3-2",..: 1 2 3 4 5 6 7 8 9 10 ...<br>
$ Plot : Factor w/ 43 levels "1C5-3","1C5-4",..: 1 1 1 1 2 2 2 2 3 3 ...<br> $ Transecto : Factor w/ 5 levels "1C5","2A5","2B5",..: 1 1 1 1 1 1 1 1 1 1 ...<br>
$ Seedlings : int 9 59 5 92 8 11 4 4 22 33 ...<br> $ isf : num 0.852 0.848 0.855 0.862 0.82 ...<br> $ dsf : num 0.812 0.785 0.807 0.835 0.812 ...<br> $ gsf : num 0.817 0.793 0.813 0.838 0.813 ...<br>
$ altitud : int 1730 1730 1730 1730 1730 1730 1730 1730 1730 1730 ...<br> $ pendgrados : num 14 11 12 16 16 15 15 17 19 11 ...<br> $ pend100 : num 25 20 22 29 29 27 28 32 35 20 ...<br> $ numfoto : int 9 10 11 12 13 14 15 16 17 18 ...<br>
$ ph : num 4.67 4.67 4.67 4.67 8.45 8.45 8.45 8.45 4.76 4.76 ...<br> $ conductividad : num 0.08 0.08 0.08 0.08 0.2 0.2 0.2 0.2 0.08 0.08 ...<br> $ arena : num 71 71 71 71 58 ...<br> $ limo : num 11 11 11 11 12.6 ...<br>
$ arcilla : num 18.4 18.4 18.4 18.4 29.4 ...<br> $ MO : num 13.9 13.9 13.9 13.9 17.4 ...<br> $ potasio : int 134 134 134 134 182 182 182 182 180 180 ...<br> $ fosforo : num 11.5 11.5 11.5 11.5 13.5 13.5 13.5 13.5 8.8 8.8 ...</span><br>
<br></div>Some variables contains NA values (e.g. fosforo (fosforo=<span id="result_box" class="" lang="en"><span class="">phosphorus)). Below, it is possible to read my R code (to fit the best model and avoid overparametization I use a stepwise model selection) and some Errors:<br>
<br><span style="color:rgb(204,0,0)">> todo2<-glmmadmb(Seedlings~Transecto + fosforo + (1|Plot), na.omit, data=todonava, zeroInflation=FALSE, family="nbinom", link="log")</span><br><br><span style="color:rgb(39,78,19)">Error in II[, ii] = II[, ii] + REmat$codes[[i]] : <br>
number of items to replace is not a multiple of replacement length<br>In addition: Warning messages:<br>1: In glmmadmb(Seedlings ~ Transecto + fosforo + (1 | Plot), data = todonava, :<br> NAs removed in constructing fixed-effect model frame: you should probably remove them manually, e.g. with na.omit()<br>
2: In II[, ii] + REmat$codes[[i]] :<br> longer object length is not a multiple of shorter object length</span><br><br></span></span></div><span id="result_box" class="" lang="en"><span class="">It could be a NA problem. Then, I removed NA values:<br>
<span style="color:rgb(204,0,0)"><br>navana<-na.omit(todonava)</span><br><br><span style="color:rgb(204,0,0)"> str(navana)</span><br><span style="color:rgb(56,118,29)">'data.frame': 0 obs. of 41 variables:<br>
$ COD : int <br> $ Subplot : Factor w/ 170 levels "1C5-3-1","1C5-3-2",..: <br> $ Plot : Factor w/ 43 levels "1C5-3","1C5-4",..: <br> $ Transecto : Factor w/ 5 levels "1C5","2A5","2B5",..: <br>
$ Seedlings : int <br> $ isf : num <br> $ dsf : num <br> $ gsf : num <br> $ altitud : int <br> $ pendgrados : num <br> $ pend100 : num <br> $ numfoto : int <br>
$ ph : num <br> $ conductividad : num <br> $ arena : num <br> $ limo : num <br> $ arcilla : num <br> $ MO : num <br> $ potasio : int <br> $ fosforo : num <br>
$ magnesio : num <br> $ calcio : num <br> $ sodio : num <br> $ texturaISSS : Factor w/ 5 levels " arcillo arenoso",..: <br> $ F25 : logi <br> $ lnca : num <br> $ lnconductividad: num <br>
$ lnfosforo : num <br> $ gsfcuadrado : num <br> $ lnMg : num <br> $ lnpotasio : num <br> $ raizpotasio : num <br> $ lnsodio : num <br> $ ipot : num <br> $ ifn : num <br>
$ trees : int <br> $ stump : int <br> $ perctrees : num <br> $ percstumps : num <br> $ pedre : num <br> $ Lnpedre : num <br> - attr(*, "na.action")=Class 'omit' Named int [1:170] 1 2 3 4 5 6 7 8 9 10 ...<br>
.. ..- attr(*, "names")= chr [1:170] "1" "2" "3" "4" ...<br><br></span></span></span><div><span id="result_box" class="" lang="en"><span class=""><span style="color:rgb(56,118,29)"><font color="#000000">Then, I run again the model with the new data frame:<br>
<span style="color:rgb(204,0,0)"><br>> todo3<-glmmadmb(Seedlings~Transecto + fosforo + (1|Plot), na.omit, data=navana, zeroInflation=FALSE, family="nbinom", link="log")</span><br><span style="color:rgb(39,78,19)">Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) : <br>
contrasts can be applied only to factors with 2 or more levels</span><br></font></span></span></span></div><div><span id="result_box" class="" lang="en"><span class=""><br></span></span></div><div><span id="result_box" class="" lang="en"><span class="">I am new with R (till now, I worked with SAS). Could you help me to solve this problems)<br>
<br></span></span></div><div><span id="result_box" class="" lang="en"><span class="">Thanks you all,<br><br></span></span></div><div><span id="result_box" class="" lang="en"><span class="">Daniel<br></span></span></div><div>
<span id="result_box" class="" lang="en"><span class=""><br></span></span><div><br></div></div></div>