Closed vincentarelbundock closed 5 days ago
@ngreifer related to our discussion https://github.com/vincentarelbundock/marginaleffects/issues/1242
Do you see any downside of this approach?
Would also be nice to have native support for Kenward-Roger / Satterthwaite dfs for mixed models (Some nice code to get those in emmeans:::emm_basis.merMod()
) ;)
@mattansb K-R and S are already supported. See the vcov
argument in all functions and the documentation here: https://marginaleffects.com/r/man/predictions.html#arguments
Ohhhh I missed that!
Do you see any downside of this approach?
Downside: this gives df for glms (which don't really "need" them?)
mod <- glm(am ~ hp, binomial, mtcars)
insight::get_df(mod, type = "residual")
#> [1] 30
I agree with @mattansb that is this is too broad an approach because it gives GLMs a finite df, which would imply a t-test. I'm not expert on this but I think only linear models can be tested with t-statistics. In clarify
, I have the following function which is used to decide whether to use a t-distribution or z-distribution:
# Get the model degrees of freedom
## Assesses whether the model is linear and fit with OLS; if not,
## returns Inf. Linear models fit with MLE get Inf.
get_df <- function(fit) {
if (!insight::is_model_supported(fit)) {
return(Inf)
}
statistic <- insight::find_statistic(fit)
if (identical(statistic, "chi-squared statistic")) {
return(Inf)
}
insight::get_df(fit, type = "wald", statistic = statistic)
}
I don't remember where I found that code, but I think it does the job. Feel free to use it or something like it.
Yeah, that all makes. Thanks both form the input!
Noah's function could be a great default here as well IMO
Currently,
marginaleffects
reports $z$ statistics and computes $p$ values usingpnorm()
. Should we try to extract the residual degrees of freedom automatically and report $t$ statistics instead?We could do this by writing a
sanitize_df()
function and calling this the top of our main functions.This function would default to
NULL
in case of error, which reverts us to $z$.This was suggested by @mattansb