I am very new to R and GIS and statistics. I'm trying to find out if two set of points of different class (ie. species) that I have are aggregated or seggregated. For that I need to randomize the proccess of the observation and resample to get a mean of how clustered are those observations.
First I created a grid over my study area and kept only the cells where observations of at least one type of points fell into and made sure the grids were squared polygons. That way I can check how many times the two type of points fall into the same cells compared to the total observed cells where points are found (Nº cells with coincidence /Nº of total cells with observations) and get a percentage. This was done in QGIS.
Then I need to randomize those observations and calculate again how many coincidences I have in relation to total cells with observations. If I repeat this process 1000 times I can get the mean of those 1000 result as the random aggregation pattern in that area to compare to the observed one. If my pattern was 60% and the observed 40% coincidences, then it would mean my points are more seggregated than randomly distributed in the area.
So, I want to do this in R. Firstly I uploaded the shapefile.
shape <- readOGR(dsn = ".", layer = "pruebamalla")
Then I generated random points within the cells of my shapefile for the first type of points. The number of points must be equal to my number of observations for that type of points, which are different for each type of points. (n is an example)
pointsinshape<-spsample(shape, n=120, type = "random")
And I can do the same with the other type of points sets
pointsinshape2<-spsample(shape, n=95, type = "random")
So now I have my two sets of points randomly distirbuted within the cells. Some cells would have x points of type 1, some x points of type 2, some x and y points of type 1 and 2, and some would be empty. I checked it with
plot() and visually the results are reasonable
I know I can use
sp package to check in which cells are my points of each type located. But now I don't know how to proceed to check which cells have the two type of points, besides checking manually in the list to see if the coordinates for the boundaries of each polygon given by over() match or not. And I need to know that to get how many coincidences I have, what is the total of different cells that have at least one type of point and to calculate the percentage of coincidences.
And if it can be done with a generic function or automatically so I could do 1000 resamples of that process and how to get the average valure of those results instead of doing it manually it would also be amazing as I need to repeat this process several times for different pair of points
I have already been searching everywhere and looking at similar threads or problems but found nothing, it would be amazing if someone could give me some guidance or orientation of how I could do this last step.
If you need more information or to upload the shapefile it isn't an issue.