Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testSpatialAutocorrelation() returns an ape: :Moran.I error #190

Closed
schis023 opened this issue Jul 6, 2020 · 4 comments
Closed

testSpatialAutocorrelation() returns an ape: :Moran.I error #190

schis023 opened this issue Jul 6, 2020 · 4 comments

Comments

@schis023
Copy link

schis023 commented Jul 6, 2020

Hello,

I have a data set of multiple locations (approx. 14 000 unique coordinate points) that have been sampled multiple times over ~10 years. I'm building mixed models with these data and I want to test the residuals for spatial autocorrelation. Following this package's recommendations, I used recalculateResiduals() to account for the multiple samples for each location as follows:

sims <- simulateResiduals(model1)
groupedSims <- recalculateResiduals(sims, group = df$Site) # Where Site indicates each location with a unique coordinate point.

This works fine up to the point where I use testSpatialAutocorrelation(). First I isolated one year's worth of coordinate points so that I have a data frame of unique coordinates to refer to. Then I plugged in these unique coordinates into testSpatialAutocorrelation():

year1 <- df[(df$YEAR == 2000),]
coords <- data.frame(LONG = c(year1$LONG), LAT = c(year1$LAT))

testSpatialAutocorrelation(groupedSims,coords$LONG,coords$LAT,plot=FALSE)

This returns the error:

Error in ape::Moran.I(simulationOutput$scaledResiduals, weight = invDistMat,  : 
  'weight' must have as many rows as observations in 'x'

Any ideas about what might be going on and how to resolve this problem?

Thank you!

@florianhartig
Copy link
Owner

There is with near certainty some problem in your data structure. Check:

  • groupedSims plots fine?
  • how many residuals are in groupedSims?
  • how many rows does coords have? Does this match?
  • are there any duplicates in coords?

I should probably check these things and implement a more meaningful error message.

Best,
Florian

@schis023
Copy link
Author

schis023 commented Jul 7, 2020

Thanks for your suggestions Florian.

After digging into the structure of my data set, I did indeed find the problem there. One of my sites had two separate locations in space, resulting in two unique coordinate points for one site with the same ID. This resulted in one extra value in 'coords' compared to the number of residuals in 'groupedSims'. After giving the two locations unique site IDs and re-running the code above, testSpatialAutocorrelation() worked just fine.

Cheers,
Sarah

@florianhartig
Copy link
Owner

Hi Sarah,

thanks for the feedback - I'll keep the issue open as a reminder to implement a more meaningful error message.

Best,
Florian

@florianhartig florianhartig modified the milestones: 0.3.3., 0.3.4 Aug 22, 2020
@florianhartig
Copy link
Owner

@EttnerAndreas - could you have a look at this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants