-
Notifications
You must be signed in to change notification settings - Fork 48
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
support for models from rstpm2 #1041
Comments
I gave this a shot but can't get the standard errors to work. I'm optimistic that this is possible, but don't have more time to invest at the moment. If anyone wants to give this a shot, the tutorial on extensions is here: https://marginaleffects.com/vignettes/extensions.html#support-a-new-model-type Below, I paste my initial attempts. I think that everything works, except that the output of options("marginaleffects_model_classes" = "stpm2")
#' @rdname set_coef
#' @export
set_coef.stpm2 <- function(model, coefs, ...) {
insight::check_if_installed("rstpm2")
model@coef <- coefs
model
}
#' @rdname get_vcov
#' @export
get_vcov.stpm2 <- function(model, ...) {
insight::check_if_installed("rstpm2")
rstpm2::vcov(model)
}
#' @rdname get_predict
#' @export
get_predict.stpm2 <- function(model, newdata = NULL, ...) {
insight::check_if_installed("rstpm2")
pred <- rstpm2::predict(model, newdata = newdata)
sanity_predict_vector(pred = pred, model = model, newdata = newdata)
sanity_predict_numeric(pred = pred, model = model, newdata = newdata)
out <- data.frame(
rowid = 1:nrow(newdata),
estimate = pred)
return(out)
} |
I am very interested in supporting this. But just to keep the repo clean, I close individual model request to consolidate them in a list here: #49 |
@aghaynes writes I'm not sure whether conversation on the rstpm2 implementation should be here or in the other issue... I guess here, as this is the open one? In stpm2 models, the coefficients seem to be stored in many places... Using the following at least produces the SEs etc in the predictions output... (i dont know which are important so i changed them all)
avg_predictions doesnt work though for some reason... if the missing variables were the spline terms, I might have kinda understood, but that hormon is missing confuses me... it seems to give the same error whether newdata is passed or not
to note: rstpm2 can predict a whole load of effect measures... so the type_dictionary would need updating to include some of them (i would be most interested in rmst and rmstdiff, but others are certainly also of interest) |
This is interesting, but I worry about substituting all those coef values. Ideally, we'd want a better understanding of the model object before starting to change things willy-nilly. Also, can this package use other than My guess is that |
Sure.. i just did it to see if it worked. most likely only one or two are actually relevant (perhaps reaching out to the author is worthwhile). I dont know the inner workings of the package unfortunately. I had a quick look through the helpfiles and dont see anything about using model types besides |
Another way would be to look at the code for the predict() method in the package to see what it uses. |
the next approx 700 lines starting here https://github.com/mclements/rstpm2/blob/79b05487a1f64e60cdc7235e7180ae07475b9038/R/pm2-3.R#L1635 |
lol |
to be fair, it's because there are so many things it can predict... there are multiple places where it uses |
@aghaynes thanks to the great work of @mclements this is now available in the Github version of Thanks again for the feature request. |
That is great news! Thanks to both of you!! |
Hey, great package!
Would it be possible to add support for models from the rstpm2 package? This allows things like RMST from flexible parametric survival models...
It would be great to be able to marginalise over e.g.
x3
...The text was updated successfully, but these errors were encountered: