Problems with spatial autocorrelation plot

9 views
Skip to first unread message

Gabriella Scatà

unread,
Jul 4, 2024, 9:01:49 PM (4 days ago) Jul 4
to dartR
Hi,
I have just started using the gl.spatial.autoCorr() function and I already have issues at the start.... :/

The functions runs fine, but the plot looks weird, no matter which distances (max and bins) I use.
I don't get any curve/lines representing the relatedness of samples across bins, I only get a bar for each population or for each sex (I tried both with pop = pop, or pop=sex) that is fixed at the start...
What am I doing wrong?

I checked my lon and lat info:
it is reported correctly i think:
head(my_dataset_genlight@other$latlon)
ind ID   lat          lon
1          -25.5     153.35

I tried also to convert the lat lon data with Mercator:
the Mercator function was giving me this warning message:
 # Warning message:
    # In .pointsToMatrix(p, checkLonLat = FALSE) :
      # Suspect column names (longitude and latitude reversed?)

So, I reversed the order of lat lon in my genlight, like this
my_dataset_genlight@other$latlon = 
   my_dataset_genlight@other$latlon[ ,c(2,1)]

then run Mercator:
my_dataset_genlight@other$latlon = Mercator(
my_dataset_genlight@other$latlon , inverse= T)

ind ID     lat              lon
1          -0.00022     0.0013

Although I am not sure if I should transform to Mercator, if my lat and lon is taken from Google map positions?

Anyways, this is the code I used:
gl.spatial.autoCorr(my_dataset_genlight,
                    bins = seq(0, 1500000, 100000),
                    plot.pops.together = FALSE,
                    plot.colors.pop = c('#E69F00', '#5D3FD3', "red", "blue", "green", "violet"))

I also tried running the functions in this way:
- plot.pops.together = TRUE
- replace pop(my_dataset_genlight) = my_dataset_genlight@other$ind.metrics$sex
- changing the bins to seq(0, 150, 10)

But I always get the same result with no lines plotted...and a single bar for each pop/each sex at the very start of the plot...

I also tried to convert to Mercator, but with inverse = F (which seems more correct as I am passing from latlon to Mercator), but then when I run the spatial autocorrelation with the dataset converted in this way, i get the message:
Error in x_temp@other$latlon[ , c("lon", "lat")]: suscript out of bound

What am I doing wrong?
See plot attached...

I would really appreciate some help!!
Thanks a lot!
Gabriella
spatial_autocorr_plot_0_1500km.jpeg

Jose Luis Mijangos

unread,
Jul 5, 2024, 1:31:59 AM (4 days ago) Jul 5
to dartR
Hi Gabriella,

The problem is that the spatial autocorrelation analysis is performed by population, as mentioned in the function documentation:

"If the input is a genlight object, the function calculates the linear distance for Dgeo and the relevant Dgen matrix (see Dgen_method) for each population"

In your case, all the individuals within a population have the same GPS location. 

One solution would be assigning the same population to all the individuals, as shown below:

library(dartRverse)
t1 <- your_genlight
pop(t1) <- rep("pop",nInd(t1))
res <- gl.spatial.autoCorr(t1)

Cheers,
Luis 

Gabriella Scatà

unread,
Jul 5, 2024, 2:56:08 AM (4 days ago) Jul 5
to da...@googlegroups.com
Oh, I see, yes that makes sense!
Buy then can I also ask this again for clarifications:
- do I need to convert my Google maps coordinates lat lon coordinates (i.e. -18.00, 152.30)  into Mercator or can I just use my Google maps coordinates? In the function documentation, it seems I can use both, is that correct?
- but do I need to convert to Mercator if I want my bin sizes and distance information in the plot in meters? Or does the function automatically take that into account the different type of information and does the conversion to meters before plotting?
- In case I convert to Mercator - it seems I need to reverse the order of genlight@other$latlon to "lon lat" to use Mercator() (correct?) --> in that case, do I need to reverse the order back again to "lat lon" to use the genlight in gl.spatial.autoCorr()? 
- To decide the bin sizes and min -max distance to plot, can I just look at my max range of distances? so say if my sampling goes from a certain location to 1500 km away, is it correct to code it in meters in the gl.spatial.autoCorr() function? --
--> like this: bins = seq(0, 1500000, 100000) ?

Thanks a lot for your feedback once again!
Best,
Gabriella

--
You received this message because you are subscribed to the Google Groups "dartR" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dartr+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dartr/c3a5d6b5-46d6-4ab2-8d82-c2035ea79175n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages