Adding observation covariates to an unmarkedFrameOccu object

19 views
Skip to first unread message

Greg Distiller

unread,
May 20, 2026, 6:00:29 AM (6 days ago) May 20
to hmecology: Hierarchical Modeling in Ecology

I am trying to figure out how  observation covariates are formatted within an unmarkedFrameOccu object. I know that these covariates are represented as vectors rather than with a matrix like structure as done with spOcc but am unsure how these vector are constructed. I asked AI and initially AI said that all covariate vectors in unmarked are constructed from a data frame column-wise but it is apparent that this cannot be true. The first column of a detection matrix I am using has no NA values but the first set of the elements in the one observational covariate shows “3 NA NA NA NA…”. After much iterating AI said that while the covariate values are definitely correctly associated with the detection matrix, the order of the elements inside the vectors is not predictable and that if one wants to add a covariate it should be passed to the unmarkedFrameOccu() function when constructing the unmarked object. In other words it says one should never first construct the unmarked object and then add a covariate. 

I am now passing all covariates I want when I create the unmarkedFrameOccu object but I find it difficult to believe that the unmarkedFrameOccu() function would not have a systematic way of arranging the covariate vectors and to me it looks like the vector is constructed row-wise rather than column-wise. But AI is completely adamant that unmarked would not use row-wise construction so I thought worth asking here if anyone knows how these vectors are constructed?

Many thanks

Greg

Jeffrey Royle

unread,
May 20, 2026, 9:13:54 AM (6 days ago) May 20
to Greg Distiller, hmecology: Hierarchical Modeling in Ecology, unma...@googlegroups.com
hi Greg,
 This is a good question for the unmarked email list, although there is a lot of overlap in the communities I think.
  At any rate , here is an example which I modified from the help file for occu (see ?occu) which I actually don't think is that helpful (sorry about that).   
 Bottom line: your observation covariates should be matrices of dimension nsites x nobs and you can include them AS A LIST in the unmarkedFrame with the "obsCovs" argument.
 So if you follow the steps shown below for your example it should work out.  
 If you have multiple covariates then the argument would look like:  obsCovs = list(obsvar1 = matrix containing the first covariate, obsvar2 = matrix containing the 2nd, obsvar3 = and so on)

data(frogs)
plot(pferUMF, panels=4)
# add some fake covariates for illustration
sC <- data.frame(sitevar1 = rnorm(numSites(pferUMF)))
nsites<- 130
nobs<- 3
obsvar1<-  matrix(rnorm(nsites*nobs),ncol=nobs)  
str(obsvar1)
pferUMF <- unmarkedFrameOccu(pfer.bin,siteCovs = sC, obsCovs = list(obsvar1=obsvar1) )
(fm <- occu(~ obsvar1 ~ 1, pferUMF))

--
*** Three hierarchical modeling email lists ***
(1) unmarked: for questions specific to the R package unmarked
(2) SCR: for design and Bayesian or non-bayesian analysis of spatial capture-recapture
(3) HMecology (this list): for everything else, especially material covered in the books by Royle & Dorazio (2008), Kéry & Schaub (2012), Kéry & Royle (2016, 2021) and Schaub & Kéry (2022)
---
You received this message because you are subscribed to the Google Groups "hmecology: Hierarchical Modeling in Ecology" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hmecology+...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/hmecology/8b278577-9697-4159-8da4-04fb0c64682fn%40googlegroups.com.

Greg Distiller

unread,
May 20, 2026, 11:54:42 AM (6 days ago) May 20
to Jeffrey Royle, hmecology: Hierarchical Modeling in Ecology, unma...@googlegroups.com
Hi Jeffrey, and thanks for the quick response. Apologies if this question is better suited to a more targeted group, a colleague suggested I try this group.

I am creating the object with the unmarkedFrameOccu() function by passing the obsCovs as a sites * visits data.frame. The help file refers to obsCovs being passed either as a data frame or as a list of data frames, but even if I follow what you have done (by using a list of dfs) the resulting unmarkedFrameOccu object still shows the covariate as a vector i.e. not with a matrix structure:

> obsvar1<- matrix(rnorm(390),ncol=3)
> class(obsvar1)
[1] "matrix" "array” 
> pferUMF <- unmarkedFrameOccu(pfer.bin,siteCovs = sC, obsCovs = list(obsvar1=obsvar1) )
> str(pferUMF@obsCovs$obsvar1)
 num [1:390] 0.332 -0.725 1.016 -0.454 0.28 ...
> class(pferUMF@obsCovs$obsvar1)
[1] "numeric"

It does look like the vector is constructed row-wise, which is exactly what I observed with the other dataset I am working with, so I suspect that AI is simply wrong on being so adamant about the construction of the vector being column-wise.

Thanks again for the input.

Greg

From: Jeffrey Royle <jar...@gmail.com>
Date: Wednesday, 20 May 2026 at 15:14
To: Greg Distiller <greg.di...@uct.ac.za>
Cc: hmecology: Hierarchical Modeling in Ecology <hmec...@googlegroups.com>; unma...@googlegroups.com <unma...@googlegroups.com>
Subject: Re: Adding observation covariates to an unmarkedFrameOccu object

CAUTION: This email originated outside the UCT network. Do not click any links or open attachments unless you know and trust the source.
Disclaimer - University of Cape Town This email is subject to UCT policies and email disclaimer published on our website at https://www.uct.ac.za/main/email-disclaimer or obtainable from +27 21 650 9111. If this email is not related to the business of UCT, it is sent by the sender in an individual capacity. Please report security incidents or abuse via https://csirt.uct.ac.za/report-incident
Reply all
Reply to author
Forward
0 new messages