-2

I am trying to calculate the mean squared displacement of various longitude and latitudes from a centroid latitude and longitude to show how the spread of an invasive ant progressed through time.

Here is my centroid:

56.6558 3.097367

Here is the rest of my long/lat data

-31.90000 26.88330` -29.31670 27.48330 50.83600 4.38500 -33.91667 18.41667

I am slightly confused on how to progress and would appreciate the help! Thanks!

Here is my current data:

first<-invasion[2:8,] #1906-1910
first<-first[,2:3]

head(first)

       Long       Lat
2  34.20000 -90.56670
3 -31.90000  26.88330
4 -29.31670  27.48330
5  50.83600   4.38500
6 203.34400  17.54000
7 -33.91667  18.41667

fx<-mean(first$Long)
fy<-mean(first$Lat)

coord06<-cbind(fx,fy)
coord06all<-cbind(first$Long, first$Lat)


Ana
  • 9
  • 5
  • 1
    Hello Ana, please provide a reproducible dataset with an example of what you are looking to get, what you have tried, and so forth, so that others users can more easily help you. – Phil Mar 10 '20 at 21:43
  • In addition to @Phil's comment, you can see [here](https://stackoverflow.com/help/minimal-reproducible-example) or [here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) how to make a reproducible example – bretauv Mar 10 '20 at 21:50

1 Answers1

0

Maybe this can help you

displacment <- data - do.call(rbind,replicate(nrow(data),centroid,simplify = FALSE))
mqd <- mean(do.call(`+`,displacment**2))

such that

> mqd
[1] 6216.857

DATA

centroid <- c(56.6558,3.097367)
data <- structure(list(long = c(-31.9, -29.3167, 50.836, -33.91667), 
    lat = c(26.8833, 27.4833, 4.385, 18.41667)), class = "data.frame", row.names = c(NA, 
-4L))
ThomasIsCoding
  • 96,636
  • 9
  • 24
  • 81