Skip to main content

Using Packages to Apply Advanced Models

  • Chapter
  • First Online:
Political Analysis Using R

Part of the book series: Use R! ((USE R))

  • 12k Accesses

Abstract

In the first seven chapters of this book, we have treated R like a traditional statistical software program and reviewed how it can perform data management, report simple statistics, and estimate a variety of regression models. In the remainder of this book, though, we turn to the added flexibility that R offers—both in terms of programming capacity that is available for the user as well as providing additional applied tools through packages. In this chapter, we focus on how loading additional batches of code from user-written packages can add functionality that many software programs will not allow. Although we have used packages for a variety of purposes in the previous seven chapters (including car, gmodels, and lattice, to name a few), here we will highlight packages that enable unique methods. While the CRAN website lists numerous packages that users may install at any given time, we will focus on four particular packages to illustrate the kinds of functionality that can be added.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Subscribe and save

Springer+ Basic
$34.99 /Month
  • Get 10 units per month
  • Download Article/Chapter or eBook
  • 1 Unit = 1 Article or 1 Chapter
  • Cancel anytime
Subscribe now

Buy Now

Chapter
USD 29.95
Price excludes VAT (USA)
eBook
USD 54.99
Price excludes VAT (USA)
Softcover Book
USD 69.99
Price excludes VAT (USA)

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Similar content being viewed by others

Notes

  1. 1.

    Note that this multilevel approach to panel data is most sensible for short panels such as these where there are many individuals relative to the number of time points. For long panels in which there are many time points relative to the number of individuals, more appropriate models are described as pooled time series cross-section methods. For more on the study of short panels, see Monogan (2011) and Fitzmaurice et al. (2004).

  2. 2.

    If you do not have these data from before, you can download the file BPchap7.dta from the Dataverse on page vii or the chapter content on page 125.

  3. 3.

    See also the nlme library, which was a predecessor to lme4.

  4. 4.

    If you do not have these data from before, you can download the file SinghJTP.dta from the Dataverse on page vii or the chapter content on page 125.

  5. 5.

    For priors on the coefficients, the option b0 sets the vector of means of a multivariate Gaussian prior, and B0 sets the variance-covariance matrix of the multivariate Gaussian prior. The prior distribution of the error variance of regression is inverse Gamma, and this distribution can be manipulated by setting its shape parameter with option c0 and scale parameter with option d0. Alternatively, the inverse Gamma distribution can be manipulated by changing its mean with the option sigma.mu and its variance with the option sigma.var.

  6. 6.

    To write out a similar table to Table 8.2 in LaTeX, load the xtable library in R and type the following into the console:

    xtable(cbind(summary(mcmc.hours)$statistics[,1:2], summary(mcmc.hours)$quantiles[,c(1,5)]),digits=4)

  7. 7.

    This frequently occurs when one package depends on code from another.

  8. 8.

    LaLonde’s data is also available in the file LL.csv, available in the Dataverse (see page vii) or the chapter content (see page 125).

  9. 9.

    The UN data is also available in the file UN.csv, available in the Dataverse (see page vii) or the chapter content (see page 125).

  10. 10.

    When choosing how many dimensions to include in a measurement model, many scholars use the “elbow rule,” meaning they do not include any dimensions past a visual elbow in the scree plot. In this case, a scholar certainly would not include more than three dimensions, and may be content with two. Another common cutoff is to include any dimension for which the eigenvalue exceeds 1, which would have us stop at two dimensions.

References

  • Alvarez RM, Levin I, Pomares J, Leiras M (2013) Voting made safe and easy: the impact of e-voting on citizen perceptions. Polit Sci Res Methods 1(1):117–137

    Article  Google Scholar 

  • Bates D, Maechler M, Bolker B, Walker S (2014) lme4: linear mixed-effects models using Eigen and S4. R package version 1.1-7. http://www.CRAN.R-project.org/package=lme4

  • Berkman M, Plutzer E (2010) Evolution, creationism, and the battle to control America’s classrooms. Cambridge University Press, New York

    Book  Google Scholar 

  • Black D (1958) The theory of committees and elections. Cambridge University Press, London

    MATH  Google Scholar 

  • Carlin BP, Louis TA (2009) Bayesian methods for data analysis. Chapman & Hall/CRC, Boca Raton, FL

    MATH  Google Scholar 

  • Downs A (1957) An economic theory of democracy. Harper and Row, New York

    Google Scholar 

  • Fitzmaurice GM, Laird NM, Ware JH (2004) Applied longitudinal analysis. Wiley-Interscience, Hoboken, NJ

    MATH  Google Scholar 

  • Gelman A, Hill J (2007) Data analysis using regression and multilevel/hierarchical models. Cambridge University Press, New York

    Google Scholar 

  • Gelman A, Carlin JB, Stern HS, Rubin DB (2004) Bayesian data analysis, 2nd edn. Chapman & Hall/CRC, Boca Raton, FL

    MATH  Google Scholar 

  • Gill J (2008) Bayesian methods: a social and behavioral sciences approach, 2nd edn. Chapman & Hall/CRC, Boca Raton, FL

    MATH  Google Scholar 

  • Honaker J, King G, Blackwell M (2011) Amelia II: a program for missing data. J Stat Softw 45(7):1–47

    Article  Google Scholar 

  • Hotelling H (1929) Stability in competition. Econ J 39(153):41–57

    Article  Google Scholar 

  • Iacus SM, King G, Porro G (2009) cem: software for coarsened exact matching. J Stat Softw 30(9):1–27

    Article  Google Scholar 

  • Iacus SM, King G, Porro G (2011) Multivariate matching methods that are monotonic imbalance bounding. J Am Stat Assoc 106(493):345–361

    Article  MathSciNet  MATH  Google Scholar 

  • Iacus SM, King G, Porro G (2012) Causal inference without balance checking: coarsened exact matching. Polit Anal 20(1):1–24

    Article  Google Scholar 

  • Imai K, van Dyk DA (2004) Causal inference with general treatment regimes: generalizing the propensity score. J Am Stat Assoc 99(467):854–866

    Article  MathSciNet  MATH  Google Scholar 

  • Laird NM, Fitzmaurice GM (2013) Longitudinal data modeling. In: Scott MA, Simonoff JS, Marx BD (eds) The Sage handbook of multilevel modeling. Sage, Thousand Oaks, CA

    Google Scholar 

  • LaLonde RJ (1986) Evaluating the econometric evaluations of training programs with experimental data. Am Econ Rev 76(4):604–620

    Google Scholar 

  • Martin AD, Quinn KM, Park JH (2011) MCMCpack: Markov chain Monte Carlo in R. J Stat Softw 42(9):1–21

    Article  Google Scholar 

  • McCarty NM, Poole KT, Rosenthal H (1997) Income redistribution and the realignment of American politics. American enterprise institute studies on understanding economic inequality. AEI Press, Washington, DC

    Google Scholar 

  • Monogan JE III (2011) Panel data analysis. In: Badie B, Berg-Schlosser D, Morlino L (eds) International encyclopedia of political science. Sage, Thousand Oaks, CA

    Google Scholar 

  • Peake JS, Eshbaugh-Soha M (2008) The agenda-setting impact of major presidential TV addresses. Polit Commun 25:113–137

    Article  Google Scholar 

  • Poole KT, Rosenthal H (1997) Congress: a political-economic history of roll call voting. Oxford University Press, New York

    Google Scholar 

  • Poole KT, Lewis J, Lo J, Carroll R (2011) Scaling roll call votes with wnominate in R. J Stat Softw 42(14):1–21

    Article  Google Scholar 

  • Robert CP (2001) The Bayesian choice: from decision-theoretic foundations to computational implementation, 2nd edn. Springer, New York

    MATH  Google Scholar 

  • Rubin DB (2006) Matched sampling for causal effects. Cambridge University Press, New York

    Book  MATH  Google Scholar 

  • Scott MA, Simonoff JS, Marx BD (eds) (2013) The Sage handbook of multilevel modeling. Sage, Thousand Oaks, CA

    Google Scholar 

  • Sekhon JS, Grieve RD (2012) A matching method for improving covariate balance in cost-effectiveness analyses. Health Econ 21(6):695–714

    Article  Google Scholar 

  • Singh SP (2014a) Linear and quadratic utility loss functions in voting behavior research. J Theor Polit 26(1):35–58

    Article  Google Scholar 

  • Singh SP (2015) Compulsory voting and the turnout decision calculus. Polit Stud 63(3):548–568

    Article  Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

8.1 Electronic Supplementary material

Rights and permissions

Reprints and permissions

Copyright information

© 2015 Springer International Publishing Switzerland

About this chapter

Cite this chapter

Monogan, J.E. (2015). Using Packages to Apply Advanced Models. In: Political Analysis Using R. Use R!. Springer, Cham. https://doi.org/10.1007/978-3-319-23446-5_8

Download citation

Publish with us

Policies and ethics