Formula interface and tidybayes support #18
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I implemented a front end function for
spatialGEV_fitthat is more R idiomatic. It accepts a multi-part formula like the ones in the Formula package, a square dataset, and refactors many arguments into a control and prior argument. I've also implemented a basic function to initialize the parameters. This uses the evd package since it was already imported. You can use it on thesimulatedDatadata set:You can call the
spatial_gevfunction like this:The formula can be a 3 part formula separated by
|where the parts correspond to location, scale, and shape models (y ~ location | scale | shape). Each of the subparts must be a lme4 style random effect term:(x1 + log(x2) | location_id)where the grouping factor corresponds to an identifier for the observed locations. Thus, the model I fit above corresponds to a random = "ab" with X_a and X_b design matrices with an intercept only. You could specify covariates likez ~ (x1 | id) | (x2 | id). In addition, I've supported the Formula package dot shorthand which means you could specify a random = "abs" model with the same regression terms like thisy ~ (x1 | id) | . | .and the formula will be expanded to accomodate the b and s terms.I also implemented a
posterior::as_draws_dfmethod which allows us to usespatialGEVsamobjects with the tidybayes package.I'm sure the code is somewhat brittle and could use some checks on the sanity of the data.frame that is passed. The control and prior implementations are pretty straightforward and are mostly to simplify the signature of the function and align with idiomatic R conventions. I generally tried to stick to the tidymodels recommendations: https://tidymodels.github.io/model-implementation-principles/function-interfaces.html.