dredge function in distsamp and fix covariates

612 views
Skip to first unread message

Pablo

unread,
Oct 2, 2013, 1:13:49 PM10/2/13
to unma...@googlegroups.com
Hi all,

I am trying to use the dredge function and fix a covariate (Obs). However I get an error message. I looked for information regarding the fix command for distsamp and I could not find it. I will appreciate any help with this.


GRWEumf <- unmarkedFrameDS(y=as.matrix(GRWE_50mVegPercen[,5:9]),
                           siteCovs=data.frame(GRWE_50mVegPercen[,c("Obs","Rain","Wind","Time","Noise","Clouds","PN","LNEdge","AgroFo","SecVeg","Wetland")]),
                           dist.breaks=c(0,10,20,30,40,50), unitsIn="m", survey="point")

> GRWE_5<- distsamp(~Obs~PN+LNEdge+AgroFo+SecVeg+Wetland, GRWEumf)
> (GRWE_5<- distsamp(~Obs~PN+LNEdge+AgroFo+SecVeg+Wetland, GRWEumf))

Call:
distsamp(formula = ~Obs ~ PN + LNEdge + AgroFo + SecVeg + Wetland, 
    data = GRWEumf)

Density:
            Estimate    SE      z  P(>|z|)
(Intercept)    1.802 0.314  5.742 9.37e-09
PN            -0.204 0.297 -0.685 4.93e-01
LNEdge        -0.024 0.068 -0.353 7.24e-01
AgroFo         0.241 0.180  1.344 1.79e-01
SecVeg         0.947 0.216  4.386 1.16e-05
Wetland       -1.273 0.248 -5.126 2.97e-07

Detection:
                 Estimate     SE     z P(>|z|)
sigma(Intercept)   3.0987 0.0721 42.97  0.0000
sigmaObsE          0.1729 0.1076  1.61  0.1081
sigmaObsJ         -0.1684 0.0862 -1.95  0.0507
sigmaObsP          0.0824 0.0774  1.06  0.2870

AIC: 1662.517 
> MuMIn:::fixCoefNames(names(coef(GRWE_5)))
 [1] "lam(Int)"            "lam(PN)"             "lam(LNEdge)"         "lam(AgroFo)"        
 [5] "lam(SecVeg)"         "lam(Wetland)"        "p(sigma(Intercept))" "p(sigmaObsE)"       
 [9] "p(sigmaObsJ)"        "p(sigmaObsP)"       
attr(,"order")
 [1] 1 1 1 1 1 1 1 1 1 1
> GRWE6 <- dredge(GRWE_5,fixed=~p(Obs))
Warning message:
In dredge(GRWE_5, fixed = ~p(Obs)) :
  not all terms in 'fixed' exist in 'global.model'

Dan Linden

unread,
Oct 2, 2013, 3:20:44 PM10/2/13
to unma...@googlegroups.com
You don't have a term named "p(Obs)", hence the error message.  The fixCoefNames function has listed all the terms that you could potentially use in the dredge function.  And the fix command is specific to dredge, not distsamp.  Fixing a term in the dredge function looks like this:

dredge(global.model, fixed = ~term)

where "term" exactly matches the naming convention a term from your global model.

Pablo

unread,
Oct 2, 2013, 10:24:20 PM10/2/13
to unma...@googlegroups.com
Dear Dan,
I tried your suggestion and still does not recognize my covariate Obs. Here is my code and results. I would really appreciate if you can take a look.

GRWEumf <- unmarkedFrameDS(y=as.matrix(GRWE_50mVegPercen[,5:9]),
                           siteCovs=data.frame(GRWE_50mVegPercen[,c("Obs","Rain","Wind","Time","Noise","Clouds","PN","LNEdge","AgroFo","SecVeg","Wetland")]),
                           dist.breaks=c(0,10,20,30,40,50), unitsIn="m", survey="point")

global<- distsamp(~Obs~PN+LNEdge+AgroFo+SecVeg+Wetland, GRWEumf)
MuMIn:::fixCoefNames(names(coef(global)))

 [1] "lam(Int)"            "lam(PN)"             "lam(LNEdge)"         "lam(AgroFo)"         "lam(SecVeg)"        
 [6] "lam(Wetland)"        "p(sigma(Intercept))" "p(sigmaObsE)"        "p(sigmaObsJ)"        "p(sigmaObsP)"       
attr(,"order")
 [1] 1 1 1 1 1 1 1 1 1 1
> GRWE8 <- dredge(global,fixed= ~Obs)
Warning message:
In dredge(global, fixed = ~Obs) :
  not all terms in 'fixed' exist in 'global.model'

Any help or suggestions will be greatly received.

Thanks

Pablo

Dan Linden

unread,
Oct 3, 2013, 10:52:23 AM10/3/13
to unma...@googlegroups.com
Pablo, the term "Obs" does not appear in your list of coefficient names.  As I said previously, the fixCoefNames function returns the exact names of model coefficients.  You can only choose terms in the dredge function that exactly match those coefficient names (NOT the terms in your original model formula).  It appears that "Obs" is a categorical covariate for observer name and you had 4 different observers.  Which observer are you trying to fix?  If you use:

dredge(global,fixed= ~p(sigma(Intercept)))

The default observer (which is the intercept) will be fixed for p.

Pablo

unread,
Oct 3, 2013, 1:04:47 PM10/3/13
to unma...@googlegroups.com
Dear Dan,

I tried and worked fine, thanks. I fixed p(sigma(Intercept)) and work great , however when I tried to fix the others observers I got the same error message. I check and the estimates that I got when I fixed p(sigma(Intercept)) were the same when I run the top model by it self. So my questions is when I fix p(sigma(Intercept)) is including the others observers as well? In the case that this is not correct, do you have a suggestion about fixing more than one covariate?

MuMIn:::fixCoefNames(names(coef(global)))
 [1] "lam(Int)"            "lam(PN)"             "lam(LNEdge)"         "lam(AgroFo)"         "lam(SecVeg)"        
 [6] "lam(Wetland)"        "p(sigma(Intercept))" "p(sigmaObsE)"        "p(sigmaObsJ)"        "p(sigmaObsP)"       
attr(,"order")
 [1] 1 1 1 1 1 1 1 1 1 1
> GRWE9 <- dredge(global,fixed= ~p(sigma(Intercept))+p(sigmaObsE)+p(sigmaObsJ)+p(sigmaObsP))
Warning message:
In dredge(global, fixed = ~p(sigma(Intercept)) + p(sigmaObsE) +  :
  not all terms in 'fixed' exist in 'global.model'

Dan

unread,
Oct 29, 2013, 12:32:31 PM10/29/13
to unma...@googlegroups.com
Hi Folks,

I don't mean to hijack this thread, but this question relates to using dredge and unmarked. I have supplied a basic example below where I would like to run a global model but constrain the model results where I have a quadratic term (i.e., include only 'I(sitevar1^2)' when 'sitevar1' is in the same model). If anyone has an idea of how to do this that would be awesome. Thanks!

Cheers,
Dan

# Bring in Data
library(unmarked)
data(frogs)
pferUMF <- unmarkedFrameOccu(pfer.bin)
siteCovs(pferUMF) <- data.frame(sitevar1 = rnorm(numSites(pferUMF)),sitevar2 = rnorm(numSites(pferUMF)))

# Run Global Model & Dredge
library(MuMIn)
global <- occu(~ sitevar1 + I(sitevar1^2) + sitevar2 ~ 1, pferUMF)
dd1<-dredge(global) # <- has models containing quadratic 'I(sitecar1^2)' without corresponding 'sitevar1' (not what I want)

# Trying to use subset to constrain model set
msubset <- expression(sitevar1|!`I(sitevar1^2)`)
dd2<-dredge(global, subset=msubset)


Srinivas Vaidyanathan

unread,
Jul 28, 2014, 2:30:16 AM7/28/14
to unma...@googlegroups.com
Try I(sitevar1^2) -sitevar1 while constructing the global model.

Srinivas Vaidyanathan

unread,
Jul 29, 2014, 11:46:29 PM7/29/14
to unma...@googlegroups.com
You can use subset in dredge, the format for the same is

subset=!(`psi(sitevar1)` && `psi(sitevar1^2)`)

or you can use the above to update msubset
Reply all
Reply to author
Forward
0 new messages