[R-sig-eco] loss of infolocs data when using redisltraj

basille.web at ase-research.org basille.web at ase-research.org
Tue Feb 10 20:03:21 CET 2015


Dear Liz,

I guess the problem is both technical (the dimensions of the data frames, 
as you pointed out) and biological (how does information associated to 
given steps make sense after interpolation?). You're suggesting to put in 
NAs for the newly interpolated points, which is probably a safe approach if 
the data is considered at the location level, and not at the step level.

Anyway, one issue with 'redisltraj' is that it is written in C, which makes 
editing not very easy... One way to achieve what you want, I think (not 
tested, you'll have to try it by yourself), would be to:

1) Put missing locations back in the trajectory using setNA:

tr1 <- setNA(tr1, tr1[[1]][1, "date"], 60, units = "sec")

This way, you will have the correct dimensions for the main df and the 
infolocs for each ltraj element, but NAs for the coordinates of the missing 
locs.

2) Storing the infolocs somewhere:

info <- infolocs(tr1)

3) Removing the missing locations (!) with na.omit, and interpolate the 
trajectory, as you did before:

tr1.interp <- redisltraj(na.omit(tr1), 60, type = "time"))

4) Now you should be able to transfer the infolocs:

infolocs(tr1.interp) <- info

Let me know if that works!
Mathieu.


Le 10/02/2015 11:52, Elizabeth Morgan a écrit :
> I am using the package AdehabitatLT to interpolate tracking data.
>
> I am working of GPS tracks from diving seabirds, devices were set to record locations every 60s but due to the diving behaviour of the birds I have a lot of missing location data. In order to carry out further analyses I need a regular trajectory so I am trying to interpolate the tracks to every 60s. I have been using the package AdehabitatLT and have created an ltraj object for the tracks, and managed to interpolate the data, however when the data is interpolated I lose the data stored within the infolocs component. I'm guessing it is something to do with the lengths of the dataframes differing. Is there any way to transfer the infolocs data to the interpolated values replacing any missing rows/values with NAs?
>
> R code:
> # Creation of a "ltraj" object, with metadata ("infolocs")
> tr1 <- as.ltraj(xy,date = da,id=id,infolocs = birdData[,6:15])
>> str(tr1)
> List of 1
> $ :'data.frame': 4188 obs. of  10 variables:
>    ..$ x        : num [1:4188] -1.66 -1.66 -1.66 -1.65 -1.66 ...
>    ..$ y        : num [1:4188] 55.6 55.6 55.6 55.6 55.6 ...
>    ..$ date     : POSIXct[1:4188], format: "2014-05-06 10:17:46" "2014-05-06 10:20:34" "2014-05-06 10:21:27" "2014-05-06 10:22:20" ...
>    ..$ dx       : num [1:4188] -0.000206 -0.000587 0.003507 -0.002726 0.0001 ...
>    ..$ dy       : num [1:4188] -0.000828 0.00349 -0.002739 -0.000011 -0.000042 ...
>    ..$ dist     : num [1:4188] 0.000853 0.003539 0.00445 0.002726 0.000108 ...
>    ..$ dt       : num [1:4188] 168 53 53 57 57 53 53 54 56 53 ...
>    ..$ R2n      : num [1:4188] 0.00 7.28e-07 7.72e-06 7.37e-06 7.89e-09 ...
>    ..$ abs.angle: num [1:4188] -1.815 1.737 -0.663 -3.138 -0.398 ...
>    ..$ rel.angle: num [1:4188] NA -2.73 -2.4 -2.47 2.74 ...
>    ..- attr(*, "id")= chr "1465801"
>    ..- attr(*, "burst")= chr "1465801"
>    ..- attr(*, "infolocs")='data.frame':          4188 obs. of  10 variables:
>    .. ..$ GPS_ALT  : num [1:4188] 18.61 2.82 7.12 21.22 24.39 ...
>    .. ..$ GPS_SPD  : int [1:4188] 5184 29088 48780 33732 1008 504 756 396 0 0 ...
>    .. ..$ GPS_CRS  : int [1:4188] 181 88 238 130 179 109 12 137 22 164 ...
>    .. ..$ LOC_TYPE : int [1:4188] 0 0 0 0 0 0 0 0 0 0 ...
>    .. ..$ GPS_DIST : num [1:4188] 0 93 390 376 171 ...
>    .. ..$ Essential: int [1:4188] NA NA NA NA NA NA NA NA NA NA ...
>    .. ..$ time_numb: num [1:4188] 0.429 0.431 0.432 0.432 0.433 ...
>    .. ..$ BIRDID   : int [1:4188] 1465801 1465801 1465801 1465801 1465801 1465801 1465801 1465801 1465801 1465801 ...
>    .. ..$ SEX      : Factor w/ 1 level "M": 1 1 1 1 1 1 1 1 1 1 ...
>    .. ..$ SUBCOL   : Factor w/ 1 level "IF": 1 1 1 1 1 1 1 1 1 1 ...
> - attr(*, "class")= chr [1:2] "ltraj" "list"
> - attr(*, "typeII")= logi TRUE
> - attr(*, "regular")= logi FALSE
>
>
> #interpolation of one track, at 60s.
> tr1.interp<- redisltraj(na.omit(tr1), 60, type = "time")
> str(tr1.interp)
> List of 1
> $ :'data.frame': 132864 obs. of  10 variables:
>    ..$ x        : num [1:132864] -1.66 -1.66 -1.66 -1.66 -1.65 ...
>    ..$ y        : num [1:132864] 55.6 55.6 55.6 55.6 55.6 ...
>    ..$ date     : POSIXct[1:132864], format: "2014-05-06 10:17:46" "2014-05-06 10:18:46" "2014-05-06 10:19:46" "2014-05-06 10:20:46" ...
>    ..$ dx       : num [1:132864] -7.36e-05 -7.36e-05 -1.92e-04 8.03e-04 1.01e-03 ...
>    ..$ dy       : num [1:132864] -0.000296 -0.000296 0.000554 0.001718 -0.001762 ...
>    ..$ dist     : num [1:132864] 0.000305 0.000305 0.000586 0.001896 0.002029 ...
>    ..$ dt       : num [1:132864] 60 60 60 60 60 60 60 60 60 60 ...
>    ..$ R2n      : num [1:132864] 0.00 9.29e-08 3.71e-07 1.16e-07 3.04e-06 ...
>    ..$ abs.angle: num [1:132864] -1.81 -1.81 1.9 1.13 -1.05 ...
>    ..$ rel.angle: num [1:132864] NA 0 -2.564 -0.771 -2.185 ...
>    ..- attr(*, "id")= chr "1465801"
>    ..- attr(*, "burst")= chr "1465801"
>    ..- attr(*, "infolocs")='data.frame':          132864 obs. of  1 variable:
>    .. ..$ pkey: Factor w/ 132864 levels "1465801.2014-05-06 10:17:46",..: 1 2 3 4 5 6 7 8 9 10 ...
> - attr(*, "class")= chr [1:2] "ltraj" "list"
> - attr(*, "typeII")= logi TRUE
> - attr(*, "regular")= logi TRUE
>
>
> Any help would be much appreciated
>
> Thanks,
> Liz
>
> 	[[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-ecology mailing list
> R-sig-ecology at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
>

-- 

~$ whoami
Mathieu Basille
http://ase-research.org/basille

~$ locate --details
University of Florida \\
Fort Lauderdale Research and Education Center
(+1) 954-577-6314

~$ fortune
« Le tout est de tout dire, et je manque de mots
Et je manque de temps, et je manque d'audace. »
  -- Paul Éluard



More information about the R-sig-ecology mailing list