flipscores: Robust testing in GLMs, by sign-flipping score contributions

View source: R/flipscores.R

flipscoresR Documentation

Robust testing in GLMs, by sign-flipping score contributions

Description

Provides robust tests for testing in GLMs, by sign-flipping score contributions. The tests are often robust against overdispersion, heteroscedasticity and, in some cases, ignored nuisance variables.

Usage

flipscores(formula, family, data, score_type, 
n_flips=5000, alternative ="two.sided", 
id = NULL, seed = NULL, ...)

Arguments

formula

see glm function. It can also be a model (usually generated by a call to glm); in this case, any other glm-related parameter (e.g. family, data, etc.) are discarded, the function will make use of the ones used to generate the model.

family

see glm function.

data

see glm function.

score_type

The type of score that is computed. It can be "orthogonalized", "effective" or "basic". Both "orthogonalized" and "effective" take into account the nuisance estimation and they provide the same test statistic. In case of small samples "effective score" might have a slight anti-conservative behaviour. "orthogonalized effective score" gives a solution for this issue. Note that in case of a big model matrix, the "orthogonalized" may take a long time.

n_flips

The number of random flips of the score contributions. When n_flips is equal or larger than the maximum number of possible flips (i.e. n^2), all possible flips are performed.

alternative

It can be "greater", "less" or "two.sided" (default)

id

a vector identifying the clustered observations. If NULL (default) observations are assumed to be independent. If id is not NULL, only score_type=="effective" is allowed, yet.

seed

NULL by default.

...

see glm function.

Details

flipscores borrow the same parameters from function glm (and glm.nb). See these helps for more details about parameters such as formula, data, family. Note: in order to use Negative Binomial family, family reference must have quotes (i.e. family="negbinom").

Value

glm class object with sign-flip score test. See also the related functions (summary.flipscores, anova.flipscores, print.flipscores).

Author(s)

Livio Finos, Riccardo De Santis, Vittorio Giatti, Jesse Hemerik and Jelle Goeman

References

"Robust testing in generalized linear models by sign-flipping score contributions" by J.Hemerik, J.Goeman and L.Finos.

See Also

anova.flipscores, summary.flipscores, flip

Examples

set.seed(1)
dt=data.frame(X=rnorm(20),
   Z=factor(rep(LETTERS[1:3],length.out=20)))
dt$Y=rpois(n=20,lambda=exp(dt$Z=="C"))
mod=flipscores(Y~Z+X,data=dt,family="poisson")
summary(mod)

# Equivalent to:
model=glm(Y~Z+X,data=dt,family="poisson")
mod2=flipscores(model)
summary(mod2)

flipscores documentation built on Aug. 15, 2022, 5:09 p.m.