Modelling detection probability in OccuMulti

415 views
Skip to first unread message

Shreya Ray

unread,
May 6, 2022, 8:30:52 AM5/6/22
to unmarked
Hello Everyone, I am trying to model marginal and conditional occupancy of two species using the occuMulti function which runs the model defined by Rota et al 2016. Since the detection covariates that I am trying to include are not in obsCovs format(RxJ rows in site-major order), I am running across error, "Error in unmarkedFrameOccuMulti(y = multi_sm_list, obsCovs = det_list,  : At least one matrix in obsCovs has incorrect number of dimensions.." my detection covariates look like this:
      station       NDVI          Effort 
1    B1-103  0.67793775      47
 2    B1-104  0.62666667     48
 3    B1-110  0.62845850     47

Hence, I am trying to include them in unmarked framework by siteCovs (I have done this for single season occupancy models before) but here when I am trying to run this in occuMulti I am getting error, "Error in model.frame.default(object, data, xlev = xlev) : invalid type (list) for variable 'NDVI'"
Here is my code for your reference:

multi_sm_lis_umf <- unmarkedFrameOccuMulti(y=multi_sm_list , obsCovs=NULL, siteCovs=occ_cov)
plot(multi_sm_lis_umf)
multi_sm_lis_umf@fDesign
##############################occuMUlti##########################

detFormula <- c('~NDVI','~NDVI')

##disturbance parameter
stateformula <- c('~Human_RAI', '~Human_RAI', '~Human_RAI')

occu_multi <- occuMulti(detFormula, stateformula, multi_sm_lis_umf)
occu_multi
 plot(occu_multi)

Is there any other way that I can model the detection probability?

Attaching image of my site covariatessitecovs.png

Ken Kellner

unread,
May 6, 2022, 8:41:28 AM5/6/22
to unmarked
You should be able to use site covariates in your detection formulas, if you are using the latest version of unmarked. The error you are getting suggests something might be wrong with the way the site covariates were read into R - do you get any errors if you make the detection formulas intercept-only and run the model?

If that isn't working you can also manually turn NDVI into a site covariate by replicating your R NDVI values J times each - i.e., take the NDVI column, copy it J times, and bind the J columns into a new RxJ matrix and supply that as an observation covariate.

Ken

Shreya Ray

unread,
May 6, 2022, 9:25:32 AM5/6/22
to unmarked
Thanks Ken, I tried updating unmark and running the occuMulti function again to use NDVI from the siteCovs data frame, but I am again getting this error, "Error in eval(predvars, data, env) : object 'NDVI' not found". I am not getting any error for intercept only formula(detFormula1 <- c('~1', '~1')).  
I had tried converting my NDVI values to a JxR matrix(205 rows and 52 columns) by copying the values 52 times but when I am trying to insert it through the obsCovs, I am getting error;"Error in unmarkedFrameOccuMulti(y = multi_sm_list, obsCovs = dete_list,  : At least one matrix in obsCovs has incorrect number of dimensions."
Here is a snap of this TableRxJ_NDVI.png

Also sharing the code:
dete_cov <- read.csv("F:/BUXA/paper/multi_spanalysis/NDVI_try.csv")
dete_list <-list(NDVI=dete_cov)##detection covariates list

##unmarked frame#############
multi_sm_lis_umf <- unmarkedFrameOccuMulti(y=multi_sm_list , obsCovs=dete_list, siteCovs=occ_cov)

Ken Kellner

unread,
May 6, 2022, 9:32:36 AM5/6/22
to unmarked
You need to remove the 'station' column from dete_cov, it should only have NDVI values in it.

Shreya Ray

unread,
May 7, 2022, 2:39:02 PM5/7/22
to unmarked
Hi Ken, I removed the station column and managed to run function unmarkedFrameOccuMulti( y=y_list1, siteCovs = occ_cov, obsCovs = det_list ) and included NDVI values in JXR form. However, when I tried to include NDVI to model detection using code " occu_multi <- occuMulti(detformulas= c('~NDVI','~NDVI'), stateformulas = c('~Human_RAI', '~Human_RAI', '~Human_RAI'), data=msom)" , I am getting an error; "Error in x[!navec, , drop = FALSE] : (subscript) logical subscript too long". The function is running though when I use intercept only formula "occu_multi <- occuMulti(detformulas= c('~1','~1'), stateformulas = c('~Human_RAI', '~Human_RAI', '~Human_RAI'), data=msom)". Could it be because of repeated values J times?

Ken Kellner

unread,
May 7, 2022, 6:27:41 PM5/7/22
to unmarked
I think I will need to be able to look at this more closely in order to help. Can you email me your dataset and current code off-list so I can run it myself?

Ken

Shreya Ray

unread,
May 8, 2022, 1:00:15 AM5/8/22
to unmarked
Many thanks Ken, I sent you the trial dataset and codes. Hopefully this issue can be resolved.

Tanvi Gurjar

unread,
Feb 26, 2024, 6:07:22 PM2/26/24
to unmarked
Hello everyone, 

I am posting my query in this thread since I have been getting the same error for my 'obsCovs' in 'occuMulti'. I hope that is alright. 

My dataset consists of 33 sites sampled 5 times. I have 6 reptiles in my dataset and subsequently have species-specific 'obsCovs' for them. I tried to put these into a list. However, following are the errors I have been getting:

1. 
det_covs_list = list(AFR_OBS = (obsCovs_AFR),LAGL_OBS=(obsCovs_LAGL),PMU_OBS=(obsCovs_PMU),ZVIV_OBS=(obsCovs_ZVIV),GSN_OBS=(obsCovs_GSN),SSN_OBS=(obsCovs_SSN)) > REPTILES3 <- unmarkedFrameOccuMulti(y = y_list, siteCovs = site_list, obsCovs = det_covs_list) Error in FUN(X[[i]], ...) : At least one element of obsCovs is not a matrix or data frame.
2. I tried to explicitly specify my species-specific obsCovs as matrices:

obsCovs = list(AFR_OBS = as.matrix(obsCovs_AFR),LAGL_OBS=as.matrix(obsCovs_LAGL),PMU_OBS=as.matrix(obsCovs_PMU),ZVIV_OBS=as.matrix(obsCovs_ZVIV),GSN_OBS=as.matrix(obsCovs_GSN),SSN_OBS=as.matrix(obsCovs_SSN))
> REPTILES3 <- unmarkedFrameOccuMulti(y = y_list, siteCovs = siteCovs, obsCovs = obsCovs) Error: All elements of list provided to obsCovs argument must be named
3. I then tried to explicitly name all my species-specific obsCovs in a separate list:

det_covs_list = list(AFR_OBS = (obsCovs_AFR),LAGL_OBS=(obsCovs_LAGL),PMU_OBS=(obsCovs_PMU),ZVIV_OBS=(obsCovs_ZVIV),GSN_OBS=(obsCovs_GSN),SSN_OBS=(obsCovs_SSN)) > REPTILES3 <- unmarkedFrameOccuMulti(y = y_list, siteCovs = siteCovs, obsCovs = det_cov_list)
Error in FUN(X[[i]], ...) :
At least one element of obsCovs has incorrect number of dimensions.

However, the initial error returns. I am unable to locate the problem and would be delighted to receive your input.
I would be grateful for any help!

Thank you so much!
-Tanvi

Ken Kellner

unread,
Feb 27, 2024, 9:03:19 AM2/27/24
to unma...@googlegroups.com
Can you share the output of str(y_list) and str(det_cov_list) ?

Ken
> >>>>> Thanks Ken, I tried updating *unmark* and running the occuMulti
> --
> *** Three hierarchical modeling email lists ***
> (1) unmarked (this list): for questions specific to the R package unmarked
> (2) SCR: for design and Bayesian or non-bayesian analysis of spatial capture-recapture
> (3) HMecology: 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 "unmarked" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to unmarked+u...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/unmarked/4856f102-a2a9-4048-9564-c7bea21d62a2n%40googlegroups.com.

Message has been deleted

Tanvi Gurjar

unread,
Feb 27, 2024, 9:59:55 AM2/27/24
to unmarked
Dear Ken, 

Thank you for your response! Here is the output:

> str(det_cov_list)
List of 6
 $ :List of 6
  ..$ TRANSECT: tibble [94 × 5] (S3: tbl_df/tbl/data.frame)
  .. ..$ TRANSECT...25: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ TRANSECT...26: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ TRANSECT...27: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ TRANSECT...28: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ TRANSECT...29: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  ..$ ACO     : tibble [94 × 5] (S3: tbl_df/tbl/data.frame)
  .. ..$ ACO...30: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ ACO...31: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ ACO...32: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ ACO...33: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ ACO...34: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  ..$ PREVDET : tibble [94 × 5] (S3: tbl_df/tbl/data.frame)
  .. ..$ PrevDet...35: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ PrevDet...36: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ PrevDet...37: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ PrevDet...38: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ PrevDet...39: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  ..$ MONTH   : tibble [94 × 5] (S3: tbl_df/tbl/data.frame)
  .. ..$ MONTH...40: chr [1:94] "EAp" "EAp" "EAp" "EAp" ...
  .. ..$ MONTH...41: chr [1:94] "EM" "EM" "EM" "EM" ...
  .. ..$ MONTH...42: chr [1:94] "EJ" "EJ" "EJ" "EJ" ...
  .. ..$ MONTH...43: chr [1:94] "MJu" "MJu" "MJu" "MJu" ...
  .. ..$ MONTH...44: chr [1:94] "EaAu" "EaAu" "EaAu" "EaAu" ...
  ..$ TOD     : tibble [94 × 5] (S3: tbl_df/tbl/data.frame)
  .. ..$ TOD...45: chr [1:94] "A" "A" "A" "A" ...
  .. ..$ TOD...46: chr [1:94] "M" "M" "A" "A" ...
  .. ..$ TOD...47: chr [1:94] "E" "A" "A" "A" ...
  .. ..$ TOD...48: chr [1:94] "M" "M" "A" "A" ...
  .. ..$ TOD...49: chr [1:94] "M" "M" "A" "A" ...
  ..$ CC      : tibble [94 × 5] (S3: tbl_df/tbl/data.frame)
  .. ..$ CC...50: num [1:94] 2 2 3 3 3 3 3 1 3 1 ...
  .. ..$ CC...51: num [1:94] 3 2 3 3 3 3 3 1 2 2 ...
  .. ..$ CC...52: num [1:94] 3 1 3 3 3 3 3 1 1 3 ...
  .. ..$ CC...53: num [1:94] 3 2 3 3 3 3 2 2 2 2 ...
  .. ..$ CC...54: num [1:94] 3 2 2 2 2 3 2 1 3 3 ...
 $ :List of 6
  ..$ TRANSECT: tibble [94 × 5] (S3: tbl_df/tbl/data.frame)
  .. ..$ TRANSECT...25: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ TRANSECT...26: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ TRANSECT...27: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ TRANSECT...28: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ TRANSECT...29: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  ..$ ACO     : tibble [94 × 5] (S3: tbl_df/tbl/data.frame)
  .. ..$ ACO...30: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ ACO...31: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ ACO...32: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ ACO...33: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ ACO...34: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  ..$ PREVDET : tibble [94 × 5] (S3: tbl_df/tbl/data.frame)
  .. ..$ PrevDet...35: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ PrevDet...36: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ PrevDet...37: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ PrevDet...38: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ PrevDet...39: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  ..$ MONTH   : tibble [94 × 5] (S3: tbl_df/tbl/data.frame)
  .. ..$ MONTH...40: chr [1:94] "EAp" "EAp" "EAp" "EAp" ...
  .. ..$ MONTH...41: chr [1:94] "EM" "EM" "EM" "EM" ...
  .. ..$ MONTH...42: chr [1:94] "EJ" "EJ" "EJ" "EJ" ...
  .. ..$ MONTH...43: chr [1:94] "MJu" "MJu" "MJu" "MJu" ...
  .. ..$ MONTH...44: chr [1:94] "EaAu" "EaAu" "EaAu" "EaAu" ...
  ..$ TOD     : tibble [94 × 5] (S3: tbl_df/tbl/data.frame)
  .. ..$ TOD...45: chr [1:94] "A" "A" "A" "A" ...
  .. ..$ TOD...46: chr [1:94] "M" "M" "A" "A" ...
  .. ..$ TOD...47: chr [1:94] "E" "A" "A" "A" ...
  .. ..$ TOD...48: chr [1:94] "M" "M" "A" "A" ...
  .. ..$ TOD...49: chr [1:94] "M" "M" "A" "A" ...
  ..$ CC      : tibble [94 × 5] (S3: tbl_df/tbl/data.frame)
  .. ..$ CC...50: num [1:94] 2 2 3 3 3 3 3 1 3 1 ...
  .. ..$ CC...51: num [1:94] 3 2 3 3 3 3 3 1 2 2 ...
  .. ..$ CC...52: num [1:94] 3 1 3 3 3 3 3 1 1 3 ...
  .. ..$ CC...53: num [1:94] 3 2 3 3 3 3 2 2 2 2 ...
  .. ..$ CC...54: num [1:94] 3 2 2 2 2 3 2 1 3 3 ...
 $ :List of 6
  ..$ TRANSECT: tibble [94 × 5] (S3: tbl_df/tbl/data.frame)
  .. ..$ TRANSECT...25: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ TRANSECT...26: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ TRANSECT...27: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ TRANSECT...28: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ TRANSECT...29: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  ..$ ACO     : tibble [94 × 5] (S3: tbl_df/tbl/data.frame)
  .. ..$ ACO...30: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ ACO...31: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ ACO...32: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ ACO...33: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ ACO...34: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  ..$ PREVDET : tibble [94 × 5] (S3: tbl_df/tbl/data.frame)
  .. ..$ PrevDet...35: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ PrevDet...36: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ PrevDet...37: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ PrevDet...38: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ PrevDet...39: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  ..$ MONTH   : tibble [94 × 5] (S3: tbl_df/tbl/data.frame)
  .. ..$ MONTH...40: chr [1:94] "EAp" "EAp" "EAp" "EAp" ...
  .. ..$ MONTH...41: chr [1:94] "EM" "EM" "EM" "EM" ...
  .. ..$ MONTH...42: chr [1:94] "EJ" "EJ" "EJ" "EJ" ...
  .. ..$ MONTH...43: chr [1:94] "MJu" "MJu" "MJu" "MJu" ...
  .. ..$ MONTH...44: chr [1:94] "EaAu" "EaAu" "EaAu" "EaAu" ...
  ..$ TOD     : tibble [94 × 5] (S3: tbl_df/tbl/data.frame)
  .. ..$ TOD...45: chr [1:94] "A" "A" "A" "A" ...
  .. ..$ TOD...46: chr [1:94] "M" "M" "A" "A" ...
  .. ..$ TOD...47: chr [1:94] "E" "A" "A" "A" ...
  .. ..$ TOD...48: chr [1:94] "M" "M" "A" "A" ...
  .. ..$ TOD...49: chr [1:94] "M" "M" "A" "A" ...
  ..$ CC      : tibble [94 × 5] (S3: tbl_df/tbl/data.frame)
  .. ..$ CC...50: num [1:94] 2 2 3 3 3 3 3 1 3 1 ...
  .. ..$ CC...51: num [1:94] 3 2 3 3 3 3 3 1 2 2 ...
  .. ..$ CC...52: num [1:94] 3 1 3 3 3 3 3 1 1 3 ...
  .. ..$ CC...53: num [1:94] 3 2 3 3 3 3 2 2 2 2 ...
  .. ..$ CC...54: num [1:94] 3 2 2 2 2 3 2 1 3 3 ...
 $ :List of 6
  ..$ TRANSECT: tibble [94 × 5] (S3: tbl_df/tbl/data.frame)
  .. ..$ TRANSECT...25: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ TRANSECT...26: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ TRANSECT...27: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ TRANSECT...28: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ TRANSECT...29: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  ..$ ACO     : tibble [94 × 5] (S3: tbl_df/tbl/data.frame)
  .. ..$ ACO...30: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ ACO...31: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ ACO...32: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ ACO...33: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ ACO...34: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  ..$ PREVDET : tibble [94 × 5] (S3: tbl_df/tbl/data.frame)
  .. ..$ PrevDet...35: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ PrevDet...36: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ PrevDet...37: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ PrevDet...38: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ PrevDet...39: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  ..$ MONTH   : tibble [94 × 5] (S3: tbl_df/tbl/data.frame)
  .. ..$ MONTH...40: chr [1:94] "EAp" "EAp" "EAp" "EAp" ...
  .. ..$ MONTH...41: chr [1:94] "EM" "EM" "EM" "EM" ...
  .. ..$ MONTH...42: chr [1:94] "EJ" "EJ" "EJ" "EJ" ...
  .. ..$ MONTH...43: chr [1:94] "MJu" "MJu" "MJu" "MJu" ...
  .. ..$ MONTH...44: chr [1:94] "EaAu" "EaAu" "EaAu" "EaAu" ...
  ..$ TOD     : tibble [94 × 5] (S3: tbl_df/tbl/data.frame)
  .. ..$ TOD...45: chr [1:94] "A" "A" "A" "A" ...
  .. ..$ TOD...46: chr [1:94] "M" "M" "A" "A" ...
  .. ..$ TOD...47: chr [1:94] "E" "A" "A" "A" ...
  .. ..$ TOD...48: chr [1:94] "M" "M" "A" "A" ...
  .. ..$ TOD...49: chr [1:94] "M" "M" "A" "A" ...
  ..$ CC      : tibble [94 × 5] (S3: tbl_df/tbl/data.frame)
  .. ..$ CC...50: num [1:94] 2 2 3 3 3 3 3 1 3 1 ...
  .. ..$ CC...51: num [1:94] 3 2 3 3 3 3 3 1 2 2 ...
  .. ..$ CC...52: num [1:94] 3 1 3 3 3 3 3 1 1 3 ...
  .. ..$ CC...53: num [1:94] 3 2 3 3 3 3 2 2 2 2 ...
  .. ..$ CC...54: num [1:94] 3 2 2 2 2 3 2 1 3 3 ...
 $ :List of 6
  ..$ TRANSECT: tibble [94 × 5] (S3: tbl_df/tbl/data.frame)
  .. ..$ TRANSECT...25: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ TRANSECT...26: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ TRANSECT...27: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ TRANSECT...28: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ TRANSECT...29: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  ..$ ACO     : tibble [94 × 5] (S3: tbl_df/tbl/data.frame)
  .. ..$ ACO...30: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ ACO...31: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ ACO...32: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ ACO...33: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ ACO...34: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  ..$ PREVDET : tibble [94 × 5] (S3: tbl_df/tbl/data.frame)
  .. ..$ PrevDet...35: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ PrevDet...36: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ PrevDet...37: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ PrevDet...38: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ PrevDet...39: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  ..$ MONTH   : tibble [94 × 5] (S3: tbl_df/tbl/data.frame)
  .. ..$ MONTH...40: chr [1:94] "EAp" "EAp" "EAp" "EAp" ...
  .. ..$ MONTH...41: chr [1:94] "EM" "EM" "EM" "EM" ...
  .. ..$ MONTH...42: chr [1:94] "EJ" "EJ" "EJ" "EJ" ...
  .. ..$ MONTH...43: chr [1:94] "MJu" "MJu" "MJu" "MJu" ...
  .. ..$ MONTH...44: chr [1:94] "EaAu" "EaAu" "EaAu" "EaAu" ...
  ..$ TOD     : tibble [94 × 5] (S3: tbl_df/tbl/data.frame)
  .. ..$ TOD...45: chr [1:94] "A" "A" "A" "A" ...
  .. ..$ TOD...46: chr [1:94] "M" "M" "A" "A" ...
  .. ..$ TOD...47: chr [1:94] "E" "A" "A" "A" ...
  .. ..$ TOD...48: chr [1:94] "M" "M" "A" "A" ...
  .. ..$ TOD...49: chr [1:94] "M" "M" "A" "A" ...
  ..$ CC      : tibble [94 × 5] (S3: tbl_df/tbl/data.frame)
  .. ..$ CC...50: num [1:94] 2 2 3 3 3 3 3 1 3 1 ...
  .. ..$ CC...51: num [1:94] 3 2 3 3 3 3 3 1 2 2 ...
  .. ..$ CC...52: num [1:94] 3 1 3 3 3 3 3 1 1 3 ...
  .. ..$ CC...53: num [1:94] 3 2 3 3 3 3 2 2 2 2 ...
  .. ..$ CC...54: num [1:94] 3 2 2 2 2 3 2 1 3 3 ...
 $ :List of 6
  ..$ TRANSECT: tibble [94 × 5] (S3: tbl_df/tbl/data.frame)
  .. ..$ TRANSECT...25: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ TRANSECT...26: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ TRANSECT...27: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ TRANSECT...28: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ TRANSECT...29: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  ..$ ACO     : tibble [94 × 5] (S3: tbl_df/tbl/data.frame)
  .. ..$ ACO...30: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ ACO...31: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ ACO...32: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ ACO...33: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ ACO...34: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  ..$ PREVDET : tibble [94 × 5] (S3: tbl_df/tbl/data.frame)
  .. ..$ PrevDet...35: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ PrevDet...36: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ PrevDet...37: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ PrevDet...38: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ PrevDet...39: num [1:94] 0 0 0 0 0 0 0 0 0 0 ...
  ..$ MONTH   : tibble [94 × 5] (S3: tbl_df/tbl/data.frame)
  .. ..$ MONTH...40: chr [1:94] "EAp" "EAp" "EAp" "EAp" ...
  .. ..$ MONTH...41: chr [1:94] "EM" "EM" "EM" "EM" ...
  .. ..$ MONTH...42: chr [1:94] "EJ" "EJ" "EJ" "EJ" ...
  .. ..$ MONTH...43: chr [1:94] "MJu" "MJu" "MJu" "MJu" ...
  .. ..$ MONTH...44: chr [1:94] "EaAu" "EaAu" "EaAu" "EaAu" ...
  ..$ TOD     : tibble [94 × 5] (S3: tbl_df/tbl/data.frame)
  .. ..$ TOD...45: chr [1:94] "A" "A" "A" "A" ...
  .. ..$ TOD...46: chr [1:94] "M" "M" "A" "A" ...
  .. ..$ TOD...47: chr [1:94] "E" "A" "A" "A" ...
  .. ..$ TOD...48: chr [1:94] "M" "M" "A" "A" ...
  .. ..$ TOD...49: chr [1:94] "M" "M" "A" "A" ...
  ..$ CC      : tibble [94 × 5] (S3: tbl_df/tbl/data.frame)
  .. ..$ CC...50: num [1:94] 2 2 3 3 3 3 3 1 3 1 ...
  .. ..$ CC...51: num [1:94] 3 2 3 3 3 3 3 1 2 2 ...
  .. ..$ CC...52: num [1:94] 3 1 3 3 3 3 3 1 1 3 ...
  .. ..$ CC...53: num [1:94] 3 2 3 3 3 3 2 2 2 2 ...
  .. ..$ CC...54: num [1:94] 3 2 2 2 2 3 2 1 3 3 ...
> str(y_list)
List of 6
 $ AFR : num [1:94, 1:5] 0 0 0 0 0 0 0 0 0 0 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : NULL
  .. ..$ : chr [1:5] "o1" "o2" "o3" "o4" ...
 $ LAGL: num [1:94, 1:5] 0 0 0 0 0 0 0 0 0 0 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : NULL
  .. ..$ : chr [1:5] "o1" "o2" "o3" "o4" ...
 $ PMU : num [1:94, 1:5] 0 0 0 0 0 0 0 0 0 0 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : NULL
  .. ..$ : chr [1:5] "o1" "o2" "o3" "o4" ...
 $ ZVIV: num [1:94, 1:5] 0 0 0 0 0 0 0 0 0 0 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : NULL
  .. ..$ : chr [1:5] "o1" "o2" "o3" "o4" ...
 $ GSN : num [1:94, 1:5] 0 0 0 0 0 0 0 0 0 0 ...
  ..- attr(*, "dimnames")=List of 2
.. ..$ : NULL
.. ..$ : chr [1:5] "o1" "o2" "o3" "o4" ...
$ SSN : num [1:94, 1:5] 0 0 0 0 0 0 0 0 0 0 ...
..- attr(*, "dimnames")=List of 2
.. ..$ : NULL
.. ..$ : chr [1:5] "o1" "o2" "o3" "o4" ...

Ken Kellner

unread,
Feb 27, 2024, 10:48:50 AM2/27/24
to unmarked
The obsCovs must be a list of matrices. You have a list of lists of data frames. If you want to use unique obs covariates for each species, you'll have to make a single list containing only matrices that includes covariates for all species. You should be able to name the list with species-specific names so that you can still have species-level covariates. For example:

list(TRANSECT_AFR = matrix(), TRANSECT_LAGL = matrix(), ... , ACO_AFR = matrix(), ACO_LAGL = matrix(), ...)

Does that help?

Tanvi Gurjar

unread,
Feb 27, 2024, 12:12:13 PM2/27/24
to unmarked
Dear Ken, 

It works now, with 'as.matrix' instead of 'matrix', for some reason. Thank you so much!!

Best wishes, 
tanvi
Message has been deleted
Message has been deleted

Kristin Brandon

unread,
Nov 8, 2024, 2:06:19 PM11/8/24
to unmarked
Hi all,

I am running into the same issues as tannu4 but am having difficulty following along with the example above. I have 76 sites that were surveyed between 5 and 20 times. I have 2 site-level observation variables, Effort and Year, that I would like to use to assess detection probability for each of 4 rodent species. I have tried assigning these to obsCovs as a list of lists of matrices (because I am applying occuMulti across a list of 10 imputed datasets) but it is not working. Here is what I currently have, as well as the structure for each object. Any input would be much appreciated!

#1. Create presence/absence matrices #a. Extract detection data for each species Rrav <- rodent %>% select(matches("^Rrav_[1-9]$|^Rrav_1[0-9]$|^Rrav_20$")) Rrav <- as.matrix(Rrav) Rmeg <- rodent %>% select(matches("^Rmeg_[1-9]$|^Rmeg_1[0-9]$|^Rmeg_20$")) Rmeg <- as.matrix(Rmeg) Mmus <- rodent %>% select(matches("^Mmus_[1-9]$|^Mmus_1[0-9]$|^Mmus_20$")) Mmus <- as.matrix(Mmus) Mcal <- rodent %>% select(matches("^Mcal_[1-9]$|^Mcal_1[0-9]$|^Mcal_20$")) Mcal <- as.matrix(Mcal) #b. Combine into one named list ylist <- list(Rrav=Rrav, Rmeg=Rmeg, Mmus=Mmus, Mcal=Mcal) str(ylist) > str(ylist)
List of 4
 $ Rrav: int [1:76, 1:20] 0 0 0 1 0 0 0 0 0 0 ...

  ..- attr(*, "dimnames")=List of 2
  .. ..$ : NULL
  .. ..$ : chr [1:20] "Rrav_1" "Rrav_2" "Rrav_3" "Rrav_4" ...
 $ Rmeg: int [1:76, 1:20] 1 1 1 0 0 0 0 0 0 0 ...

  ..- attr(*, "dimnames")=List of 2
  .. ..$ : NULL
  .. ..$ : chr [1:20] "Rmeg_1" "Rmeg_2" "Rmeg_3" "Rmeg_4" ...
 $ Mmus: int [1:76, 1:20] 0 0 0 0 1 0 0 0 1 0 ...

  ..- attr(*, "dimnames")=List of 2
  .. ..$ : NULL
  .. ..$ : chr [1:20] "Mmus_1" "Mmus_2" "Mmus_3" "Mmus_4" ...
 $ Mcal: int [1:76, 1:20] 0 0 1 0 0 0 0 0 0 0 ...

  ..- attr(*, "dimnames")=List of 2
  .. ..$ : NULL
  .. ..$ : chr [1:20] "Mcal_1" "Mcal_2" "Mcal_3" "Mcal_4" ... #---------- #2. Create data frame of standardized site covariates #a. Extract covariate names covs <- colnames(rodent_imp[[1]]) covs <- covs[c(3:9)] #b. Define a function to extract covariates and convert characters to factor extract_covs <- function(data){ covariate_df <- data[, covs, drop=FALSE] covariate_df[] <- lapply(covariate_df, function(col) { if (is.character(col)) { as.factor(col) } else { col } }) return(covariate_df) } #c. Apply the function to each imputed data set sitecovs <- lapply(rodent_imp, extract_covs) str(sitecovs) > str(sitecovs)
List of 10
 $ :'data.frame': 76 obs. of  7 variables:
  ..$ Type      : Factor w/ 4 levels "Both","Muted",..: 4 4 4 4 4 4 4 4 4 3 ...
  ..$ Area      : num [1:76] -0.393 -0.5011 -0.0197 0.3686 -0.3821 ...
  ..$ Dist_urban: num [1:76] -0.237 -0.043 2.206 0.481 -0.995 ...
  ..$ Above_MHW : num [1:76] 0.156 0.614 1.209 -0.314 -1.426 ...
  ..$ Mcal_conn : num [1:76] -0.125 -0.8 0.386 1.051 -0.443 ...
  ..$ Mmus_conn : num [1:76] -0.528 -0.934 0.611 1.04 -0.609 ...
  ..$ Rrav_conn : num [1:76] -0.9293 -0.9675 0.0539 0.8905 -0.9627 ...
 $ :'data.frame': 76 obs. of  7 variables:
  ..$ Type      : Factor w/ 4 levels "Both","Muted",..: 4 4 4 4 4 4 4 4 4 3 ...
  ..$ Area      : num [1:76] -0.393 -0.5011 -0.0197 0.3686 -0.3821 ...
  ..$ Dist_urban: num [1:76] -0.237 -0.043 2.206 0.481 -0.995 ...
  ..$ Above_MHW : num [1:76] 0.156 0.614 1.209 -0.314 -1.426 ...
  ..$ Mcal_conn : num [1:76] -0.125 -0.8 0.386 1.051 -0.443 ...
  ..$ Mmus_conn : num [1:76] -0.528 -0.934 0.611 1.04 -0.609 ...
  ..$ Rrav_conn : num [1:76] -0.9293 -0.9675 0.0539 0.8905 -0.9627 ...
 $ :'data.frame': 76 obs. of  7 variables:
  ..$ Type      : Factor w/ 4 levels "Both","Muted",..: 4 4 4 4 4 4 4 4 4 3 ...
  ..$ Area      : num [1:76] -0.393 -0.5011 -0.0197 0.3686 -0.3821 ...
  ..$ Dist_urban: num [1:76] -0.237 -0.043 2.206 0.481 -0.995 ...
  ..$ Above_MHW : num [1:76] 0.156 0.614 1.209 -0.314 -1.426 ...
  ..$ Mcal_conn : num [1:76] -0.125 -0.8 0.386 1.051 -0.443 ...
  ..$ Mmus_conn : num [1:76] -0.528 -0.934 0.611 1.04 -0.609 ...
  ..$ Rrav_conn : num [1:76] -0.9293 -0.9675 0.0539 0.8905 -0.9627 ...
 $ :'data.frame': 76 obs. of  7 variables:
  ..$ Type      : Factor w/ 4 levels "Both","Muted",..: 4 4 4 4 4 4 4 4 4 3 ...
  ..$ Area      : num [1:76] -0.393 -0.5011 -0.0197 0.3686 -0.3821 ...
  ..$ Dist_urban: num [1:76] -0.237 -0.043 2.206 0.481 -0.995 ...
  ..$ Above_MHW : num [1:76] 0.156 0.614 1.209 -0.314 -1.426 ...
  ..$ Mcal_conn : num [1:76] -0.125 -0.8 0.386 1.051 -0.443 ...
  ..$ Mmus_conn : num [1:76] -0.528 -0.934 0.611 1.04 -0.609 ...
  ..$ Rrav_conn : num [1:76] -0.9293 -0.9675 0.0539 0.8905 -0.9627 ...
 $ :'data.frame': 76 obs. of  7 variables:
  ..$ Type      : Factor w/ 4 levels "Both","Muted",..: 4 4 4 4 4 4 4 4 4 3 ...
  ..$ Area      : num [1:76] -0.393 -0.5011 -0.0197 0.3686 -0.3821 ...
  ..$ Dist_urban: num [1:76] -0.237 -0.043 2.206 0.481 -0.995 ...
  ..$ Above_MHW : num [1:76] 0.156 0.614 1.209 -0.314 -1.426 ...
  ..$ Mcal_conn : num [1:76] -0.125 -0.8 0.386 1.051 -0.443 ...
  ..$ Mmus_conn : num [1:76] -0.528 -0.934 0.611 1.04 -0.609 ...
  ..$ Rrav_conn : num [1:76] -0.9293 -0.9675 0.0539 0.8905 -0.9627 ...
 $ :'data.frame': 76 obs. of  7 variables:
  ..$ Type      : Factor w/ 4 levels "Both","Muted",..: 4 4 4 4 4 4 4 4 4 3 ...
  ..$ Area      : num [1:76] -0.393 -0.5011 -0.0197 0.3686 -0.3821 ...
  ..$ Dist_urban: num [1:76] -0.237 -0.043 2.206 0.481 -0.995 ...
  ..$ Above_MHW : num [1:76] 0.156 0.614 1.209 -0.314 -1.426 ...
  ..$ Mcal_conn : num [1:76] -0.125 -0.8 0.386 1.051 -0.443 ...
  ..$ Mmus_conn : num [1:76] -0.528 -0.934 0.611 1.04 -0.609 ...
  ..$ Rrav_conn : num [1:76] -0.9293 -0.9675 0.0539 0.8905 -0.9627 ...
 $ :'data.frame': 76 obs. of  7 variables:
  ..$ Type      : Factor w/ 4 levels "Both","Muted",..: 4 4 4 4 4 4 4 4 4 3 ...
  ..$ Area      : num [1:76] -0.393 -0.5011 -0.0197 0.3686 -0.3821 ...
  ..$ Dist_urban: num [1:76] -0.237 -0.043 2.206 0.481 -0.995 ...
  ..$ Above_MHW : num [1:76] 0.156 0.614 1.209 -0.314 -1.426 ...
  ..$ Mcal_conn : num [1:76] -0.125 -0.8 0.386 1.051 -0.443 ...
  ..$ Mmus_conn : num [1:76] -0.528 -0.934 0.611 1.04 -0.609 ...
  ..$ Rrav_conn : num [1:76] -0.9293 -0.9675 0.0539 0.8905 -0.9627 ...
 $ :'data.frame': 76 obs. of  7 variables:
  ..$ Type      : Factor w/ 4 levels "Both","Muted",..: 4 4 4 4 4 4 4 4 4 3 ...
  ..$ Area      : num [1:76] -0.393 -0.5011 -0.0197 0.3686 -0.3821 ...
  ..$ Dist_urban: num [1:76] -0.237 -0.043 2.206 0.481 -0.995 ...
  ..$ Above_MHW : num [1:76] 0.156 0.614 1.209 -0.314 -1.426 ...
  ..$ Mcal_conn : num [1:76] -0.125 -0.8 0.386 1.051 -0.443 ...
  ..$ Mmus_conn : num [1:76] -0.528 -0.934 0.611 1.04 -0.609 ...
  ..$ Rrav_conn : num [1:76] -0.9293 -0.9675 0.0539 0.8905 -0.9627 ...
 $ :'data.frame': 76 obs. of  7 variables:
  ..$ Type      : Factor w/ 4 levels "Both","Muted",..: 4 4 4 4 4 4 4 4 4 3 ...
  ..$ Area      : num [1:76] -0.393 -0.5011 -0.0197 0.3686 -0.3821 ...
  ..$ Dist_urban: num [1:76] -0.237 -0.043 2.206 0.481 -0.995 ...
  ..$ Above_MHW : num [1:76] 0.156 0.614 1.209 -0.314 -1.426 ...
  ..$ Mcal_conn : num [1:76] -0.125 -0.8 0.386 1.051 -0.443 ...
  ..$ Mmus_conn : num [1:76] -0.528 -0.934 0.611 1.04 -0.609 ...
  ..$ Rrav_conn : num [1:76] -0.9293 -0.9675 0.0539 0.8905 -0.9627 ...
 $ :'data.frame': 76 obs. of  7 variables:
  ..$ Type      : Factor w/ 4 levels "Both","Muted",..: 4 4 4 4 4 4 4 4 4 3 ...
  ..$ Area      : num [1:76] -0.393 -0.5011 -0.0197 0.3686 -0.3821 ...
  ..$ Dist_urban: num [1:76] -0.237 -0.043 2.206 0.481 -0.995 ...
  ..$ Above_MHW : num [1:76] 0.156 0.614 1.209 -0.314 -1.426 ...
  ..$ Mcal_conn : num [1:76] -0.125 -0.8 0.386 1.051 -0.443 ...
  ..$ Mmus_conn : num [1:76] -0.528 -0.934 0.611 1.04 -0.609 ...
  ..$ Rrav_conn : num [1:76] -0.9293 -0.9675 0.0539 0.8905 -0.9627 ... #---------- #3. Create a list of matrices of observation covariates obscovs <- lapply(rodent_imp, function(x){ scaled_obs <- scale(x[, c("Effort", "Year")]) obs_matrix <- as.matrix(scaled_obs) rownames(obs_matrix) <- rodent$Location attr(obs_matrix, "scaled:center") <- NULL attr(obs_matrix, "scaled:scale") <- NULL return(list(obs_matrix)) }) names(obscovs) <- paste0("obs", 1:length(rodent_imp)) str(obscovs) > str(obscovs)
List of 10
 $ obs1 :List of 1
  ..$ : num [1:76, 1:2] -0.68 -1.493 0.337 0.134 -1.493 ...
  .. ..- attr(*, "dimnames")=List of 2
  .. .. ..$ : chr [1:76] "Almonte" "Alto" "Alviso Triangle" "American Canyon" ...
  .. .. ..$ : chr [1:2] "Effort" "Year"
 $ obs2 :List of 1
  ..$ : num [1:76, 1:2] -0.68 -1.493 0.337 0.134 -1.493 ...
  .. ..- attr(*, "dimnames")=List of 2
  .. .. ..$ : chr [1:76] "Almonte" "Alto" "Alviso Triangle" "American Canyon" ...
  .. .. ..$ : chr [1:2] "Effort" "Year"
 $ obs3 :List of 1
  ..$ : num [1:76, 1:2] -0.68 -1.493 0.337 0.134 -1.493 ...
  .. ..- attr(*, "dimnames")=List of 2
  .. .. ..$ : chr [1:76] "Almonte" "Alto" "Alviso Triangle" "American Canyon" ...
  .. .. ..$ : chr [1:2] "Effort" "Year"
 $ obs4 :List of 1
  ..$ : num [1:76, 1:2] -0.68 -1.493 0.337 0.134 -1.493 ...
  .. ..- attr(*, "dimnames")=List of 2
  .. .. ..$ : chr [1:76] "Almonte" "Alto" "Alviso Triangle" "American Canyon" ...
  .. .. ..$ : chr [1:2] "Effort" "Year"
 $ obs5 :List of 1
  ..$ : num [1:76, 1:2] -0.68 -1.493 0.337 0.134 -1.493 ...
  .. ..- attr(*, "dimnames")=List of 2
  .. .. ..$ : chr [1:76] "Almonte" "Alto" "Alviso Triangle" "American Canyon" ...
  .. .. ..$ : chr [1:2] "Effort" "Year"
 $ obs6 :List of 1
  ..$ : num [1:76, 1:2] -0.68 -1.493 0.337 0.134 -1.493 ...
  .. ..- attr(*, "dimnames")=List of 2
  .. .. ..$ : chr [1:76] "Almonte" "Alto" "Alviso Triangle" "American Canyon" ...
  .. .. ..$ : chr [1:2] "Effort" "Year"
 $ obs7 :List of 1
  ..$ : num [1:76, 1:2] -0.68 -1.493 0.337 0.134 -1.493 ...
  .. ..- attr(*, "dimnames")=List of 2
  .. .. ..$ : chr [1:76] "Almonte" "Alto" "Alviso Triangle" "American Canyon" ...
  .. .. ..$ : chr [1:2] "Effort" "Year"
 $ obs8 :List of 1
  ..$ : num [1:76, 1:2] -0.68 -1.493 0.337 0.134 -1.493 ...
  .. ..- attr(*, "dimnames")=List of 2
  .. .. ..$ : chr [1:76] "Almonte" "Alto" "Alviso Triangle" "American Canyon" ...
  .. .. ..$ : chr [1:2] "Effort" "Year"
 $ obs9 :List of 1
  ..$ : num [1:76, 1:2] -0.68 -1.493 0.337 0.134 -1.493 ...
  .. ..- attr(*, "dimnames")=List of 2
  .. .. ..$ : chr [1:76] "Almonte" "Alto" "Alviso Triangle" "American Canyon" ...
  .. .. ..$ : chr [1:2] "Effort" "Year"
 $ obs10:List of 1
  ..$ : num [1:76, 1:2] -0.68 -1.493 0.337 0.134 -1.493 ...
  .. ..- attr(*, "dimnames")=List of 2
  .. .. ..$ : chr [1:76] "Almonte" "Alto" "Alviso Triangle" "American Canyon" ...
  .. .. ..$ : chr [1:2] "Effort" "Year" #---------- #4. Create unmarkedFrameOccuMulti objects #a. Define a function to create the umf objects create_umf <- function(ylist, site_covs, obs_covs) { umf_list <- list() for (i in 1:length(site_covs)) { umf_list[[i]] <- unmarkedFrameOccuMulti( y = ylist, siteCovs = site_covs[[i]], obsCovs = obs_covs[[i]] ) } return(umf_list) } #b. Apply the function to create a list of umf objects (one for each dataset) umf_list <- create_umf(ylist, sitecovs, obscovs) Error: All elements of list provided to obsCovs argument must be named

Kristin Brandon

unread,
Nov 12, 2024, 8:12:50 PM11/12/24
to unmarked
I'm still troubleshooting my code but have not had any success yet. Here is what I have now for obscovs:
#3. Create a list of matrices of observation covariates #a. Extract covariate names obs <- colnames(rodent_imp[[1]]) obs <- obs[c(10:11)] #b. Define a function to extract observation covariates extract_obs <- function(data){ obs_list <- list( Effort = as.matrix(data$Effort), Year = as.matrix(data$Year) ) return(obs_list) } #c. Apply the function to each imputed data set obscovs <- lapply(rodent_imp, extract_obs) str(obscovs) > str(obscovs)
List of 10
 $ :List of 2
  ..$ Effort: num [1:76, 1] -0.68 -1.493 0.337 0.134 -1.493 ...
  ..$ Year  : num [1:76, 1] 0 0 0 0 0 0 0 1 1 0 ...
 $ :List of 2
  ..$ Effort: num [1:76, 1] -0.68 -1.493 0.337 0.134 -1.493 ...
  ..$ Year  : num [1:76, 1] 0 0 0 0 0 0 0 1 1 0 ...
 $ :List of 2
  ..$ Effort: num [1:76, 1] -0.68 -1.493 0.337 0.134 -1.493 ...
  ..$ Year  : num [1:76, 1] 0 0 0 0 0 0 0 1 1 0 ...
 $ :List of 2
  ..$ Effort: num [1:76, 1] -0.68 -1.493 0.337 0.134 -1.493 ...
  ..$ Year  : num [1:76, 1] 0 0 0 0 0 0 0 1 1 0 ...
 $ :List of 2
  ..$ Effort: num [1:76, 1] -0.68 -1.493 0.337 0.134 -1.493 ...
  ..$ Year  : num [1:76, 1] 0 0 0 0 0 0 0 1 1 0 ...
 $ :List of 2
  ..$ Effort: num [1:76, 1] -0.68 -1.493 0.337 0.134 -1.493 ...
  ..$ Year  : num [1:76, 1] 0 0 0 0 0 0 0 1 1 0 ...
 $ :List of 2
  ..$ Effort: num [1:76, 1] -0.68 -1.493 0.337 0.134 -1.493 ...
  ..$ Year  : num [1:76, 1] 0 0 0 0 0 0 0 1 1 0 ...
 $ :List of 2
  ..$ Effort: num [1:76, 1] -0.68 -1.493 0.337 0.134 -1.493 ...
  ..$ Year  : num [1:76, 1] 0 0 0 0 0 0 0 1 1 0 ...
 $ :List of 2
  ..$ Effort: num [1:76, 1] -0.68 -1.493 0.337 0.134 -1.493 ...
  ..$ Year  : num [1:76, 1] 0 0 0 0 0 0 0 1 1 0 ...
 $ :List of 2
  ..$ Effort: num [1:76, 1] -0.68 -1.493 0.337 0.134 -1.493 ...
  ..$ Year  : num [1:76, 1] 0 0 0 0 0 0 0 1 1 0 ...
W​
When I apply this to my umf object, I get the error
Error in FUN(X[[i]], ...) : At least one element of obsCovs has incorrect number of dimensions.
Any ideas what I am doing wrong?

Ken Kellner

unread,
Nov 12, 2024, 9:05:53 PM11/12/24
to unmarked
The code output is hard to read but ultimately, each element in the obsCovs list must be a matrix with identical dimensions to each species y matrix. For some reason you have a list of lists (which unmarked does not support). I guess this relates to your imputed datasets but I don't quite understand what your end goal is with that. Furthermore within each nested list, the matrices have 76 rows and 1 column, implying 76 sites and 1 replicate occasion. But to fit this model  as with regular occupancy models you need >1 replicate occasion. So I recommend checking your y-matrix dimensions and figuring out why the obs cov dimensions have only one column. Year and effort seem like site-level covariates, meaning they do not change across occasions. If so put them in your siteCovs. You will still be able to use them in your detection formula.

If you are having trouble building the unmarkedFrameOccuMulti I recommend reading ?unmarkedFrameOccuMulti again, running the examples, and then comparing the structure of the known 'good' unmarkedFrame outputs from the examples with the structure you are trying to create, in order to identify differences that could be causing these issues.

Ken

Kristin Brandon

unread,
Nov 13, 2024, 11:29:31 AM11/13/24
to unmarked
Hi Ken,

Yes, the obsCovs are currently structured as a list of lists of matrices to accommodate the imputed datasets for occuMulti. I see your point that this structure may be unnecessary given that these variables remain constant across imputations. I will try incorporating these variables into siteCovs instead and will refer to the examples if I encounter further challenges building the unmarkedFrameOccuMulti. Thank you for your guidance!  

Best,
Kristin

Reply all
Reply to author
Forward
0 new messages