### Enable Interactive Mode Source: https://context7.com/cran/regplot/llms.txt Basic setup for enabling interactive nomogram exploration. ```r library(regplot) model <- lm(mpg ~ wt + hp + cyl, data = mtcars) ``` -------------------------------- ### Create Regression Nomograms Source: https://context7.com/cran/regplot/llms.txt Examples of generating nomograms for linear, Cox survival, and logistic regression models. ```r library(regplot) library(survival) # Example 1: Linear Model Nomogram n <- 500 X <- cbind(rnorm(n, sd = 1), rnorm(n, sd = 0.5)) Y <- 10 + X %*% c(0.2, 0.1) + rnorm(n, sd = 1) D <- as.data.frame(cbind(Y, X)) colnames(D) <- c("Y", "x1", "x2") model <- lm(Y ~ x1 + x2, data = D) # Basic nomogram with confidence interval for first observation regplot(model, observation = D[1,], interval = "confidence") # Example 2: Cox Survival Model Nomogram data(pbc) pbccox <- coxph( formula = Surv(time, status == 2) ~ age + cut(bili, breaks = c(-Inf, 2, 4, Inf)) + sex + copper + as.factor(stage), data = pbc ) # Interactive nomogram with points scale and multiple failure times regplot( pbccox, observation = pbc[1,], clickable = TRUE, # Enable mouse interaction points = TRUE, # Use 0-100 points scale rank = "sd", # Order variables by importance failtime = c(730, 1825) # Survival probability at 2 and 5 years ) # Example 3: Logistic Regression Nomogram data(mtcars) logit_model <- glm(am ~ mpg + hp + wt, data = mtcars, family = binomial) regplot( logit_model, observation = mtcars[1,], plots = c("density", "boxes"), # Density for numeric, boxes for factors center = TRUE, # Align at mean values showP = TRUE, # Show p-value asterisks subticks = TRUE # Add minor tick marks ) ``` -------------------------------- ### Configure Survival Model Features Source: https://context7.com/cran/regplot/llms.txt Advanced configuration for survival analysis, including failure probabilities and survival quantiles. ```r library(regplot) library(survival) data(pbc) # Cox model with strata cox_model <- coxph( Surv(time, status == 2) ~ age + sex + strata(edema) + bili + albumin, data = pbc, x = TRUE, y = TRUE # Required for rms models ) # Probability of survival at specific times regplot( cox_model, observation = pbc[1,], failtime = c(365, 730, 1825), # 1, 2, and 5 years prfail = FALSE # Show survival (not failure) probability ) # Show failure probability instead regplot( cox_model, observation = pbc[1,], failtime = c(1825), prfail = TRUE # Probability of death before failtime ) # Survival quantiles (median survival time) regplot( cox_model, observation = pbc[1,], failtime = c("50%", "25%") # Median and 25th percentile survival ) # Parametric survival (Weibull) survreg_model <- survreg( Surv(time, status == 2) ~ age + sex + bili, data = pbc, dist = "weibull" ) regplot( survreg_model, observation = pbc[1,], failtime = 1825, prfail = TRUE ) ``` -------------------------------- ### Configure Distribution Plot Types Source: https://context7.com/cran/regplot/llms.txt Demonstrates various visualization styles for covariate distributions using the plots parameter. ```r library(regplot) # Create sample model model <- lm(mpg ~ wt + hp + cyl, data = mtcars) # Different distribution visualizations # Density plots for continuous, boxes for factors (default) regplot(model, plots = c("density", "boxes")) # Spikes showing frequency regplot(model, plots = c("spikes", "spikes")) # Violin plots for continuous variables regplot(model, plots = c("violin", "boxes")) # Bean plots (requires beanplot package) regplot(model, plots = c("bean", "boxes")) # Boxplots for continuous variables regplot(model, plots = c("boxplot", "boxes")) # Empirical CDF regplot(model, plots = c("ecdf", "boxes")) # Bar histogram regplot(model, plots = c("bars", "bars")) # No distribution plots (just scales) regplot(model, plots = c("no plot", "no plot")) ``` -------------------------------- ### Display Confidence Intervals Source: https://context7.com/cran/regplot/llms.txt Use the `interval` argument to display uncertainty bounds on predictions. Options include 'confidence' for the mean prediction and 'prediction' for new observations. ```r library(regplot) # Linear model with intervals model <- lm(mpg ~ wt + hp, data = mtcars) # Confidence interval on mean prediction regplot( model, observation = mtcars[1,], interval = "confidence" # 95% CI for E[Y|X] ) ``` ```r # Prediction interval for new observation regplot( model, observation = mtcars[1,], interval = "prediction" # 95% PI for Y_new ) ``` ```r # Confidence intervals on coefficient contributions regplot( model, observation = mtcars[1,], interval = "coefficients" # Shows CI on beta*X for each variable ) ``` ```r # Logistic model confidence interval logit_model <- glm(am ~ mpg + hp + wt, data = mtcars, family = binomial) regplot( logit_model, observation = mtcars[1,], interval = "confidence" # CI on probability scale ) ``` -------------------------------- ### Enable Interactive Mode in Regplot Source: https://context7.com/cran/regplot/llms.txt Use `clickable = TRUE` to enable mouse interaction with the nomogram. Press ESC to exit interactive mode. ```r regplot( model, observation = mtcars[1,], clickable = TRUE # Enables mouse interaction ) ``` -------------------------------- ### Customize Regplot Appearance Source: https://context7.com/cran/regplot/llms.txt Customize colors, fonts, and layout using parameters like `dencol`, `boxcol`, `obscol`, `spkcol`, `cexscales`, `cexvars`, `cexcats`, `droplines`, and `leftlabel`. ```r regplot( model, observation = mtcars[1,], clickable = TRUE, dencol = "#CCCCFF", # Density fill color boxcol = "#FFCCCC", # Factor box color obscol = "#FF0000", # Observation highlight color spkcol = "#0000FF", # Spike color cexscales = 0.9, # Scale font size cexvars = 1.0, # Variable name font size cexcats = 0.8, # Category label font size droplines = TRUE, # Show vertical droplines leftlabel = TRUE # Labels on left side ) ``` -------------------------------- ### Visualize Mixed Effects Models Source: https://context7.com/cran/regplot/llms.txt Regplot supports `lmer` and `glmer` models from the `lme4` package, displaying both fixed and random effects. For `glmer`, specify plots using `plots = c("density", "boxes")`. ```r library(regplot) library(lme4) # Linear mixed model data(sleepstudy) lmer_model <- lmer(Reaction ~ Days + (1|Subject), data = sleepstudy) regplot( lmer_model, observation = sleepstudy[1,], clickable = TRUE ) # Note: An additional random effects scale is shown at top ``` ```r # Generalized linear mixed model data(cbpp) glmer_model <- glmer( cbind(incidence, size - incidence) ~ period + (1|herd), data = cbpp, family = binomial ) regplot( glmer_model, observation = cbpp[1,], plots = c("density", "boxes") ) # Shows fixed effects nomogram with random effect contribution ``` -------------------------------- ### Generate Points Scale Tables Source: https://context7.com/cran/regplot/llms.txt Set `points = TRUE` to convert a nomogram into a points-based scoring system. The function returns a list of dataframes for covariate points and total points to probability mapping. ```r library(regplot) model <- glm(am ~ mpg + hp + wt, data = mtcars, family = binomial) # Use points scale (0-100) instead of raw beta*X points_table <- regplot( model, observation = mtcars[1,], points = TRUE # Returns points lookup tables ) # points_table is a list of dataframes: # - One dataframe per covariate showing variable values and points # - Final dataframe shows total points to probability mapping # Access the scoring tables print(points_table) # Each element contains: # - Variable name column with values # - Points column with corresponding score (0-100) # Example output structure: # [[1]] mpg Points # 15 45 # 20 52 # 25 60 # ... # [[n]] Total Points Pr(am) # 100 0.05 # 200 0.25 # 300 0.75 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.