Closed shinneuro closed 3 years ago
Hi,
I believe your component specification should be
components <- coordinates ~ Intercept + s(map = coordinates, group = effect, model = spde)
and for the prediction, supply a Spatial*DataFrame
with a column effect
equal to 1 for the coordinates belonging to "A" and equal to 2 for "B", just as for the data frame you use when estimating the model. I other words, the data supplied to predict()
needs to take a similar format as your actual data.
For example, to extract a spatial grid of predictions for effect 1 only:
df_raw <- pixels(mesh)
df_predict <- SpatialPixelsDataFrame(df_raw, data.frame(effect = rep(1, length(df_raw))))
... <- predict(fit, df_predict, ...)
Hi, finn.
Once again, thank you for your quick response!
The problem is that I am estimating two separate effect for THE SAME MAP.
And I forgot to mention that therefore I added control.group = list(model = "iid")
in the random spatial effects, ending
components <- coordinates ~ Intercept + s(map = coordinates, group = "effect", model = spde, control.group = list(model = "iid"))
For now, I ended up with generating mesh that contains all the coordinates that I want, and I just am using estimates from the lgcp object.
Also, for your reference, for the group effect, group = effect
does not work with the error like that R cannot find effect object. group = "effect"
worked without error, which is a column within the spatialdataframe provided in lgcp
function.
From version 2.3.1, the predict method has an _eval
feature for each component that allows evaluating the result at arbitrary values (e.g. new coordinates and group-values), like s_eval(main=your_coordinates, group = rep("A", nrow(your_coordinates))
.
The interface has been updated quite a lot in versions >= 2.3.0.
Dear Finn,
Thanks!
I was directly working with INLA, but now inlabru seems more powerful!!
I will give it a try!
Dear inlabru,
Thanks to your help, I am getting results! But one concern is that I have difficulty grouping spatial random effects and predicting with
predict
function.For example, I have a set of coordinates and they are either from
effect
A or B. 1) I have tried usinggroup
argument in component: In this case,components <- coordinates ~ Intercept + s(map = coordinates, group = "effect", model = spde)
worked but I have no idea how to generate posteriors usingpredict
with respect to each effect A or B. I checked that two hyperparameterstheta1
andtheta2
were sampled but I do not know how to access them. 2) Alternatively, I tried to useindex
to pointing each effect after I found the function ineffect.R
file. For indexing I generated two columns for two effects, which contains 1 or NA. So, I triedcomponents <- coordinates ~ Intercept + s1(map = coordinates, index = "A", model = spde) + s2(map = coordinates, index = "B", model = spde)
but it didn't work.Thank you again for building this wonderful tool! Yours Sincerely, Minho