model selection and density estimation

235 views
Skip to first unread message

Antonela Marozzi

unread,
Aug 9, 2016, 3:17:14 PM8/9/16
to unmarked

Hello dear all, I am new at the unmarked package. I am working with distance sampling and I am interested in appliying an HDS model with guanaco (Lama guanicoe) populations and I am having some trouble with the model script and with density estimation. I am working with two different sites each one has 500 kmsq. Below is my R-script. My questions are: 

 

1)     Which is the best way to choose among the key function? I looked at the histograms and ran null models for all the possibilities (hazard, halfnorm, uniform or exp); afther that I calculated the AIC foreach model and choose the model with the smallest AIC  . Is this correct? Is there any statics which help with this?

2)     I ran the models that you can see below but when I run sc5 and sc6  I have this alarm: "Hessian is singular. Try using fewer covariates or providing starting values." I tried to provide an starting value but another error appears: “Error in names(starts) <- c(lamParms, detParms) :   'names' attribute [5] must be the same length as the vector [2]. I can’t see any problem in my R-script. How can I solve this?

3)     I decided leave the two problematic models and to run all to others models just to learn when I do it and try to estimate density with the selected model which is the null one, it seems that all the transects from both sites have the same guanaco’s density. This seems wrong.

 

Perhaps my questions are too simpler to this group; in that case I would be grateful to receive  some advice of another group.  I’ve read Chandler,2015 R-script example and I am also reading the Kéry and Royle book “Hirarchical modeling in ecology”, but I am still having trouble with this,perhaps they are too advanced for me. Can you recommend something for starters?


R-script  

 

library(unmarked)

 

distancia<-transectas_grupos[,2]

transecta<-transectas_grupos[,1]

 

yDat <- formatDistData(transectas_grupos, distCol="distancia",

                       transectNameCol="transecta", dist.breaks=c(0, 230,440,700))

 

area1<-500

area2<-500

 

#transect lenght en metros

tlenght<-c(6000,6600,5900,4500,10200,6500,9900,10000)    #creo el objeto tlenght porque todas las transectas son de 

                                                         #distinta longitud

 

#juntamos las transectas con las covaribales

umf<- unmarkedFrameDS(y=as.matrix(yDat),siteCovs=data.frame(covariables, (area1+area2)),

        dist.breaks=c(0,230,440,700), unitsIn="m",survey="line",

        tlenght,(unitsIn=m))

 

summary (umf)

hist(umf)

 

#fitmodels (primero pruebo las fnciones halfnorm y hazzard con el modelo nulo para ver si puedo ajustar 

#una u otra función)

NUll1<-distsamp(~1~1, umf, keyfun="halfnorm", output="density",unitsOut="kmsq")

Null2<-distsamp(~1~1, umf, keyfun="hazard", output="density",unitsOut="kmsq")

Null3<-distsamp(~1~1, umf, keyfun="exp", output="density",unitsOut="kmsq")

Null4<-distsamp(~1~1, umf, keyfun="uniform", output="density",unitsOut="kmsq")

 

#comparo los aic de cada uno de los modelos nulos para selecciionar la keynfun que mejor funcione

scs<-fitList(Null=NUll1, a=Null2,b=Null3,c=Null4)

ms <- modSel(scs, nullmod="Null")

ms

 

hist(NUll1)

hist(Null2)

hist(Null3)

hist(Null4)

 

#elijo  Null1 que tiene un ajuste halfnorm  entonces a todos los otros modelos les hago un ajuste halfnorm

NUll1<-distsamp(~1~1, umf, keyfun="halfnorm", output="density",unitsOut="kmsq")

SC1<-distsamp(~1~sitio, umf, keyfun="halfnorm", output="density",unitsOut="kmsq")

sc2<-distsamp(~1~relieve, umf, keyfun="halfnorm", output="density",unitsOut="kmsq")

sc3<-distsamp(~relieve~1, umf, keyfun="halfnorm", output="density",unitsOut="kmsq")

sc4<-distsamp(~sitio~1, umf, keyfun="halfnorm", output="density",unitsOut="kmsq")

sc5<-distsamp(~sitio~relieve +sitio, umf,keyfun="halfnorm", output="density",unitsOut="kmsq")

sc6<-distsamp(~sitio~relieve*sitio, umf,starts = c(1), keyfun="halfnorm", output="density",unitsOut="kmsq")

sc7<-distsamp(~sitio~sitio^2, umf, keyfun="halfnorm", output="density",unitsOut="kmsq")

sc8<-distsamp(~relieve~relieve, umf, keyfun="halfnorm", output="density",unitsOut="kmsq")

sc9<-distsamp(~relieve~relieve*sitio, umf, keyfun="halfnorm", output="density",unitsOut="kmsq")

  

### model selection

> scs2<-fitList(Null=NUll1,a=SC1,b=sc2,c=sc3,d=sc4,e=sc5,f=sc8,g=sc9 )

> ms <- modSel(scs, nullmod="Null")

> ms

     nPars    AIC delta   AICwt cumltvWt      Rsq

Null     2 126.11  0.00 5.0e-01     0.50   0.0000

b        2 127.00  0.89 3.2e-01     0.82  -0.1174

a        3 128.10  1.99 1.8e-01     1.00   0.0012

c        1 156.12 30.01 1.5e-07     1.00 -41.5956

> null

Error: object 'null' not found

> NULL

NULL

> Null1

Error: object 'Null1' not found

> NUll1

 

Call:

distsamp(formula = ~1 ~ 1, data = umf, keyfun = "halfnorm", output = "density",

    unitsOut = "kmsq")

 

Density:

 Estimate    SE    z  P(>|z|)

    0.916 0.123 7.47 7.78e-14

 

Detection:

 Estimate    SE  z P(>|z|)

     5.83 0.104 56       0

 

AIC: 126.1083

> backTransform(NUll1,type=state)

Error in obj[type] : object 'state' not found

> backTransform(NUll1,type="state")

Backtransformed linear combination(s) of Density estimate(s)

 

 Estimate    SE LinComb (Intercept)

      2.5 0.307   0.916           1

 

Transformation: exp

> backTransform(NUll1,type="det")

Backtransformed linear combination(s) of Detection estimate(s)

 

 Estimate   SE LinComb sigma(Intercept)

      340 35.4    5.83                1

 

 

Transformation: exp

> backTransform(NUll1,type="det")

Backtransformed linear combination(s) of Detection estimate(s)

 

 Estimate   SE LinComb sigma(Intercept)

      340 35.4    5.83                1

 

> predict(NUll1,type="state")$Predicted

[1] 2.500199 2.500199 2.500199 2.500199 2.500199 2.500199 2.500199 2.500199

 

Jeffrey Royle

unread,
Aug 10, 2016, 10:18:14 PM8/10/16
to unma...@googlegroups.com
Dear Antonela,

 1) I think it is ok to use AIC to choose among the key functions if you think this is an important aspect of your problem. Normally I recommend not choosing among detection models because they usually do not correspond to explicit hypotheses. I think the distance sampling community disagrees with me on this point, however.

 2) I do not see the problem with the starting values. Can you produce the exact R code and result?

 3) The null model has only a constant expected density per site and thus the fitted density is indeed constant. I suggest using the ranef() and bup() functions to produce estimates of site-specific abundance. This is discussed in some detail in various parts of the AHM book.  see p 234 and 439 and elsewhere.  I'm sure you can resolve your problem with starting values and produce better site-specific estimates though....

regards,
andy


--
You received this message because you are subscribed to the Google Groups "unmarked" group.
To unsubscribe from this group and stop receiving emails from it, send an email to unmarked+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Antonela Marozzi

unread,
Aug 11, 2016, 9:15:52 AM8/11/16
to unma...@googlegroups.com
Thank you very much for your answer Andy.  Here I copy and paste the R code and result 
> library(unmarked)
> distancia<-transectas_grupos[,2]
> transecta<-transectas_grupos[,1]
> yDat <- formatDistData(transectas_grupos, distCol="distancia",
+ transectNameCol="transecta", dist.breaks=c(0, 230,440,700))
> #pongo dos áreas porque cada sitio tiene 500 kilómetros cuadrados
> area1<-500
> area2<-500
> #transect lenght en metros
> tlenght<-c(6000,6600,5900,4500,10200,6500,9900,10000)    #creo el objeto tlenght porque todas las transectas son de
> #distinta longitud
> #juntamos las transectas con las covaribales
> umf<- unmarkedFrameDS(y=as.matrix(yDat),siteCovs=data.frame(covariables, (area1+area2)),
+ dist.breaks=c(0,230,440,700), unitsIn="m",survey="line",
+ tlenght,(unitsIn=m))
> summary (umf)
unmarkedFrameDS Object

line-transect survey design
Distance class cutpoints (m):  0 230 440 700 

8 sites
Maximum number of distance classes per site: 3 
Mean number of distance classes per site: 3 
Sites with at least one detection: 8 

Tabulation of y observations:
   0    1    2    3    4    5    6    7    8   11   12   13   17 <NA> 
   2    2    4    3    4    1    1    1    2    1    1    1    1    0 

Site-level covariates:
       X          relieve  ruta        sitio   X.area1...area2.
 bo1    :1   canadones:4   no:4   bombero :4   Min.   :1000    
 bo2    :1   plano    :4   si:4   moyaique:4   1st Qu.:1000    
 bo3    :1                                     Median :1000    
 bo4    :1                                     Mean   :1000    
 mo1    :1                                     3rd Qu.:1000    
 mo2    :1                                     Max.   :1000    
 (Other):2                                                     
> hist(umf)
> #fitmodels (primero pruebo las fnciones halfnorm y hazzard con el modelo nulo para ver si puedo ajustar
> #una u otra función)
> NUll1<-distsamp(~1~1, umf, keyfun="halfnorm", output="density",unitsOut="kmsq")
> Null2<-distsamp(~1~1, umf, keyfun="hazard", output="density",unitsOut="kmsq")
> Null3<-distsamp(~1~1, umf, keyfun="exp", output="density",unitsOut="kmsq")
> Null4<-distsamp(~1~1, umf, keyfun="uniform", output="density",unitsOut="kmsq")
> #comparo los aic de cada uno de los modelos nulos para selecciionar la keynfun que mejor funcione
> scs<-fitList(Null=NUll1, a=Null2,b=Null3,c=Null4)
> ms <- modSel(scs, nullmod="Null")
> ms
     nPars    AIC delta   AICwt cumltvWt      Rsq
Null     2 126.11  0.00 5.0e-01     0.50   0.0000
b        2 127.00  0.89 3.2e-01     0.82  -0.1174
a        3 128.10  1.99 1.8e-01     1.00   0.0012
c        1 156.12 30.01 1.5e-07     1.00 -41.5956
> hist(NUll1)
> hist(Null2)
> hist(Null3)
> hist(Null4)
> #elijo  Null1 que tiene un ajuste halfnorm  entonces a todos los otros modelos les hago un ajuste halfnorm
> NUll1<-distsamp(~1~1, umf, keyfun="halfnorm", output="density",unitsOut="kmsq")
> SC1<-distsamp(~1~sitio, umf, keyfun="halfnorm", output="density",unitsOut="kmsq")
> sc2<-distsamp(~1~relieve, umf, keyfun="halfnorm", output="density",unitsOut="kmsq")
> sc3<-distsamp(~relieve~1, umf, keyfun="halfnorm", output="density",unitsOut="kmsq")
> sc4<-distsamp(~sitio~1, umf, keyfun="halfnorm", output="density",unitsOut="kmsq")
> sc5<-distsamp(~sitio~relieve +sitio, umf,keyfun="halfnorm", output="density",unitsOut="kmsq")
[1] "Hessian is singular. Try using fewer covariates or providing starting values."

> sc6<-distsamp(~sitio~relieve*sitio, umf, keyfun="halfnorm", output="density",unitsOut="kmsq")
[1] "Hessian is singular. Try using fewer covariates or providing starting values."

> sc7<-distsamp(~sitio~sitio^2, umf, keyfun="halfnorm", output="density",unitsOut="kmsq")
> sc8<-distsamp(~relieve~relieve, umf, keyfun="halfnorm", output="density",unitsOut="kmsq")

> sc9<-distsamp(~relieve~relieve*sitio, umf, keyfun="halfnorm", output="density",unitsOut="kmsq")
[1] "Hessian is singular. Try using fewer covariates or providing starting values."
> 

#hago l selección de modelos con los que pude correr, no la hago con sc6 y sc7 porque me salta un error y quiero probar
> #la selección de modelos
> scs2<-fitList(Null=NUll1,a=SC1,b=sc2,c=sc3,d=sc4,e=sc5,f=sc8,g=sc9 )
> ms <- modSel(scs, nullmod="Null")
> ms
     nPars    AIC delta   AICwt cumltvWt      Rsq
Null     2 126.11  0.00 5.0e-01     0.50   0.0000
b        2 127.00  0.89 3.2e-01     0.82  -0.1174
a        3 128.10  1.99 1.8e-01     1.00   0.0012
c        1 156.12 30.01 1.5e-07     1.00 -41.5956
> NUll1

Call:
distsamp(formula = ~1 ~ 1, data = umf, keyfun = "halfnorm", output = "density", 
    unitsOut = "kmsq")

Density:
 Estimate    SE    z  P(>|z|)
    0.916 0.123 7.47 7.78e-14

Detection:
 Estimate    SE  z P(>|z|)
     5.83 0.104 56       0

AIC: 126.1083 

Jeffrey Royle

unread,
Aug 11, 2016, 9:24:26 AM8/11/16
to unma...@googlegroups.com
I don't see where you specified the starting values.
I suggest using some of the simpler models that produced good fits to set the starting values for the more complex models.  This sometimes will help avoid the "Hessian is singular" problem.

Alternatively, one or more parameters may simply be unidentifiable (this can happen in very small data sets or when the covariates are highly correlated).

regards
andy

Antonela Marozzi

unread,
Aug 11, 2016, 9:49:41 AM8/11/16
to unma...@googlegroups.com
Excuseme , here is a model with the staring values: 
sc5<-distsamp(~sitio~relieve +sitio, umf,start(0, 1),keyfun="halfnorm", output="density",unitsOut="kmsq")
Error in names(starts) <- c(lamParms, detParms) : 
  'names' attribute [5] must be the same length as the vector [2]
Regards
Antonela

Jeffrey Royle

unread,
Aug 11, 2016, 10:07:50 AM8/11/16
to unma...@googlegroups.com
the problem here is that there has to be one starting value for EACH parameter in the model. You only have 2 starting values....  You need 5.  Moreover, it is very helpful if the starting values are close to the MLE. This is difficult to do without fitting some simpler models to see what reasonable values might be.   (so look at the output from the simpler models and use the parameter estimates as starting values).

regards
andy

Antonela Marozzi

unread,
Nov 4, 2016, 2:28:37 PM11/4/16
to unmarked
Hello dear all, some time ago I started this topic and I would like to know if there is any criterion to choose among key functions. 
Regards
Antonela
To unsubscribe from this group and stop receiving emails from it, send an email to unmarked+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages