"Error in names(tau)..." when estimating speed and distance

55 views
Skip to first unread message

Charlotte Milling

unread,
Mar 3, 2021, 6:10:50 PM3/3/21
to ctmm R user group
Hi! I ran into this error when estimating distance travelled:

Error in names(tau) <- tau.names[1:K] : 
  'names' attribute [2] must be the same length as the vector [0]
In addition: Warning message:
In min(dz[dz > 0]) : no non-missing arguments to min; returning Inf

The script worked fine for a different animal over several days, but when I got to this individual, it estimated distance travelled on Day 1, and I got the error on Day 2. 

I have used other functions in the ctmm package with this same dataset without issue, so I'm inclined to think the issue isn't with the data, but I'm at a loss to explain what's happening. 

Any ideas?

Can't tell you how grateful I am for your help!
Charlotte Milling

### Estimate daily movement distance over the duration of the animal wearing the collar
mydata2.tel$day<-cut(mydata2.tel$timestamp, breaks="day")
days<-unique(mydata2.tel$day) #determines how many days the animal was tracked for
res<-list() #Empty list to fill with the results
#Loop over the number of days
for(i in 1:length(days)){
  message("Estimating distance travelled on day ", i, ": ", days[i])
  #Select data for the day in question
  mydata2.tel.SUBSET<-mydata2.tel[which(mydata2.tel$day == days[i]),]
  #Calculate the duration of the sampling period in seconds
  SAMP.TIME<-diff(c(mydata2.tel.SUBSET$t[1],
                     mydata2.tel.SUBSET$t[nrow(mydata2.tel.SUBSET)]))
  #Guesstimate the model for initial parameter values
  GUESS<-ctmm.guess(mydata2.tel, variogram = variogram(mydata2.tel), interactive=F)
  #Turn error on
  GUESS$error<-TRUE
  #Fits the movement model to the day's data
  FITS<-ctmm.fit(mydata2.tel.SUBSET, CTMM=GUESS)
  #Calculate the speed in m/s
  ctmm_speed<-speed(object= mydata2.tel.SUBSET, CTMM= FITS, units = FALSE)
  #Multiply speed (in m/s) by the sample time (in s) to get the estimate distance traveled (in m)
  ctmm_dist<-ctmm_speed*SAMP.TIME
  #Rename the variable
  rownames(ctmm_dist) <- "distance (meters)"
  #Store the results in the list
  x<-c(i, #The day
       ctmm_dist[2], #The ML distance estimate
       ctmm_dist[1], #Min CI
       ctmm_dist[3]) #Max CI
  names(x) <- c("date", "dist.ML", "dist.Min", "dist.Max")
  res[[i]]<-x
}

Charlotte Milling

unread,
Mar 3, 2021, 6:16:34 PM3/3/21
to ctmm R user group
Actually, now that I've sent that, I am wondering if the number of relocations in a given day would trigger that error and cause the for loop to crash (rather than just moving onto day 2)? On the day in question, I only have three relocations for the animal. Perhaps instead of issuing a warning and recording a value of Inf or some other unrealistic number, the entire looped just crashed and did not run for the rest of the days in the dataset? 

Christen Fleming

unread,
Mar 3, 2021, 7:48:58 PM3/3/21
to ctmm R user group
Hi Charlotte,

That's probably the case. I'll look into it further in a couple of days, when I'm finished re-coding the location error class fitting. I should be able to squeeze something better than an error out of 3 locations.

Best,
Chris

Christen Fleming

unread,
Mar 11, 2021, 7:28:05 PM3/11/21
to ctmm R user group
Hi Charlotte,

I made an example case where I took smaller and smaller datasets and ran them through ctmm.guess, ctmm.select, speed, and fixed every error that came up when having only 4,3,2,1 sampled locations. The updates are in the development branch on GitHub. Please tell me if you run into any further issues.

devtools::install_github("ctmm-initiative/ctmm")

Best,
Chris

Charlotte Milling

unread,
Mar 12, 2021, 6:07:39 PM3/12/21
to ctmm R user group
That's great news! Thanks so much for your help!
Reply all
Reply to author
Forward
0 new messages