Permutation test for binomial logistic regression
Source:R/grouped_perm_binoglm.R
grouped_perm_binoglm.Rdgrouped_perm_binoglm is a nonparametric test for binomial
logistic regression. It assesses the significance of coefficients by
permutation, computing the null distribution of the z-statistic by
randomly rearranging the binary outcome variable.
Arguments
- tbl
A data frame or tibble containing all model variables.
- formla
A formula describing the logistic regression model; passed to
stats::glm()withfamily = binomial.- var_to_perm
Character. Name of the binary outcome column to permute.
- permNum
Integer. Number of permutations to generate. Default
1000.- seed
Integer. Random seed for reproducibility; passed to
base::set.seed(). Default42.
Value
A tibble with one row per model term and columns:
termName of the regression term.
estimateEstimated log-odds coefficient.
statisticObserved z-statistic.
p.valueAsymptotic two-sided p-value from the fitted model.
p.permPermutation p-value: proportion of permuted |statistics| >= |observed statistic|. A value of
0means no permuted statistic was as extreme; report asp < 1/permNum.
Examples
counts <- c(10, 11, 8, 9, 6, 3, 5, 1)
gender <- c(0, 0, 0, 0, 0, 1, 1, 1)
TBL <- data.frame(counts, gender)
grouped_perm_binoglm(TBL, gender ~ counts, "gender", permNum = 500, seed = 1)
#> Warning: glm.fit: algorithm did not converge
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> Warning: glm.fit: algorithm did not converge
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> Warning: glm.fit: algorithm did not converge
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> Warning: glm.fit: algorithm did not converge
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> Warning: glm.fit: algorithm did not converge
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> Warning: glm.fit: algorithm did not converge
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> Warning: glm.fit: algorithm did not converge
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> Warning: glm.fit: algorithm did not converge
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> Warning: glm.fit: algorithm did not converge
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> Warning: glm.fit: algorithm did not converge
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> Warning: glm.fit: algorithm did not converge
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> Warning: glm.fit: algorithm did not converge
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> Warning: glm.fit: algorithm did not converge
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> Warning: glm.fit: algorithm did not converge
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> Warning: glm.fit: algorithm did not converge
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> # A tibble: 2 × 5
#> term estimate statistic p.value p.perm
#> <chr> <dbl> <dbl> <dbl> <dbl>
#> 1 (Intercept) 246. 0.000723 0.999 1
#> 2 counts -44.7 -0.000728 0.999 1