VMM

235 views
Skip to first unread message

adrian...@gmail.com

unread,
Jan 16, 2021, 1:16:24 PM1/16/21
to ctmm R user group
Hi Chris,

I am trying to fit a VMM using the code pasted below and I am getting an error message (Error in `diag<-`).  I have no clue on what its going here. Data used in this attempt is attached. Thanks for your help. Best 
Adrian

##read data for one day of Anonymous (ASY - BLVU)
v1<-as.telemetry("E:\\Hurricane Zeta\\v1.csv")

##read calibration data
cal<-as.telemetry("E:\\Vultures_Fixes\\Calibration data CTT E-400 MB unit 12340 Nov15-21.csv")
#calibrate
UERE <- uere.fit(cal) # only using calibration data
uere(v1)<-UERE

##variogram with altitudinal data
svf.h<-variogram(v1, axes="z")
plot(svf.h)

#guesstimate
GUESS<-ctmm.guess(v1,variogram = svf.h, interactive = F)
GUESS$error<-TRUE

#model selection
FIT<-ctmm.select(v1,GUESS, trace = T)
* Fitting model OUF isotropic error
Error in `diag<-`(`*tmp*`, value = par[c(NAME, NAME)]) : 
  replacement diagonal has wrong length
In addition: Warning message:
In ctmm.fit(data, GUESS, trace = trace2, ...) :
  pREML failure: indefinite ML Hessian or divergent REML gradient
v1.csv
Calibration data CTT E-400 MB unit 12340 Nov15-21.csv

Christen Fleming

unread,
Jan 18, 2021, 4:59:03 PM1/18/21
to ctmm R user group
Hi Adrian,

These issues should be fixed on GitHub now. I anticipate that you may run into further issues, as the vertical (1D) code has not been used in a very long time, but please let me know if you do.

Best,
Chris

adrian...@gmail.com

unread,
Jan 18, 2021, 6:04:07 PM1/18/21
to ctmm R user group
Hi Chris,
Thanks for this. It worked, now I am getting other error when try predict():

> predict(v1, FIT, complete = T)
Error in dim(z) <- c(n, OBS * DIM, VEC) : 
  dims [product 0] do not match the length of object [151]

I tried predict() using the same dataset but with a 2D model and it worked. All the best,

Adrian

Christen Fleming

unread,
Jan 20, 2021, 9:07:16 PM1/20/21
to ctmm R user group
Hi Adrian,

I have one thing on my plate at the moment and I will be right on it.

Best,
Chris

Christen Fleming

unread,
Jan 22, 2021, 12:46:46 PM1/22/21
to ctmm R user group
Hi Adrian,

I fixed a bug and added the ability to predict/simulate both horizontally and vertically, so that complete=TRUE can be performed. You can update the package via devtools::install_github("ctmm-initiative/ctmm")
Below is the sample code I ran and the output. The vertical errors were improved by predict(), but they are still pretty large.

Best,
Chris

##read data for one day of Anonymous (ASY - BLVU)
DATA <- as.telemetry("../DATA/Adrian Naveda-Rodríguez/v1.csv")

##read calibration data
CALI <- as.telemetry("../DATA/Adrian Naveda-Rodríguez/Calibration data CTT E-400 MB unit 12340 Nov15-21.csv")
#calibrate
UERE <- uere.fit(CALI) # only using calibration data
uere(DATA) <- UERE

# fit vertical movement model
zSVF <- variogram(DATA, axes="z")
GUESS <- ctmm.guess(DATA,variogram=zSVF,CTMM=ctmm(error=TRUE),interactive=F)
zFIT <- ctmm.select(DATA,GUESS,trace=2)
zoom(zSVF,CTMM=zFIT)

# fit horizontal movement model
SVF <- variogram(DATA)
GUESS <- ctmm.guess(DATA,CTMM=ctmm(error=TRUE),interactive=F)
FIT <- ctmm.select(DATA,GUESS,trace=2)
zoom(SVF,CTMM=FIT)

# predict locations
PRED <- predict(DATA,CTMM=FIT,VMM=zFIT,complete=TRUE)

# color by time
COL <- color(PRED,by="time")

par(mfrow=c(2,1))
plot(PRED,col=COL,velocity=TRUE)
CI.lo <- PRED$z-1.96*sqrt(PRED$COV.z.z)
CI.hi <- PRED$z+1.96*sqrt(PRED$COV.z.z)
plot(PRED$timestamp,PRED$z,pch=16,col=COL,xlab="Time",ylab="Altitude (m)",ylim=range(CI.lo,CI.hi))
arrows(PRED$timestamp,CI.lo,PRED$timestamp,CI.hi,angle=90,length=0.05,code=3,col=COL)
par(mfrow=c(1,1))
altitude.png

adrian...@gmail.com

unread,
Jan 25, 2021, 5:59:52 PM1/25/21
to ctmm R user group
Chris,
Thanks for this. It works lovely. All the best,
Message has been deleted

adrian...@gmail.com

unread,
Mar 7, 2021, 12:55:06 PM3/7/21
to ctmm R user group
Hi Chris,
I began to run this with a larger dataset and got some error when running ctmm.select() 
Here is the error from the first two individuals i tried:

> FIT.z<-ctmm.select(vu[[1]],GUESS, trace = T)
* Fitting model OUF isotropic error
Error in dim(z) <- c(n, OBS * DIM, VEC) : 
  dims [product 50504] do not match the length of object [63130]

> FIT.z<-ctmm.select(vu[[2]],GUESS, trace = T)
* Fitting model OUF isotropic error
Error in dim(z) <- c(n, OBS * DIM, VEC) : 
  dims [product 143000] do not match the length of object [178750]

I give up on this a try again two weeks later and I did not get that error, but I am getting this one:


V.zFITS <- list()
V.FITS <- list()
V.AKDE <- list()
V.PRED <- list()

for(i in 1:length(vulture))
{
  print(i)
  # fit vertical movement model
  zSVF <- variogram(vulture[[i]], axes="z")
  zGUESS <- ctmm.guess(vulture[[i]],variogram=zSVF,CTMM=ctmm(error=TRUE),interactive=F)
  V.zFITS[[i]] <- ctmm.select(vulture[[i]],zGUESS,trace=2)
  
  # fit horizontal movement model
  SVF <- variogram(vulture[[i]])
  GUESS <- ctmm.guess(vulture[[i]],CTMM=ctmm(error=TRUE),interactive=F)
  V.FITS[[i]] <- ctmm.select(vulture[[i]],GUESS,trace=2)
  
  V.PRED[[i]] <- predict(vulture[[i]],CTMM=V.FITS,VMM=V.zFITS,complete=TRUE)
}

[1] 1
* Fitting model OUF isotropic error
Maximizing likelihood.
Calculating Hessian.
Calculating REML gradient.
Profiling REML likelihood.
Calculating REML Hessian.
* Fitting model OU isotropic error
Maximizing likelihood.
Calculating Hessian.
Calculating REML gradient.
Profiling REML likelihood.
Calculating REML Hessian.
* Fitting model OUf isotropic error
Maximizing likelihood.
Calculating Hessian.
Calculating REML gradient.
Profiling REML likelihood.
Calculating REML Hessian.
* Fitting model OUF isotropic error
Maximizing likelihood.
Calculating Hessian.
Calculating REML gradient.
Profiling REML likelihood.
Calculating REML Hessian.
* Fitting model OUF anisotropic error
Maximizing likelihood.
Calculating Hessian.
Calculating REML gradient.
Profiling REML likelihood.
Calculating REML Hessian.
* Fitting model OU isotropic error
Maximizing likelihood.
Calculating Hessian.
Calculating REML gradient.
Profiling REML likelihood.
Calculating REML Hessian.
* Fitting model OU anisotropic error
Maximizing likelihood.
Calculating Hessian.
Calculating REML gradient.
Profiling REML likelihood.
Calculating REML Hessian.
* Fitting model OUf isotropic error
Maximizing likelihood.
Calculating Hessian.
Calculating REML gradient.
Profiling REML likelihood.
Calculating REML Hessian.
* Fitting model OUf anisotropic error
Maximizing likelihood.
Calculating Hessian.
Calculating REML gradient.
Profiling REML likelihood.
Calculating REML Hessian.
Error in get(object$mean) : invalid first argument
In addition: Warning message:
In FUN(X[[i]], ...) :
  Objective function failure at c(major=0, tau position=4.10680418330405, tau velocity=0.213052082092495)

All the best,

Adrian

Christen Fleming

unread,
Mar 7, 2021, 4:04:14 PM3/7/21
to ctmm R user group
Hi Adrian,

Do you mind sending me a minimal working example (data and small script) so that I can diagnose the errors?

Best,
Chris

Adrián Naveda-Rodríguez

unread,
Mar 7, 2021, 6:21:01 PM3/7/21
to Christen Fleming, ctmm R user group

Hi Chris,

 

I though files were attached, sorry for that. Here goes one month of data for the first individual in the dataset and the one producing the error. This is the code I used:

 

 

 

##bring data

vulture<-as.telemetry("E:\\Vultures_Fixes\\Vultures position Summer-Fall 2020 MBf id+season.csv")

 

##read calibration data

cal<-as.telemetry("E:\\Vultures_Fixes\\Calibration data CTT E-400 MB unit 12340 Nov15-21.csv")

 

#calibrate

UERE <- uere.fit(cal) # only using calibration data

summary(UERE)

uere(vulture)<-UERE

names(vulture[[1]])

 

 

V.zFITS <- list()

V.FITS <- list()

V.AKDE <- list()

V.PRED <- list()

 

for(i in 1:length(vulture))

{

  print(i)

  # fit vertical movement model

  zSVF <- variogram(vulture[[i]], axes="z")

  zGUESS <- ctmm.guess(vulture[[i]],variogram=zSVF,CTMM=ctmm(error=TRUE),interactive=F)

  V.zFITS[[i]] <- ctmm.select(vulture[[i]],zGUESS,trace=2)

 

  # fit horizontal movement model

  SVF <- variogram(vulture[[i]])

  GUESS <- ctmm.guess(vulture[[i]],CTMM=ctmm(error=TRUE),interactive=F)

  V.FITS[[i]] <- ctmm.select(vulture[[i]],GUESS,trace=2)

 

  #V.AKDE[[i]] <- akde(vulture[[i]],V.FITS[[i]],trace=TRUE)

  V.PRED[[i]] <- predict(vulture[[i]],CTMM=V.FITS,VMM=V.zFITS,complete=TRUE)

}

 

 

 

 

 

Thanks for the help. Best

 

 

Adrian

Image removed by sender. altitude.png

--
You received this message because you are subscribed to a topic in the Google Groups "ctmm R user group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ctmm-user/3yTRsDvc7Ak/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ctmm-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ctmm-user/8104c0c2-88b4-4865-9ee2-1b14b6af7dbfn%40googlegroups.com.

~WRD000.jpg
Anonymous_Fall_2020.csv

Christen Fleming

unread,
Mar 11, 2021, 7:29:39 PM3/11/21
to ctmm R user group
Hi Adrian,

I am not getting these errors in the development branch on GitHub:

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

Please tell me if you run into any further issues.

Best,
Chris

Adrián Naveda-Rodríguez

unread,
Mar 11, 2021, 7:53:52 PM3/11/21
to ctmm R user group

Hi Chris,

Thanks for looking at this. Today I noticed that I got the error when I split the data by season or day. For example, today I split the dataset by day so in the input file each bird-day is a unique individual. By doing that I got this:

 

* Fitting model IID isotropic error

Maximizing likelihood.

Calculating Hessian.

Error in dim(z) <- c(n, OBS * DIM, VEC) :

  dims [product 228] do not match the length of object [285]

In addition: Warning messages:

1: In FUN(X[[i]], ...) : Objective function failure at c(major=0)

2: In FUN(X[[i]], ...) : Objective function failure at c(major=0)

3: In FUN(X[[i]], ...) : Objective function failure at c(major=0)

4: In FUN(X[[i]], ...) : Objective function failure at c(major=0)

Error in dim(z) <- c(n, OBS * DIM, VEC) :

  dims [product 228] do not match the length of object [285]

Profiling REML likelihood.

Calculating REML Hessian.

Error in dim(z) <- c(n, OBS * DIM, VEC) :

  dims [product 228] do not match the length of object [285]

In addition: Warning messages:

1: In ctmm.fit(data, GUESS, trace = trace2, ...) :

  pREML failure: indefinite ML Hessian or divergent REML gradient.

2: In FUN(X[[i]], ...) : Objective function failure at c(major=0)

3: In FUN(X[[i]], ...) : Objective function failure at c(major=0)

4: In FUN(X[[i]], ...) : Objective function failure at c(major=0)

5: In FUN(X[[i]], ...) : Objective function failure at c(major=0)

Error in dim(z) <- c(n, OBS * DIM, VEC) :

  dims [product 228] do not match the length of object [285]

 

After this, I ran the dataset without splitting, and it is working, so far there is no error in the first individual which is the one producing the error. I’ll let you know if something happen.

 

All the best,

 

Adrian

 

From: ctmm...@googlegroups.com <ctmm...@googlegroups.com> On Behalf Of Christen Fleming
Sent: Thursday, March 11, 2021 6:30 PM
To: ctmm R user group <ctmm...@googlegroups.com>
Subject: [ctmm-user] Re: VMM

 

Hi Adrian,

Image removed by sender. altitude.png

--

You received this message because you are subscribed to a topic in the Google Groups "ctmm R user group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ctmm-user/3yTRsDvc7Ak/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ctmm-user+...@googlegroups.com.

~WRD000.jpg

Christen Fleming

unread,
Mar 11, 2021, 10:12:47 PM3/11/21
to ctmm R user group
Hi Adrian,

Could you email me a minimal working example (data & script) that causes this error to occur?

Best,
Chris

adrian...@gmail.com

unread,
Mar 19, 2021, 11:05:10 AM3/19/21
to ctmm R user group
Hi Chris,
Hope you are doing well. Here goes the data and the scripts for three different attempts wit the same data to do estimations by day, season and/or all the data available. I got errors in all. Each script and error is in a word document and the data files have the same names than the word documents. Thankyou very much for your help.

All the best,

Vultures position Summer-Fall 2020 MBf id+season.csv
Vultures position Summer-Fall 2020 MBf.csv
Calibration data CTT E-400 MB unit 12340 Nov15-21.csv
Vultures position Summer-Fall 2020 MBf id+day.csv
R studio script and console Vultures position Summer-Fall 2020 MBf id+day.docx
R studio script and console Vultures position Summer-Fall 2020 MBf.docx
R studio script and console Vultures position Summer-Fall 2020 MBf id+season.docx

Christen Fleming

unread,
Mar 20, 2021, 10:30:53 PM3/20/21
to ctmm R user group
Thanks Adrian,

This error should be fixed on GitHub now.

There's some remaining improvement that I need to make to the optimization in these cases (where the variance estimate collapses due to large location error), but I need to mull over that more and it's just an issue of computational speed.

Best,
Chris
Reply all
Reply to author
Forward
0 new messages