jamesepaterson / trackingworkshop

Analyzing telemetry data in R
19 stars 13 forks source link

Prblems with the function reptile.kd.h.fn #4

Closed marinapardinus closed 3 years ago

marinapardinus commented 3 years ago

Hello, I am getting some problems with the function to get the smoothing factor so the 95% kernel sequals the 100%MCP: This is my code:

tracking.df <- read.table("coords_over2.txt", sep="\t", header=T, dec=".") str(tracking.df)

Remove rows with NA's tracking.sp <- tracking.df[!is.na(tracking.df$x) & !is.na(tracking.df$y),] cat(nrow(tracking.df) - nrow(tracking.sp), "records are removed")

Convert to spatial point coordinates(tracking.sp) <- c("x", "y") proj4string(tracking.sp)<-("+proj=longlat +datum=WGS84")

After creating the function: Apply smoothing factor estimating function. system.time just provides time estimate Notice I save vector of smoothing factos to "h.pred" system.time(h.pred <- reptile.kd.h.fn(tracking.sp)) # The sp object should contain at least x,y, & id Takes: 10 - 15 sec for 5 animals h.pred

Then I get this error: Error in simpleLoess(y, x, w, span, degree = degree, parametric = parametric, : invalid 'x' In addition: There were 50 or more warnings (use warnings() to see the first 50) Timing stopped at: 3.53 0.17 3.72


I don't know if I have a problem with my data or constructing the function reptile.kd.h.fn

THANK YOU VERY MUCH! :)

marinapardinus commented 3 years ago

Do we have to calculate href and hpred before?

jamesepaterson commented 3 years ago

Hi @marinapardinus, the error is caused by the loess part of the function failing. Because the function is trying to calculate area and then fit a loess function (area~smoothing factor), the coordinate inputs must be in a coordinate reference system measured in metres. I see you have yours in lat/lon decimal degrees, and I am getting the same error when I use the example data converted into decimal degrees.

Try: tracking.sp_utm <- spTransform(tracking.sp, CRS("my UTM CRS")) system.time(h.pred <- reptile.kd.h.fn(tracking.sp_utm))

Replace "my UTM CRS" with the appropriate zone and datum for your study site (e.g. CRS( "+proj=utm +zone=18 +datum=WGS84 +units=m +no_defs" ).

Please reply if this solves the issue you're having

marinapardinus commented 3 years ago

Hi @jamesepaterson It worked!! Thank you very much, yes, it was the projection all along. I did not change it properly. Now it works! Thank you very much :)

Best, Marina