how to define functions of covariates in lgcp #101
-
For a straightforward e.g. Poisson glm say, I can include any covariates with the data passed to my_fun = function(x, theta){
# something involving x and theta
}
# covariates stored in column z in the data passed to bru()
fml = y ~ my_fun(z, theta)
cmp = ~ theta How can I do something like this when the model is a log-Gaussian Cox process? In this case the covariate is defined everywhere, not just at the observed points. I am considering something like my_fun = function(x,y, theta){
# get covariate value at location x,y
# do something with this value that depends on theta
} This is similar to how do continuous covariates my_cov = function(x,y) { # get cov value at x,y}
cmp = ~ cov(main = my_cov, model = "linear") I don't understand how the model knows what to do with this component. It assumes it needs to get coordinates (probably a 2 column matrix?), split it into an |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 7 replies
-
For full control over component inputs, you can use the full function call (if This will cause inlabru to first evaluate the function call and store the result as a new internal variable. This is then used in the same way as if it had been part of the input data, so for regular models this doesn't really provide anything extra; you could just as well have created that variable before calling inlabru. But for LGCP models, this approach allows it to call your evaluator function based on new data and new locations generated internally. To use such a spatial covariate with a random effect: The shorthand |
Beta Was this translation helpful? Give feedback.
-
Hi everyone, I would like to define a nonlinear detection function based on the nonlinear effect of a covariate in a lGCP. This covariate is a spatial pixel data frame and is the time travelling to some health offices (i.e., each grid cell provides an estimation of the time needed to travel to the health offices). Here, the detectability of the point process will decay as a sigmoid shape in relation to the time travelling. I have started to define it a half normal function, however inlabru run results in an error: I have:
##vbr is a spatial points DF, samplers is a spatial polygon DF In the end, I would like to reproduce this simulated example but in the LGCP framework:
Thank you sessionInfo: Matrix products: default locale: attached base packages: other attached packages: |
Beta Was this translation helpful? Give feedback.
-
Hi, I have a related question and have not been able to figure out the right syntax. I currently have a model running fine, essentially specified as : with j a phenotype, a the age, and s the 2D spatial domain. All W and f are specified through SPDE. Following joint models for preferential sampling (e.g. #57), I'd like to add an LGCP component with this form: I am stuck at specifying I got from this post and another one from the R-INLA discussion group that I must provide a component like: psi(main = age(x, y), map = spdeage) with age(x, y) a function providing to inlabru the values for age at any point in space for each data point (so a function just returning the value for age from the dataset whatever the coordinates). I haven't been able to find the right syntax using sf object (https://inlabru-org.github.io/inlabru/articles/components_vignette.html only gives example for sp objects). Any help would be appreciated ! Best, |
Beta Was this translation helpful? Give feedback.
-
Thank you very much for your answer and example, which is indeed exactly my use case. Thanks also for the clarification about function of space vs property of the unit. The Note is also incredibly useful because I believe I encountered a computational issue yesterday, following the inclusion of a scaled copy in a model that already had a fairly large number of hyperparameters. Cheers, |
Beta Was this translation helpful? Give feedback.
For full control over component inputs, you can use the full function call (if
x
andy
are variable names in the input data, or the coordinate names):cmp = ~ cov(my_cov(x, y), model = "linear")
The function must be vectorised, so that it returns the results for each
x[i], y[i]
pair.This will cause inlabru to first evaluate the function call and store the result as a new internal variable. This is then used in the same way as if it had been part of the input data, so for regular models this doesn't really provide anything extra; you could just as well have created that variable before calling inlabru. But for LGCP models, this approach allows it to call your evaluator function based on n…