fitstat_register | R Documentation |
Enables the registration of custom fi statistics that can be easily summoned with the function fitstat
.
fitstat_register(type, fun, alias = NULL, subtypes = NULL)
type |
A character scalar giving the type-name. |
fun |
A function to be applied to a |
alias |
A (named) character vector. An alias to be used in lieu of the type name in
the display methods (ie when used in |
subtypes |
A character vector giving the name of each element returned by the
function |
If there are several components to the computed statistics (i.e. the function returns
several elements), then using the argument subtypes
, giving the names of each of
these components, is mandatory. This is to ensure that the statistic can be used as any
other built-in statistic (and there are too many edge cases impeding automatic deduction).
Laurent Berge
# An estimation
base = iris
names(base) = c("y", "x1", "x2", "x3", "species")
est = feols(y ~ x1 + x2 | species, base)
#
# single valued tests
#
# say you want to add the coefficient of variation of the dependent variable
cv = function(est){
y = model.matrix(est, type = "lhs")
sd(y)/mean(y)
}
# Now we register the routine
fitstat_register("cvy", cv, "Coef. of Variation (dep. var.)")
# now we can summon the registered routine with its type ("cvy")
fitstat(est, "cvy")
#
# Multi valued tests
#
# Let's say you want a Wald test with an heteroskedasticiy robust variance
# First we create the function
hc_wald = function(est){
w = wald(est, keep = "!Intercept", print = FALSE, se = "hetero")
head(w, 4)
}
# This test returns a vector of 4 elements: stat, p, df1 and df2
# Now we register the routine
fitstat_register("hc_wald", hc_wald, "Wald (HC1)", "test2")
# You can access the statistic, as before
fitstat(est, "hc_wald")
# But you can also access the sub elements
fitstat(est, "hc_wald.p")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.