logisticregsimulate | R Documentation |
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.
logisticregsimulate( n, betavect, intercept = TRUE, covdist = "normal", rho_x = 0, sigma_x = rep(1, length(betavect) - intercept) )
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 |
if |
covdist |
distribution of the covariates. Options: |
rho_x |
correlation among the covariates. Same for all covariate pairs. |
sigma_x |
vector with standard deviation of the covariates. |
dataframe with simulated data (y, X1, X2, ..., XK) (no intercept included).
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.