Spatial analysis within site

36 views
Skip to first unread message

shuyi yang

unread,
Jun 21, 2021, 1:24:43 PM6/21/21
to breedR
Dear Facundo,

Thanks for your introduction to this discussion group. I didn't spot it before. Apologize for any inconvenience caused by me. Really appreciate your answers to my questions. 

I used to following codes to analyze spatial effect of my data. However, I got the error message. My data was collected from every tree which was arranged in a complete randomized block design (10-tree-line-plot). I mapped every tree. The coordinates of every tree looks like this: x-308027.7 y-167830.3; x-308022.2 y-167838.3. 

Does the statement in function "remlf90" only apply on the data with regular coordinates and single tree plot?  


##codes: 
mixmod_breedR_AR1_bloc_grid0 <- remlf90(fixed = DBH ~ 1 + as.factor(BlockID),
                                        random = ~ FamilyNumber,
                                        spatial = list(model = "AR",
                                                       coordinates = data_ok[, c("X_m", "Y_m")]),
                                        data = data_ok,
                                        method = "ai")
##error message: 
Error in (function (x, label)  : This does not seem to be a regular grid.
The spacing between rows should be the same for at least the 60% of the cases.
You can override this check with autofill = FALSE.

Thanks again for your previous help.

Zoe

Facundo Muñoz

unread,
Jun 22, 2021, 4:49:24 AM6/22/21
to bre...@googlegroups.com

Dear Zoe,

Thank you for posting your questions to the group. They can be of help for other group members in the future.

If your tree-arrangement is not a regular grid it is best to use splines rather than AR.

AR works only over grids. It can fill-out some missing spots or entire lines. However, when the proportion of "holes" is too important, the computation becomes very expensive, slow and the inference is inefficient. This is what happens when your arrangement is not regular, since breedR tries to find a regular grid resolution that hits all the observations.

Remember that splines typically require method = "em".

Hope it helps

ƒacu.-

--
Report issues at https://github.com/famuvie/breedR/issues
---
You received this message because you are subscribed to the Google Groups "breedR" group.
To unsubscribe from this group and stop receiving emails from it, send an email to breedr+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/breedr/acd3149a-63ad-4db3-b0f7-a4be2b950f04n%40googlegroups.com.

shuyi yang

unread,
Jun 22, 2021, 7:28:49 AM6/22/21
to breedR
Dear  Facundo,

Thanks so much for your help and patience. I used  splines in the model and set up method="em". However, R still gave error (as followed). I think I wrote the codes in a right way? It seems that R gave error because of the large percentage of open space (might be the "holes" mentioned in your previous email) in my data? I worked on a forestry trial which were thinned several times. Much open space was introduced. So sad.   T-T


##codes:
mixmod_breedR_AR1_bloc_grid0 <- remlf90(fixed = DBH ~ 1 + as.factor(BlockID),
                                        random = ~ FamilyNumber,
                                        spatial = list(model = "splines",
                                        coord = data_ok[, c("X_m", "Y_m")]),
                                        data = data_ok,
                                        method = "em")
Using default initial variances given by default_initial_variance()
See ?breedR.getOption.

##error message:
Error in (function (x, label)  : This does not seem to be a regular grid.
The spacing between rows should be the same for at least the 60% of the cases.
You can override this check with autofill = FALSE.

Best regards,
Zoe

Facundo Muñoz

unread,
Jun 22, 2021, 8:24:24 AM6/22/21
to bre...@googlegroups.com

Dear Zoe,

You are right, I forgot that splines also checked for regularity of the grid. Even if it's not really needed, it was convenient for programming. Sorry about that.

However, if the non-regularity is due to thinning, this issue begs the question whether you really need a spatial effect at all. This means that most trees are quite far from each other. As a consequence, the effect of environmental autocorrelation will be very weak and in any case very difficult to identify and separate from individual variation.

In this case, I'd suggest simply removing the spatial effect. It would have very little impact in the results at a high computational cost.

ƒacu.-

shuyi yang

unread,
Jun 25, 2021, 12:51:39 PM6/25/21
to breedR
Dear  Facundo,

Thanks so much for your previous help. I did spatial analysis on other fours datasets.  "remlf90" works which is so exciting! However, I meet another problem when I analyzed one of them. R gave warning message: Warning message: In parse_results(file.path(tmpdir, "solutions"), effects, mf, reml.out,  : The algorithm did not converge

I saw one of your writings from "https://github.com/famuvie/breedR/blob/master/R/remlf90-class.R" , it says: 
Even when an effect accounts for no variance at all, EM-REML will always estimate a positive variance which will be determined by the starting value. If AI-REML does not converge but EM-REML does with the same dataset and model, re-run EM-REML with a small starting value for the effect. If the estimate does not change, it is likely that there is no variance. 

I tried "em" method for the same dataset and model. It ran successfully without warning message. My question is how shall we choose the best methods for our model and dataset? And is there any way to make algorithm converged when using method of "ai", e.g. does setting up initial variance by custom help? 
(I compared the outputs of random effect from "ai" method and "em" method and found that the differences was very little)

Code:
mixmod_breedR_AR1_bloc_grid07 <- remlf90(fixed = DBH ~ 1 + as.factor(BLOCK),
                                          random = ~ TRMNT,
                                          spatial = list(model = "AR",
                                                        coordinates = adh07[, c("X_ok", "Y_ok")]),
                                          data = adh07,
                                          method = "ai")

Thanks again and apologize if any inconvenience caused by me. 


Best regards,
Zoe

Facundo Muñoz

unread,
Jun 28, 2021, 9:03:00 AM6/28/21
to bre...@googlegroups.com

Dear Zoe,

> "... how shall we choose the best methods for our model and dataset?"

In principle, we propose using AI as a default since it is typically faster and more informative... except when it does not work, in which case we propose using EM. Except in a few cases (models using splines or competition) where we know in advance that AI won't perform well and you can start using EM straight away, you have to try and test. If your data set is too big and testing is computationally very expensive, you can consider pilot-testing over a partial data set first, before fitting your "final" model on the full data set.

> "is there any way to make algorithm converged when using method of "ai", e.g. does setting up initial variance by custom help?"

Yes, setting up initial variances close to the final values can help. One strategy can be using EM first to find out approximate values, and then using AI with those values set as initial values.

Another effective strategy for numerical reasons is scaling the quantitative variables (i.e. removing the mean and dividing by the SD, both for the response and the predictors). Very particularly in multi-trait models. The downside is the different interpretation of the coefficients. But is not a big deal, and it is typically well worth it.

Hope it helps,

Best wishes

ƒacu.-

Reply all
Reply to author
Forward
0 new messages