If you find any errors or have any questions, please send emails to (junxu dot soc at gmail dot com). I will respond at my earliest convenience. Or, you can fill out the publicly shared excel sheet for errata registration toward the end of this page. For corrections and revisions, please see the corrigenda page. Thank you for your help and support!
News and Updates of Important R Packages/Functions
The VGAM package (by Thomas Yee) is versatile in estimating a wide variety of vector generalized linear and additive models.
The Zelig package (by Gary King and his colleagues) is deprecated and replaced by the clarify package (by Gary King and his colleagues), which is a great R package for post-estimation analysis. Here is a document to reproduce the examples in my MARs book using functions from clarify. As this document is written, clarify still doesn't work with accelerated failure time survival regression models, in part due to the issues with the marginaleffects package.
The marginaleffects (the counterpart of margins in Stata) package (by Vincent Arel-Bundock) is amazing for post-estimation analysis. Documents to show how the examples using margins and other functions in MARs can be replaced by marginaleffects (to come soon).
The ggeffects (by Daniel Lüdecke) and effects (by John Fox) packages are great at graphing quantities of interest (e.g., response variables, predicted prob, rates) after estimation.
Chapter 1 Introduction and Linear Regression
R Materials
R Scripts (OLS Regression, R Lab, Bayes OLS)
Selected Important R functions and packages
cut: turn numeric to factor variables
tab1 (the epiDisplay package): display one-way tabulation
tabpct (the epiDisplay package): construct two-way tabulation with automatic mosaic plot
glm and lm (the stats package): fit linear models
ggpredict (the ggeffects package): estimate marginal means and adjusted predictions
bayesglm (the arm package): Bayesian generalized linear models
Chapter 2 Binary Regression
R Materials
R Scripts (Binary Regression, Bayes Binary Regression)
Selected Important R functions and packages
PseudoR2 (the DescTools package): compute commonly used pseudo R-squareds
prediction and performance (the ROCR package): compute and draw ROC
dc (the glm.predict package): compute predicted values and discrete changes
dydx and margins (the margins package): compute marginal effect of a given variable
bayesglm (the arm package): Bayesian generalized linear models
MCMClogit (the MCMCpack package): Markov chain Monte Carlo for logistic regression
Chapter 3 Polytomous Regression
R Materials
R Scripts (Polytomous Regression, Bayes Polytomous Regression)
Selected Important R functions and packages
star.cumulative and star.nomial (the EffectStar package) and effectstars.vglm (the EffectStar2 package): estimate cumulative logit and multinomial logit models and draw star plots for regression coefficients/odds ratio coefficients,
vglm and rrvglm (the VGAM package): estimate vector generalized linear model and reduced-rank vector generalized linear models
get_predicted (the insight package, the easystats package): estimate model predictions and their confidence intervals
multinom (the nnet package): estimate multinomial regression models
mnp (the MNP package): estimate multinomial probit models
stan_polr (the rstanarm package): estimate Bayesian proportional odds models
Chapter 4 Count Regression
R Materials
R Scripts (Count Regression, Bayes Count Regression)
Selected Important R functions and packages
glm (stats): estimate Poisson regression models
glm.nb (MASS): estimate negative binomial regression models
hurdle (countreg): estimate hurdle models
zeroinfl (countreg): estimate zero-inflated Poisson and negative binomial regression models
Chapter 5 Survival Regression
R Materials
R Scripts (Survival Regression, Bayes Survival Regression)
Selected Important R functions and packages
suvfit (survival): compute Kaplan-Meier (KM) estimates
suvreg (survival): estimate AFT (accelerated failure-time) survival regression models
coxph (survival): estimate Cox PH regression models
Chapter 6 Extension
Supplementary Materials
Please fill out this form if you find any errors
Data
galileo1632.RData (Chapter 1: The Galileo 1632 data)
gssCum7212Teach.dta (Chapters 1-4: Random sample from the General Social Survey data)
hkFisher.Rdata (Chapter 4: The von Bortkiewicz Prusian horse kick data trimmed by R. A. Fisher)
gssndi7802rec.dta (Chapter 5: The recoded random sample of the General Social Survey (GSS) -- National Death Index linked cumulative data file 1978-2002)
indcntdta01Samp.dta (Chapter 6.1 Multilevel Regression: A random sample of the BRFSS 2010 Survey data with both individual and county data linked/indcntdta01.dta)
Marginal effects formulas
Epigraph (for those interested in the original Chinese texts of the epigraphs at the beginning of each chapter)
Presentation, Seminar, and Workshops