R Notes

R Functions

match.call

eval(expr, parent.frame()) evaluates the expr in the environment specified by envir and returns the computed value. Default envir is parent.frame() the environment where the call to eval was made.

[1] FALSE

[1] TRUE

round(10.5)

[1] TRUE

[1] 10

match.call()

[[1]] match.call

[1] “call”

[1] FALSE

FOO()

[1] 4000

Min. 1st Qu. Median Mean 3rd Qu. Max. NA’s -1.10 -0.35 0.67 0.49 1.00 2.30 1

Min. 1st Qu. Median Mean 3rd Qu. Max. NA’s -1.0735 -0.3541 0.6729 0.4917 0.9985 2.3400 1

Min. 1st Qu. Median Mean 3rd Qu. Max. NA’s -1.0735 -0.3541 0.6729 0.4917 0.9985 2.3400 1

[1] 2

[1] “call”

foo(x = 1, y = 2)

[1] “call”

language foo(x = 1, y = 2)

[1] 12

[1] 29

Logistic Regression

Ordinal Regression

rmsb package

Frank Harrell: rmsb Package Example

Bayesian Proportional Odds Ordinal Logistic Model

  • Dirichlet priors on intercepts
  • 0.95 highest posterior density intervals
  • AUROC and \(R^2\) should be estimated with error
  • The symmetry of a posterior distribution. The value of 1.0 indicates symmetry. The symmetry index is the ratio of distance from mean to 0.95 quantile and the distance from mean to 0.05 quantile.
  • The proportional odds ordinal (PO) logistic model is a generalization of Wilcoxon/Kruskal-Wallis tests.

Model Performance

  • Stand diagnostic

Contrasts

  • Bayesian contrast’s point estimate is the posterior mean and the 0.95 posterior density interval
  • instead of p-value, the posterior probability that the constrast is positive is computed

Contrained Partial PO

  • Use the constrained partial proportional odds model to assess the proportional odds assumption.
  • Assume departures from proportional odds (constant increments in log odds) are modeled as linear in square root of the outcome level.
  • Group-stratified empirical CDFs to see visual evidence for this
  • qlogis is the logit function logit(p)=log(p/(1-p))
  • Relative explained variation (REV) is the Wald \(\chi^2\) statistics divided by the Wald statistics for the whole model.

Missing Values

When possible, full joint Bayesian modeling of possible missing covariates and the outcome variable should be used to get exact inference in the presence of missing covariate values.

Then do posterior inference on the full stacked posterior distribution.

Missing Values

Handle Missing Values with brms

Paul Burkner: Handle Missing Values with brms

Imputation before model fitting

Extract those datasets from mice imputed as a list of data frames, and then pass them to the model fitting. The returned fitted model (from brm_multiple) is an ordinary brmsfit object. Therefore, the post-processing methods are straightforward without having to worry about pooling at all.

Imputation during model fitting

Which variables contain missing values and how they should be predicted, and which of these imputed variables should be used as predictors.

Bayesian Additive Regression Tree

BART Vignettes

gbart on

Computing Environment