matthewsilk / CMRnet

CMRnet: an R package to construct and permute movement and co-capture social networks from mark-recapture data
http://matthewsilk.github.io/CMRnet
3 stars 1 forks source link

CMRnet, Error in if (nrow(adjmatrix) != ncol(adjmatrix)) { : argument is of length zero #2

Closed cls03 closed 2 years ago

cls03 commented 2 years ago

I am trying to run my capture mark recapture data through the CMRnet package, and MultiMoveNetCreate() and am hitting issues after generating the movement network. i've gone through the vignettes and am still lost. I can't figure out where I've gone wrong. I keep getting the error when running the cmr_igraph line:

Error in if (nrow(adjmatrix) != ncol(adjmatrix)) { : argument is of length zero

Enter a frame number, or 0 to exit

1: cmr_igraph(movementmodel, type = "multiplex") 2: igraph::graph.adjacency(tmat1, mode = "directed", weighted = TRUE) 3: graph.adjacency.dense(adjmatrix, mode = mode, weighted = weighted, diag = diag

Would anyone be able to point me in the right direction of what I'm doing wrong? Thanks so much.

cmrnet_help.csv



library(CMRnet)
library(lubridate)
library(igraph)
library(glmmTMB)
library(igraph)

rm(list=ls()) #clear r memory

cmr <- read.csv(file="cmrnet_help.csv", sep=",", as.is=FALSE, header=TRUE)
cmr

colnames(cmr)
str(cmr)

cmr <- as.data.frame(cmr)
cmr %>% mutate_if(is.factor, as.character) -> cmr
cmr
cmr$date <- as.Date(cmr$date, format = "%Y-%m-%d")
cmr$layer <- as.factor(cmr$layer)
str(cmr)
# Define parameters for first time period
mindate<-"2000-01-07" 
maxdate<-"2021-03-20" 
intwindow<- 2  # will use one day as the time of which two indiv can be considered as co-captured in a social network
netwindow<- 1 # 
overlap<- 0
spacewindow<- 0

# Generate Multiplex movement networks, originally MultiMoveNetCreate
movementmodel <-
  MultiMoveNetCreate(
    data = cmr,
    intwindow = intwindow,
    mindate = mindate,
    maxdate = maxdate,
    netwindow = netwindow,
    overlap = overlap,
    nextonly = TRUE,
    index=FALSE
  )
#> [1] "End of final network window aligns with end of study"

#convert the output to a list of igraph network objects for use in further analyses or plotting
# create igraph objects

networks <- cmr_igraph(movementmodel,type="multiplex")
`
matthewsilk commented 2 years ago

This is a problem caused when there were either zero or one nodes within a particular network window. I have now adjusted the cmr_igraph() function so that this error should be avoided and it provides warnings when this is the case, as it is an indicator that networks are likely very sparse with the inputs provided.