Help Needed with this: Error in unmarkedFrame(y, siteCovs, obsCovs, obsToY = diag(J), mapInfo = mapInfo) : At least one matrix in obsCovs has incorrect number of dimensions.

906 views
Skip to first unread message

Penguin

unread,
Apr 2, 2018, 12:35:28 PM4/2/18
to unmarked
I am trying to fit a single season occupancy model.
I am running into errors with my obsCovs but can't seem to figure out what went  wrong.
Would anyone provide any solutions to this please?
I have been working on this for weeks now and I am still really stuck and would greatly appreciate any tips.

This is my code:

 Odata<-read.csv("Occu_data2.csv")
> y<-Odata[,c(1,8)]
> site.covs<-Odata[,c(2,3)]
> obs.cond<- list(Odata[,c(11:13)])

> str(y)
'data.frame':   3024 obs. of  2 variables:
 $ Site: Factor w/ 7 levels "Site2","Site3",..: 1 1 1 1 1 1 1 1 1 1 ...
 $ Y1  : int  0 0 0 0 0 0 0 1 0 0 ...

> str(site.covs)
'data.frame':   3024 obs. of  2 variables:
 $ Treatment : Factor w/ 2 levels "Control","Road": 2 2 2 2 2 2 2 2 2 2 ...
 $ Road.width: num  6 6 6 6 6 6 6 6 6 6 ...

> str(obs.cond)
List of 1
 $ :'data.frame':       3024 obs. of  3 variables:
  ..$ Species: Factor w/ 8 levels "BS","DTT","LTG",..: NA NA NA NA NA NA NA 8 NA NA ...
  ..$ Sex    : Factor w/ 2 levels "F","M": NA NA NA NA NA NA NA 2 NA NA ...
  ..$ Age    : Factor w/ 2 levels "A","SA": NA NA NA NA NA NA NA 1 NA NA ...

> umf<-unmarkedFrameOccu(y=y, siteCovs = site.covs, obsCovs = obs.cond)
Error in unmarkedFrame(y, siteCovs, obsCovs, obsToY = diag(J), mapInfo = mapInfo) :
  At least one matrix in obsCovs has incorrect number of dimensions.

Occu_data2.xlsx

Jim Baldwin

unread,
Apr 2, 2018, 6:15:57 PM4/2/18
to unma...@googlegroups.com
I think you need two things:

  1. The survey design should be described more detail.  I had to guess that a "site" is a unique combination of Site and Trap.Number and that y1 is the observed status (0 or 1).  Also, it would appear that there is either a trap grid or collections of traps at specified distances from the road.  And there are "controls" which I can only assume aren't roads but yet there are the same set of distances associated with the controls.  You'll get much better advice here with a succinct set of details.

  2. Your main question is about setting up the data with unmarkedFrameOccu.  That requires some rearrangement of your data.  Here's one way that doesn't require an additional package (such as the very nice arrayhelpers):
# Define function to rearrange data so that columns represent the size separate trap nights
rearrange <- function(id) {
  matrix(c(Odata[Odata$Trap.Night==1,id],
           Odata[Odata$Trap.Night==2,id],
           Odata[Odata$Trap.Night==3,id],
           Odata[Odata$Trap.Night==4,id],
           Odata[Odata$Trap.Night==5,id],
           Odata[Odata$Trap.Night==6,id]), ncol=6, byrow=FALSE)
}

y <- rearrange(8)
obs.cond <- list(Trap.Status=rearrange(10), Species=rearrange(11), 
  Sex=rearrange(12), Age=rearrange(13))
site.covs <- Odata[Odata$Trap.Night==1,c(1,2,3,9)]
umf<-unmarkedFrameOccu(y=y, siteCovs = site.covs, obsCovs = obs.cond)

occu(~1 ~1, umf)
occu(~Distance.fromroad ~Treatment, umf)


 

--
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.

Penguin

unread,
Apr 2, 2018, 9:53:10 PM4/2/18
to unmarked

Thanks for the quick reply and attempting to understand my data.
Here is a more detailed explanation of my design.

On point 1.   I put 72 traps out for small mammals over 6 continuous trap nights at 4 road sites and 3 continuous forest (controls).
                   So I have a total of 432 data points for each site. At each site, the traps were placed in a line transect from (0m.....210m) at a fixed 30m increment.
                   To differentiate, the location of each of my trap I have a trap number. The trap number is more for my reference cause the distance from the road will provide the same information.
                   On my control sites, the traps were placed at the same distance but because there is no road, the distance is meaningless.

On my data: Y1=presence/absence of small mammal in trap
                   Trap night = Day of trapping (between 1-6)
                   Site = Site 1 to 7
                   Treatment = Road or a control site
                   Road width = Width of the road
                   Species = species of small mammal when caught in trap
                   Age = age of the small mammal
                   Sex = gender of the small mammal

My aim is to fit my data to model small mammal occupancy of road side habitats versus continuous forest sites while accounting for imperfect detectability.

Just to make sure my data is in the right format, under the following
Detection history should have : Site, Trap Night??, Y1 . Since the output of Y1(the presence/ absence is dependent on Site x number of trap night at each site)
Site specific covariates: Treatment, Road Width, Date sampled
Observation covariates: Species, Age and Sex

Am I on the right track?
To unsubscribe from this group and stop receiving emails from it, send an email to unmarked+u...@googlegroups.com.

Jim Baldwin

unread,
Apr 3, 2018, 1:02:42 AM4/3/18
to unma...@googlegroups.com
Thanks for adding the details.  That's very helpful.

I think you're on the right track but someone with far better skills that what I have at selecting reasonable models that make biological sense would need to comment.

Jim

To unsubscribe from this group and stop receiving emails from it, send an email to unmarked+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages