Confidence intervals for flipscores
confint.flipscores.RdThis function allows to apply the confint method to flipscores objects.
Arguments
- object
a
flipscores) model object.- parm
a specification of which parameters are to be given confidence intervals, either a vector of numbers or a vector of names. If missing, they are recovered from the input model (
to_be_tested).- level
the confidence level required.
- type
the type of confidence interval to build, either "equitailed" or "symmetric". Default is "equitailed".
- score_type
The type of score that is computed. It can be "standardized" or "effective". Default is inherited by the input model.
- alternative
The direction of the test to invert, and corresponding interval with respect to the estimate. It can be "two.sided" (default), "greater", or "less".
- amp_const
Argument related to the maximum initial span of the search interval. See details.
- flips
the fixed flips to use in the interval search. If
NULL(default), it tries to inherit it from the input model.- n_flips
If
flipsare not given or retrieved by the model, the number of random flips of the score contributions. Default inherits them from the input model.- ...
additional arguments for methods.
Value
A matrix (or vector) with columns giving lower and upper confidence limits for each parameter. These will be labelled as (1-level)/2 and 1 - (1-level)/2 in
Details
All families allowed in glm, as well as Negative Binomial, are supported, and inherited here by the input model object. See the main function flipscores for further information.
flipscores is based on randomly sign-flipped score contributions. Performing the test (and generating the confidence interval) different times might give slightly different results. Providing a flip matrix generated with make_flips is suggested to uniform the results.
to_be_tested works differently for factors and character variables: the corresponding dummy variables are to be tested separately. So, to test a numeric variable X, one could write to_be_tested = "X", but to test a factor Z with levels A, B and C one should write to_be_tested = c("ZB", "ZC") as they appear in the model summary.
The bisection search is initialized in a predetermined interval. The maximum width of this interval is given by an amplitude (depending on the size of the estimated parameter and its standard error) multiplied by amp_const. The default for amp_const is 20. If the confidence bound is not found in the initial interval, Inf or -Inf is returned.
#' @seealso flipscores, make_flips
Examples
set.seed(1)
dt <- data.frame(X=scale(rnorm(50)),
Z=factor(rep(LETTERS[1:3],length.out=50)))
dt$Y=rpois(n=nrow(dt),lambda=exp(dt$X*(dt$Z=="C")))
mod0 <- flipscores(Y~Z+X,data=dt,family="poisson")
summary(mod0)
#>
#> Call:
#> flipscores(formula = Y ~ Z + X, family = "poisson", data = dt)
#>
#> Coefficients:
#> Estimate Score Std. Error z value Part. Cor Pr(>|z|)
#> (Intercept) -0.3513 -5.4234 4.2404 -1.2790 -0.169 0.1152
#> ZB 0.2276 1.8048 2.8140 0.6414 0.079 0.4412
#> ZC 0.9034 10.3392 3.4527 2.9945 0.348 0.0214 *
#> X 0.6381 33.1168 8.0470 4.1154 0.478 0.0096 **
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#>
#> (Dispersion parameter for poisson family taken to be 1)
#>
#> Null deviance: 82.225 on 49 degrees of freedom
#> Residual deviance: 52.798 on 46 degrees of freedom
#> AIC: 143.12
#>
#> Number of Fisher Scoring iterations: 5
#>
confint(mod0, parm="X")
#> 2.5 % 97.5 %
#> X 0.1795823 1.147919
xx <- rnorm(20)
zz <- rnorm(20, 0.2 * xx)
yy <- rnorm(20, 1 + 2 * xx - zz)
flps <- make_flips(20, 1000)
mod1 <- flipscores(yy ~ xx + zz)
summary(mod1)
#>
#> Call:
#> flipscores(formula = yy ~ xx + zz)
#>
#> Coefficients:
#> Estimate Score Std. Error z value Part. Cor Pr(>|z|)
#> (Intercept) 0.9816 17.7723 5.8115 3.0581 0.721 0.0024 **
#> xx 2.0616 23.9152 6.4938 3.6828 0.868 0.0002 ***
#> zz -1.0089 -15.8961 5.3065 -2.9956 -0.706 0.0234 *
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#>
#> (Dispersion parameter for gaussian family taken to be 0.9488933)
#>
#> Null deviance: 66.978 on 19 degrees of freedom
#> Residual deviance: 16.131 on 17 degrees of freedom
#> AIC: 60.458
#>
#> Number of Fisher Scoring iterations: 2
#>
confint(mod1, flips = flps)
#> Error in eval(parse(text = .form___)): object 'yy' not found