Logistic regression

logistic(
  dataset,
  rvar,
  evar,
  lev = "",
  int = "",
  wts = "None",
  check = "",
  form,
  ci_type,
  data_filter = "",
  envir = parent.frame()
)

Arguments

dataset

Dataset

rvar

The response variable in the model

evar

Explanatory variables in the model

lev

The level in the response variable defined as _success_

int

Interaction term to include in the model

wts

Weights to use in estimation

check

Use "standardize" to see standardized coefficient estimates. Use "stepwise-backward" (or "stepwise-forward", or "stepwise-both") to apply step-wise selection of variables in estimation. Add "robust" for robust estimation of standard errors (HC1)

form

Optional formula to use instead of rvar, evar, and int

ci_type

To use the profile-likelihood (rather than Wald) for confidence intervals use "profile". For datasets with more than 5,000 rows the Wald method will be used, unless "profile" is explicitly set

data_filter

Expression entered in, e.g., Data > View to filter the dataset in Radiant. The expression should be a string (e.g., "price > 10000")

envir

Environment to extract data from

Value

A list with all variables defined in logistic as an object of class logistic

Details

See https://radiant-rstats.github.io/docs/model/logistic.html for an example in Radiant

See also

summary.logistic to summarize the results

plot.logistic to plot the results

predict.logistic to generate predictions

plot.model.predict to plot prediction output

Examples

logistic(titanic, "survived", c("pclass", "sex"), lev = "Yes") %>% summary()
#> Logistic regression (GLM) #> Data : titanic #> Response variable : survived #> Level : Yes in survived #> Explanatory variables: pclass, sex #> Null hyp.: there is no effect of x on survived #> Alt. hyp.: there is an effect of x on survived #> #> OR OR% coefficient std.error z.value p.value #> (Intercept) 2.151 0.188 11.420 < .001 *** #> pclass|2nd 0.409 -59.1% -0.893 0.208 -4.290 < .001 *** #> pclass|3rd 0.181 -81.9% -1.712 0.191 -8.953 < .001 *** #> sex|male 0.080 -92.0% -2.522 0.163 -15.447 < .001 *** #> #> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 #> #> Pseudo R-squared: 0.281 #> Log-likelihood: -506.562, AIC: 1021.124, BIC: 1040.924 #> Chi-squared: 396.861 df(3), p.value < .001 #> Nr obs: 1,043 #>
logistic(titanic, "survived", c("pclass", "sex")) %>% str()
#> List of 16 #> $ coeff :'data.frame': 4 obs. of 8 variables: #> ..$ label : chr [1:4] "(Intercept)" "pclass|2nd" "pclass|3rd" "sex|male" #> ..$ OR : num [1:4] 8.5966 0.4093 0.1806 0.0803 #> ..$ OR% : num [1:4] 7.597 -0.591 -0.819 -0.92 #> ..$ coefficient: num [1:4] 2.151 -0.893 -1.712 -2.522 #> ..$ std.error : num [1:4] 0.188 0.208 0.191 0.163 #> ..$ z.value : num [1:4] 11.42 -4.29 -8.95 -15.45 #> ..$ p.value : num [1:4] 0.000000000000000000000000000003312134962983916736635286 0.000017893695745503967250034788039059208131220657378435| __truncated__ #> ..$ sig_star : chr [1:4] "***" "***" "***" "***" #> $ model :List of 30 #> ..$ coefficients : Named num [1:4] 2.151 -0.893 -1.712 -2.522 #> .. ..- attr(*, "names")= chr [1:4] "(Intercept)" "pclass2nd" "pclass3rd" "sexmale" #> ..$ residuals : Named num [1:1043] 1.12 2.45 -9.6 -1.69 -9.6 ... #> .. ..- attr(*, "names")= chr [1:1043] "1" "2" "3" "4" ... #> ..$ fitted.values : Named num [1:1043] 0.896 0.408 0.896 0.408 0.896 ... #> .. ..- attr(*, "names")= chr [1:1043] "1" "2" "3" "4" ... #> ..$ effects : Named num [1:1043] 4.269 0.522 -5.63 15.447 -2.89 ... #> .. ..- attr(*, "names")= chr [1:1043] "(Intercept)" "pclass2nd" "pclass3rd" "sexmale" ... #> ..$ R : num [1:4, 1:4] -12.8 0 0 0 -3.5 ... #> .. ..- attr(*, "dimnames")=List of 2 #> .. .. ..$ : chr [1:4] "(Intercept)" "pclass2nd" "pclass3rd" "sexmale" #> .. .. ..$ : chr [1:4] "(Intercept)" "pclass2nd" "pclass3rd" "sexmale" #> ..$ rank : int 4 #> ..$ qr :List of 5 #> .. ..$ qr : num [1:1043, 1:4] -12.81 0.0384 0.0239 0.0384 0.0239 ... #> .. .. ..- attr(*, "dimnames")=List of 2 #> .. .. .. ..$ : chr [1:1043] "1" "2" "3" "4" ... #> .. .. .. ..$ : chr [1:4] "(Intercept)" "pclass2nd" "pclass3rd" "sexmale" #> .. ..$ rank : int 4 #> .. ..$ qraux: num [1:4] 1.02 1.02 1.03 1.02 #> .. ..$ pivot: int [1:4] 1 2 3 4 #> .. ..$ tol : num 0.00000000001 #> .. ..- attr(*, "class")= chr "qr" #> ..$ family :List of 12 #> .. ..$ family : chr "binomial" #> .. ..$ link : chr "logit" #> .. ..$ linkfun :function (mu) #> .. ..$ linkinv :function (eta) #> .. ..$ variance :function (mu) #> .. ..$ dev.resids:function (y, mu, wt) #> .. ..$ aic :function (y, n, mu, wt, dev) #> .. ..$ mu.eta :function (eta) #> .. ..$ initialize: language { if (NCOL(y) == 1) { ... #> .. ..$ validmu :function (mu) #> .. ..$ valideta :function (eta) #> .. ..$ simulate :function (object, nsim) #> .. ..- attr(*, "class")= chr "family" #> ..$ linear.predictors: Named num [1:1043] 2.151 -0.371 2.151 -0.371 2.151 ... #> .. ..- attr(*, "names")= chr [1:1043] "1" "2" "3" "4" ... #> ..$ deviance : num 1013 #> ..$ aic : num 1021 #> ..$ null.deviance : num 1410 #> ..$ iter : int 4 #> ..$ weights : Named num [1:1043] 0.0933 0.2416 0.0933 0.2416 0.0933 ... #> .. ..- attr(*, "names")= chr [1:1043] "1" "2" "3" "4" ... #> ..$ prior.weights : Named num [1:1043] 1 1 1 1 1 1 1 1 1 1 ... #> .. ..- attr(*, "names")= chr [1:1043] "1" "2" "3" "4" ... #> ..$ df.residual : int 1039 #> ..$ df.null : int 1042 #> ..$ y : Named num [1:1043] 1 1 0 0 0 1 1 0 1 0 ... #> .. ..- attr(*, "names")= chr [1:1043] "1" "2" "3" "4" ... #> ..$ converged : logi TRUE #> ..$ boundary : logi FALSE #> ..$ model :'data.frame': 1043 obs. of 3 variables: #> .. ..$ survived: logi [1:1043] TRUE TRUE FALSE FALSE FALSE TRUE ... #> .. ..$ pclass : Factor w/ 3 levels "1st","2nd","3rd": 1 1 1 1 1 1 1 1 1 1 ... #> .. ..$ sex : Factor w/ 2 levels "female","male": 1 2 1 2 1 2 1 2 1 2 ... #> .. ..- attr(*, "terms")=Classes 'terms', 'formula' language survived ~ pclass + sex #> .. .. .. ..- attr(*, "variables")= language list(survived, pclass, sex) #> .. .. .. ..- attr(*, "factors")= int [1:3, 1:2] 0 1 0 0 0 1 #> .. .. .. .. ..- attr(*, "dimnames")=List of 2 #> .. .. .. .. .. ..$ : chr [1:3] "survived" "pclass" "sex" #> .. .. .. .. .. ..$ : chr [1:2] "pclass" "sex" #> .. .. .. ..- attr(*, "term.labels")= chr [1:2] "pclass" "sex" #> .. .. .. ..- attr(*, "order")= int [1:2] 1 1 #> .. .. .. ..- attr(*, "intercept")= int 1 #> .. .. .. ..- attr(*, "response")= int 1 #> .. .. .. ..- attr(*, ".Environment")=<environment: 0x13282680> #> .. .. .. ..- attr(*, "predvars")= language list(survived, pclass, sex) #> .. .. .. ..- attr(*, "dataClasses")= Named chr [1:3] "logical" "factor" "factor" #> .. .. .. .. ..- attr(*, "names")= chr [1:3] "survived" "pclass" "sex" #> ..$ call : language glm(formula = form_upper, family = binomial(link = "logit"), data = dataset, weights = wts) #> ..$ formula :Class 'formula' language survived ~ pclass + sex #> .. .. ..- attr(*, ".Environment")=<environment: 0x13282680> #> ..$ terms :Classes 'terms', 'formula' language survived ~ pclass + sex #> .. .. ..- attr(*, "variables")= language list(survived, pclass, sex) #> .. .. ..- attr(*, "factors")= int [1:3, 1:2] 0 1 0 0 0 1 #> .. .. .. ..- attr(*, "dimnames")=List of 2 #> .. .. .. .. ..$ : chr [1:3] "survived" "pclass" "sex" #> .. .. .. .. ..$ : chr [1:2] "pclass" "sex" #> .. .. ..- attr(*, "term.labels")= chr [1:2] "pclass" "sex" #> .. .. ..- attr(*, "order")= int [1:2] 1 1 #> .. .. ..- attr(*, "intercept")= int 1 #> .. .. ..- attr(*, "response")= int 1 #> .. .. ..- attr(*, ".Environment")=<environment: 0x13282680> #> .. .. ..- attr(*, "predvars")= language list(survived, pclass, sex) #> .. .. ..- attr(*, "dataClasses")= Named chr [1:3] "logical" "factor" "factor" #> .. .. .. ..- attr(*, "names")= chr [1:3] "survived" "pclass" "sex" #> ..$ data : tibble [1,043 × 3] (S3: tbl_df/tbl/data.frame) #> .. ..$ survived: logi [1:1043] TRUE TRUE FALSE FALSE FALSE TRUE ... #> .. ..$ pclass : Factor w/ 3 levels "1st","2nd","3rd": 1 1 1 1 1 1 1 1 1 1 ... #> .. ..$ sex : Factor w/ 2 levels "female","male": 1 2 1 2 1 2 1 2 1 2 ... #> .. ..- attr(*, "description")= chr "## Titanic\n\nThis dataset describes the survival status of individual passengers on the Titanic. The titanic d"| __truncated__ #> ..$ offset : NULL #> ..$ control :List of 3 #> .. ..$ epsilon: num 0.00000001 #> .. ..$ maxit : num 25 #> .. ..$ trace : logi FALSE #> ..$ method : chr "glm.fit" #> ..$ contrasts :List of 2 #> .. ..$ pclass: chr "contr.treatment" #> .. ..$ sex : chr "contr.treatment" #> ..$ xlevels :List of 2 #> .. ..$ pclass: chr [1:3] "1st" "2nd" "3rd" #> .. ..$ sex : chr [1:2] "female" "male" #> ..- attr(*, "class")= chr [1:2] "glm" "lm" #> $ mmx : tibble [1,043 × 3] (S3: tbl_df/tbl/data.frame) #> ..$ survived: logi [1:1043] TRUE TRUE FALSE FALSE FALSE TRUE ... #> ..$ pclass : Factor w/ 3 levels "1st","2nd","3rd": 1 1 1 1 1 1 1 1 1 1 ... #> ..$ sex : Factor w/ 2 levels "female","male": 1 2 1 2 1 2 1 2 1 2 ... #> ..- attr(*, "description")= chr "## Titanic\n\nThis dataset describes the survival status of individual passengers on the Titanic. The titanic d"| __truncated__ #> $ rv : Factor w/ 2 levels "Yes","No": 1 1 2 2 2 1 1 2 1 2 ... #> $ not_vary : chr(0) #> $ df_name : chr "titanic" #> $ vars : chr [1:2] "pclass" "sex" #> $ rvar : chr "survived" #> $ evar : chr [1:2] "pclass" "sex" #> $ lev : chr "Yes" #> $ int : chr "" #> $ wts : NULL #> $ check : chr "" #> $ form : symbol #> $ ci_type : chr "profile" #> $ data_filter: chr "" #> - attr(*, "class")= chr [1:3] "logistic" "model" "list"