logisticregsimulate: Simulate from a logistic regression model

View source: R/regression.R

logisticregsimulateR Documentation

Simulate from a logistic regression model

Description

Simulates a dataset with n observation from the logistic regression model

Pr(y = 1 | x) = 1/(1 + exp(-(β_0 + β_1 * x_1 + ... + β_k * x_k)))

with covariates (x) simulated from a normal distribution with the same correlation rho_x
between all pairs of covariates. Covariate x_j has standard deviation sigma_x[j].
Alternatively the covariate can follow a uniform distribution.

Usage

logisticregsimulate(
  n,
  betavect,
  intercept = TRUE,
  covdist = "normal",
  rho_x = 0,
  sigma_x = rep(1, length(betavect) - intercept)
)

Arguments

n

the number of observations in the simulated dataset.

betavect

a vector with regression coefficients c(beta_0,beta_1,...beta_k). First element is intercept if intercept = TRUE

intercept

if TRUE an intercept is added to the model.

covdist

distribution of the covariates. Options: 'normal' or 'uniform'.

rho_x

correlation among the covariates. Same for all covariate pairs.

sigma_x

vector with standard deviation of the covariates.

Value

dataframe with simulated data (y, X1, X2, ..., XK) (no intercept included).

Examples

library(regkurs)
simdata <- logisticregsimulate(n = 500, betavect = c(1, -2, 1, 0))
glmfit <- glm(y ~ X1 + X2 + X3, data = simdata, family = binomial)
logisticregsummary(glmfit, odds_ratio = F)

StatisticsSU/regkurs documentation built on Jan. 29, 2023, 4:54 p.m.