### Install brglm2 development version from GitHub Source: https://github.com/ikosmidis/brglm2/blob/main/README.md Installs the development version of the brglm2 package directly from its GitHub repository. ```r # install.packages("remotes") remotes::install_github("ikosmidis/brglm2", ref = "develop") ``` -------------------------------- ### Install brglm2 from CRAN Source: https://github.com/ikosmidis/brglm2/blob/main/README.md Installs the current stable version of the brglm2 package from the Comprehensive R Archive Network (CRAN). ```r install.packages("brglm2") ``` -------------------------------- ### Estimating odds ratios using the correction* method Source: https://github.com/ikosmidis/brglm2/blob/main/README.md Example of how to estimate odds ratios using the 'correction*' method for mean bias reduction with a logistic regression model fit. ```R expoRB <- expo(modML, type = "correction*") expoRB ``` -------------------------------- ### MDYPL estimation and high-dimensionality corrections Source: https://github.com/ikosmidis/brglm2/blob/main/README.md Example of fitting models using maximum Diaconis-Ylvisaker prior penalized likelihood (MDYPL) and performing a penalized likelihood ratio test. ```R full_m <- update(full_sep, method = mdypl_fit) nest_m <- update(nest_sep, method = mdypl_fit, alpha = full_m$alpha) plrtest(nest_m, full_m) ``` -------------------------------- ### High-dimensionality correction to the penalized likelihood ratio statistic Source: https://github.com/ikosmidis/brglm2/blob/main/README.md Example of applying a high-dimensionality correction to the penalized likelihood ratio test. ```R plrtest(nest_m, full_m, hd_correction = TRUE) ``` -------------------------------- ### Detecting Separation with detectseparation package Source: https://github.com/ikosmidis/brglm2/blob/main/README.md Uses the detectseparation R package to verify if the ML estimate for a parameter is infinite due to data separation. ```R # install.packages("detectseparation") library("detectseparation") update(modML, method = detect_separation) ``` -------------------------------- ### Loading and visualizing the MultipleFeatures dataset Source: https://github.com/ikosmidis/brglm2/blob/main/README.md Loads the MultipleFeatures dataset and visualizes the digits using pixel averages. ```r data("MultipleFeatures", package = "brglm2") par(mfrow = c(10, 20), mar = numeric(4) + 0.1) for (c_digit in 0:9) { df <- subset(MultipleFeatures, digit == c_digit) df <- as.matrix(df[, paste("pix", 1:240, sep = ".")]) for (inst in 1:20) { m <- matrix(df[inst, ], 15, 16)[, 16:1] image(m, col = grey.colors(7, 1, 0), xaxt = "n", yaxt = "n") } } ``` -------------------------------- ### Data preparation and model fitting for separation analysis Source: https://github.com/ikosmidis/brglm2/blob/main/README.md Centers features, sets up module formulas, and fits models using maximum likelihood with a custom method to detect separation. ```r ## Center the fou.* and kar.* features vars <- grep("fou|kar", names(MultipleFeatures), value = TRUE) train_id <- which(MultipleFeatures$training) MultipleFeatures[train_id, vars] <- scale(MultipleFeatures[train_id, vars], scale = FALSE) ## Set up module formulas full_fm <- formula(paste("I(digit == 7) ~", paste(vars, collapse = " + "))) nest_vars <- grep("fou", vars, value = TRUE) nest_fm <- formula(paste("I(digit == 7) ~", paste(nest_vars, collapse = " + "))) ## Fit the models using maximum likelihood full_sep <- glm(full_fm, data = MultipleFeatures, family = binomial(), subset = training, method = detect_separation) nest_sep <- update(full_sep, nest_fm) full_sep$outcome #> [1] TRUE nest_sep$outcome #> [1] TRUE ``` -------------------------------- ### MDYPL estimation and high-dimensionality corrections Source: https://github.com/ikosmidis/brglm2/blob/main/README.md R code demonstrating MDYPL estimation and high-dimensionality corrections, including model formulas and summary output. ```R fou.28 + fou.29 + fou.30 + fou.31 + fou.32 + fou.33 + fou.34 + fou.35 + fou.36 + fou.37 + fou.38 + fou.39 + fou.40 + fou.41 + fou.42 + fou.43 + fou.44 + fou.45 + fou.46 + fou.47 + fou.48 + fou.49 + fou.50 + fou.51 + fou.52 + fou.53 + fou.54 + fou.55 + fou.56 + fou.57 + fou.58 + fou.59 + fou.60 + fou.61 + fou.62 + fou.63 + fou.64 + fou.65 + fou.66 + fou.67 + fou.68 + fou.69 + fou.70 + fou.71 + fou.72 + fou.73 + fou.74 + fou.75 + fou.76 Model 2: I(digit == 7) ~ fou.1 + fou.2 + fou.3 + fou.4 + fou.5 + fou.6 + fou.7 + fou.8 + fou.9 + fou.10 + fou.11 + fou.12 + fou.13 + fou.14 + fou.15 + fou.16 + fou.17 + fou.18 + fou.19 + fou.20 + fou.21 + fou.22 + fou.23 + fou.24 + fou.25 + fou.26 + fou.27 + fou.28 + fou.29 + fou.30 + fou.31 + fou.32 + fou.33 + fou.34 + fou.35 + fou.36 + fou.37 + fou.38 + fou.39 + fou.40 + fou.41 + fou.42 + fou.43 + fou.44 + fou.45 + fou.46 + fou.47 + fou.48 + fou.49 + fou.50 + fou.51 + fou.52 + fou.53 + fou.54 + fou.55 + fou.56 + fou.57 + fou.58 + fou.59 + fou.60 + fou.61 + fou.62 + fou.63 + fou.64 + fou.65 + fou.66 + fou.67 + fou.68 + fou.69 + fou.70 + fou.71 + fou.72 + fou.73 + fou.74 + fou.75 + fou.76 + kar.1 + kar.2 + kar.3 + kar.4 + kar.5 + kar.6 + kar.7 + kar.8 + kar.9 + kar.10 + kar.11 + kar.12 + kar.13 + kar.14 + kar.15 + kar.16 + kar.17 + kar.18 + kar.19 + kar.20 + kar.21 + kar.22 + kar.23 + kar.24 + kar.25 + kar.26 + kar.27 + kar.28 + kar.29 + kar.30 + kar.31 + kar.32 + kar.33 + kar.34 + kar.35 + kar.36 + kar.37 + kar.38 + kar.39 + kar.40 + kar.41 + kar.42 + kar.43 + kar.44 + kar.45 + kar.46 + kar.47 + kar.48 + kar.49 + kar.50 + kar.51 + kar.52 + kar.53 + kar.54 + kar.55 + kar.56 + kar.57 + kar.58 + kar.59 + kar.60 + kar.61 + kar.62 + kar.63 + kar.64 Resid. Df Resid. Dev Df Deviance Pr(>Chi) 1 923 97.305 2 859 32.945 64 173.34 5.095e-12 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 High-dimensionality correction applied with Dimentionality parameter (kappa) = 0.14 Estimated signal strength (gamma) = 11.58 State evolution parameters (mu, b, sigma) = (0.4, 1.84, 2.21) with max(|funcs|) = 6.300466e-09 ``` ```R summ_full_m <- summary(full_m, hd_correction = TRUE) ``` ```R rescaled_coefs <- coef(summ_full_m)[-1, ] acols <- hcl.colors(3, alpha = 0.2) cols <- hcl.colors(3) plot(coef(full_m)[-1], rescaled_coefs[, "Estimate"], xlim = c(-9, 9), ylim = c(-9, 9), xlab = "MDYPL estimates", ylab = "rescaled MDYPL estimates", pch = 21, bg = acols[grepl("kar", rownames(rescaled_coefs)) + 1], col = NULL) legend(-9, 9, legend = c("fou", "kar"), pt.bg = cols[1:2], col = NA, pch = 21, title = "Features") legend(-5.4, 9, legend = expression(1, 1/hat(mu)), lty = c(2, 1), col = "grey", title = "Slope") abline(0, 1, col = "grey", lty = 2) abline(0, 1/summ_full_m$se_parameters[1], col = "grey") ``` -------------------------------- ### Bias-Reduction Estimation Source: https://github.com/ikosmidis/brglm2/blob/main/README.md Refits the model using mean bias reduction to obtain finite estimates and standard errors, improving frequentist properties compared to ML. ```R summary(update(modML, method = "brglm_fit")) ``` -------------------------------- ### Maximum Likelihood (ML) Estimation Source: https://github.com/ikosmidis/brglm2/blob/main/README.md Fits a logistic regression model using maximum likelihood (ML) to analyze data from a study on endometrial cancer. ```R library("brglm2") data("endometrial", package = "brglm2") modML <- glm(HG ~ NV + PI + EH, family = binomial("logit"), data = endometrial) summary(modML) ``` -------------------------------- ### Analysis of Deviance for nested models Source: https://github.com/ikosmidis/brglm2/blob/main/README.md Performs an Analysis of Deviance test to compare two nested models, highlighting potential convergence warnings. ```r anova(update(nest_sep, method = glm.fit), update(full_sep, method = glm.fit)) #> 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 #> Analysis of Deviance Table #> #> Model 1: I(digit == 7) ~ fou.1 + fou.2 + fou.3 + fou.4 + fou.5 + fou.6 + #> fou.7 + fou.8 + fou.9 + fou.10 + fou.11 + fou.12 + fou.13 + #> fou.14 + fou.15 + fou.16 + fou.17 + fou.18 + fou.19 + fou.20 + #> fou.21 + fou.22 + fou.23 + fou.24 + fou.25 + fou.26 + fou.27 + #> fou.28 + fou.29 + fou.30 + fou.31 + fou.32 + fou.33 + fou.34 + #> fou.35 + fou.36 + fou.37 + fou.38 + fou.39 + fou.40 + fou.41 + #> fou.42 + fou.43 + fou.44 + fou.45 + fou.46 + fou.47 + fou.48 + #> fou.49 + fou.50 + fou.51 + fou.52 + fou.53 + fou.54 + fou.55 + #> fou.56 + fou.57 + fou.58 + fou.59 + fou.60 + fou.61 + fou.62 + #> fou.63 + fou.64 + fou.65 + fou.66 + fou.67 + fou.68 + fou.69 + #> fou.70 + fou.71 + fou.72 + fou.73 + fou.74 + fou.75 + fou.76 #> Model 2: I(digit == 7) ~ fou.1 + fou.2 + fou.3 + fou.4 + fou.5 + fou.6 + #> fou.7 + fou.8 + fou.9 + fou.10 + fou.11 + fou.12 + fou.13 + #> fou.14 + fou.15 + fou.16 + fou.17 + fou.18 + fou.19 + fou.20 + #> fou.21 + fou.22 + fou.23 + fou.24 + fou.25 + fou.26 + fou.27 + #> fou.28 + fou.29 + fou.30 + fou.31 + fou.32 + fou.33 + fou.34 + #> fou.35 + fou.36 + fou.37 + fou.38 + fou.39 + fou.40 + fou.41 + #> fou.42 + fou.43 + fou.44 + fou.45 + fou.46 + fou.47 + fou.48 + #> fou.49 + fou.50 + fou.51 + fou.52 + fou.53 + fou.54 + fou.55 + #> fou.56 + fou.57 + fou.58 + fou.59 + fou.60 + fou.61 + fou.62 + #> fou.63 + fou.64 + fou.65 + fou.66 + fou.67 + fou.68 + fou.69 + #> fou.70 + fou.71 + fou.72 + fou.73 + fou.74 + fou.75 + fou.76 + ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.