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.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Similar content being viewed by others
Notes
- 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.
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.
See also the nlme library, which was a predecessor to lme4.
- 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.
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.
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.
This frequently occurs when one package depends on code from another.
- 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.
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.
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
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
Black D (1958) The theory of committees and elections. Cambridge University Press, London
Carlin BP, Louis TA (2009) Bayesian methods for data analysis. Chapman & Hall/CRC, Boca Raton, FL
Downs A (1957) An economic theory of democracy. Harper and Row, New York
Fitzmaurice GM, Laird NM, Ware JH (2004) Applied longitudinal analysis. Wiley-Interscience, Hoboken, NJ
Gelman A, Hill J (2007) Data analysis using regression and multilevel/hierarchical models. Cambridge University Press, New York
Gelman A, Carlin JB, Stern HS, Rubin DB (2004) Bayesian data analysis, 2nd edn. Chapman & Hall/CRC, Boca Raton, FL
Gill J (2008) Bayesian methods: a social and behavioral sciences approach, 2nd edn. Chapman & Hall/CRC, Boca Raton, FL
Honaker J, King G, Blackwell M (2011) Amelia II: a program for missing data. J Stat Softw 45(7):1–47
Hotelling H (1929) Stability in competition. Econ J 39(153):41–57
Iacus SM, King G, Porro G (2009) cem: software for coarsened exact matching. J Stat Softw 30(9):1–27
Iacus SM, King G, Porro G (2011) Multivariate matching methods that are monotonic imbalance bounding. J Am Stat Assoc 106(493):345–361
Iacus SM, King G, Porro G (2012) Causal inference without balance checking: coarsened exact matching. Polit Anal 20(1):1–24
Imai K, van Dyk DA (2004) Causal inference with general treatment regimes: generalizing the propensity score. J Am Stat Assoc 99(467):854–866
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
LaLonde RJ (1986) Evaluating the econometric evaluations of training programs with experimental data. Am Econ Rev 76(4):604–620
Martin AD, Quinn KM, Park JH (2011) MCMCpack: Markov chain Monte Carlo in R. J Stat Softw 42(9):1–21
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
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
Peake JS, Eshbaugh-Soha M (2008) The agenda-setting impact of major presidential TV addresses. Polit Commun 25:113–137
Poole KT, Rosenthal H (1997) Congress: a political-economic history of roll call voting. Oxford University Press, New York
Poole KT, Lewis J, Lo J, Carroll R (2011) Scaling roll call votes with wnominate in R. J Stat Softw 42(14):1–21
Robert CP (2001) The Bayesian choice: from decision-theoretic foundations to computational implementation, 2nd edn. Springer, New York
Rubin DB (2006) Matched sampling for causal effects. Cambridge University Press, New York
Scott MA, Simonoff JS, Marx BD (eds) (2013) The Sage handbook of multilevel modeling. Sage, Thousand Oaks, CA
Sekhon JS, Grieve RD (2012) A matching method for improving covariate balance in cost-effectiveness analyses. Health Econ 21(6):695–714
Singh SP (2014a) Linear and quadratic utility loss functions in voting behavior research. J Theor Polit 26(1):35–58
Singh SP (2015) Compulsory voting and the turnout decision calculus. Polit Stud 63(3):548–568
Author information
Authors and Affiliations
8.1 Electronic Supplementary material
Rights 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
DOI: https://doi.org/10.1007/978-3-319-23446-5_8
Published:
Publisher Name: Springer, Cham
Print ISBN: 978-3-319-23445-8
Online ISBN: 978-3-319-23446-5
eBook Packages: Mathematics and StatisticsMathematics and Statistics (R0)