Issue with obsCov in unmarkedFramePCO

71 views
Skip to first unread message

Meg Sanders

unread,
Apr 22, 2022, 2:25:46 PM4/22/22
to unmarked
Hi all,

I'm extremely new to unmarked, and I've been struggling with getting my data set up properly to even begin the modeling steps.

I have repeated count data (3 visits each year) for 24 sites over 6 years, and my main goals are to identify the impact certain variables have on the species abundance overtime (I'll be modeling for three separate amphibian species). This data includes forested sites that were harvested at some point during the study, so we have species abundance and other variable data collected pre- and post- harvest as well as control sites that weren't harvested at all throughout the 6 years. I'm calling the pre-, post-, and no-harvest my different treatment groups, as I really want to know how the abundance was impacted by the harvests.

I believe I have my data files set up properly with one row per site and one column per visit. The observation/detection data we have are date and effort for each survey, and they have more columns since the dates and efforts were different for each individual survey. My site covariate file just has one column for each primary visit (so for each year), and right now I've only included treatment as a site covariate because I wanted to get an idea of how to work through unmarked before I included too many site covariates.

I read in my data and go to set up the unmarked frame and get an error with obsCovs:

wf.data <- read.csv("EP_wf_abundance_unm_03302022.csv",row.names = "site",header=TRUE)
obs.data <- read.csv("EP_unm_obscovariates_03302022.csv",row.names = "site",header=TRUE)
site.data <- read.csv("EP_unm_sitecovariates_04212022.csv",row.names = "site",header=TRUE)

wfUMF <- unmarkedFramePCO(y = as.matrix(wf.data), numPrimary = 6, obsCovs = list(date = obs.data[,2:19], effort = obs.data[,20:37]), siteCovs = site.data[,2], yearlySiteCovs = list(treatment = site.data[,2:7]))

Error in `[.data.frame`(obs.data, , 20:37) : undefined columns selected

Typically this type of error would have to do with a missing comma in the formula for selecting the columns of the data frame I'm referring to, but I have the comma in the code, and those columns are definitely in the data file I called from. This is likely a silly error I've made, but I don't know how to fix this.

I've tried running it without obsCovs and then I get the same error with the yearlySiteCovs, too. I must be missing something in my code.

Any help with this is much appreciated, thank you!

-Meg

Ken Kellner

unread,
Apr 23, 2022, 6:56:06 AM4/23/22
to unmarked
Hi Meg,

I'd suggest first using dim(obs.data) and dim(site.data) to check how many columns you actually have in those data frames. When you define a column as being the row.names, as you've done, that removes that column from the actual data frame that gets read into R. So I'm guessing your CSV has 37 columns but once read into R the 'site' column is dropped and you only have 36 columns in obs.data, hence the error.

If I'm correct, to fix this you can either change your indices to e.g. 1:18 and 19:36 or drop the row.names argument when you are reading in the CSVs.

Ken

Meg Sanders

unread,
Apr 25, 2022, 3:29:42 PM4/25/22
to unmarked
Thank you, Ken!

It looks like this was the issue. I definitely misunderstood the initial use of row.names when reading in the data, so I'm glad to know better now.

Reply all
Reply to author
Forward
0 new messages