Package Poliscidata': R Topics Documented
Package Poliscidata': R Topics Documented
Package Poliscidata': R Topics Documented
R topics documented:
AdjR2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
available.imported.functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
CI95 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
CI99 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Colors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
colPercents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
compADPQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
CramersV . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
fit.svyglm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1
2 AdjR2
freqC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
gss . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
gssD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
imeansC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
inverse.logit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
iplotC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
lineType . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
logregR2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
nes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
nesD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
orci . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
pchisqC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
plotChar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
plotmeansC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
printC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
prop.testC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
quickConsolePrint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
SetTextContrastColor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
slowConsolePrint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
somersD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
sortC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
states . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
statesD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
svybyC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
svychisqC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
tablesomersDC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
welcome . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
world . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
worldD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
wtd.boxplot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
wtd.median . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
wtd.mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
wtd.sd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
wtd.ttestC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
xtabC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
xtp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
xtp.chi2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
Index 56
Description
Calculates adjusted R-Squared statistic based on user-defined inputs. This function can be used
after estimating a model that does not report adjusted R-Squared statistic. For svyglm model fit
statistics, see fit.svyglm function documentation.
available.imported.functions 3
Usage
AdjR2(tdf, null.dev, resid.dev, k)
Arguments
tdf The total degrees of freedom
null.dev The null deviance or total sum of squares
resid.dev The residual deviance or error sum of squares
k The number of parameters used (to reduce deviance)
Value
Returns an adjusted R-Squared statistic, a numeric value between 0 and 1
Examples
AdjR2(200, 1500, 1100, 5)
available.imported.functions
Imported Functions Made Available to Users
Description
The compmeans function is imported from descr package. See compmeans documentation for de-
tails.
The crosstab function is imported from the descr package. See crosstab documentation for
details.
The csv.get function is imported from the Hmisc package. See csv.get documentation for details.
The cut2 function is imported from the Hmisc package. See cut2 documentation for details.
The ddply function is imported from the plyr package. See ddply documentation for details.
The describe function is imported from the Hmisc package. See describe documentation for
details.
The freq function is imported from the descr package. See freq documentation for details.
The plotmeans function is imported from the gplots package. See plotmeans documentation for
details.
The scatterplot function is imported from the car package. See scatterplot documentation for
details.
The spss.get function is imported from the Hmisc package. See spss.get documentation for
details.
4 available.imported.functions
The stata.get function is imported from the Hmisc package. See stata.get documentation for
details.
The svyboxplot function is imported from the survey package. See svyhist documentation for
details.
The svyby function is imported from the survey package. See svyby documentation for details.
The svychisq function is imported from the survey package. See svychisq documentation for
details.
The svydesign function is imported from the survey package. See svydesign documentation for
details.
The svyglm function is imported from the survey package. See svyglm documentation for details.
The svymean function is imported from the survey package. See surveysummary documentation
for details.
The svyplot function is imported from the survey package. See svyplot documentation for details.
The svytable function is imported from the survey package. See svychisq documentation for
details.
The wtd.chi.sq function is imported from the weights package. See wtd.chi.sq documentation
for details.
The wtd.cor function is imported from the weights package. See wtd.cor documentation for
details.
The wtd.hist function is imported from the weights package. See wtd.hist documentation for
details.
The wtd.mean function is imported from the Hmisc package. See wtd.stats documentation for
details.
The wtd.quantile function is imported from the Hmisc package. See wtd.stats documentation for
details.
The wtd.t.test function is imported from the weights package. See wtd.t.test documentation
for details.
The wtd.var function is imported from the Hmisc package. See wtd.stats documentation for
details.
Usage
compmeans(...)
crosstab(...)
csv.get(...)
cut2(...)
ddply(...)
describe(...)
CI95 5
freq(...)
plotmeans(...)
scatterplot(...)
spss.get(...)
stata.get(...)
svyboxplot(...)
svyby(...)
svychisq(...)
svydesign(...)
svyglm(...)
svymean(...)
svyplot(...)
svytable(...)
wtd.chi.sq(...)
wtd.cor(...)
wtd.hist(...)
wtd.mean(...)
wtd.quantile(...)
wtd.t.test(...)
wtd.var(...)
Arguments
... See source package help file for details on function usage.
Description
Prints the lower and upper boundaries of a 95 Percent confidence interval. Also see the CI95
function.
Usage
CI95(m, se)
Arguments
m A single number equal to the mean value of a statistic.
se single number equal to the standard error of the statistic.
Value
Returns the 95
Examples
CI95(10, 1)
CI95(m=8, se=2)
Description
Prints the lower and upper boundaries of a 99 Percent confidence interval. Also see the CI95
function.
Usage
CI99(m, se)
Arguments
m A single number equal to the mean value of a statistic.
se single number equal to the standard error of the statistic.
Value
Returns the 99
Colors 7
Examples
CI99(10, 1)
CI99(m=8, se=2)
Description
Produces plot of colors available in R. Colored cells labels with numeric value that corresponds to
that color. No values supplied to function.
Usage
Colors()
Value
No value returned
Examples
Colors()
Description
Generates column percentaged tables for multi-dimensional controlled cross-tabulations, based on
function by John Fox. Used by xtabC function.
Usage
colPercents(tab, digits = 2)
Arguments
tab A table of values
digits Number of decimal places to display, default is 2.
Value
Table of column-percentaged values
8 CramersV
Description
This function is called by tablesomersDC function.
Usage
compADPQ(x)
Arguments
x A matrix or data frame
Value
Returns a list of statistics
Description
Calculates Cramer’s V, a measure of association to gauge the strength of the relationship between
two nominal-level variables. A score of 0 indicates no relationship; a score of 1 indicates a perfect
relationship.
Usage
CramersV(chi, r, c, n)
Arguments
chi A number equal to the Chi-Squared statistic
r A number equal to the number of rows
c A number equal to the number of columns
n A number equal to the sample size
Value
The Cramer’s V statistic, a number between 0 and 1.
Examples
CramersV(84.18, 2, 2, 1315)
fit.svyglm Calculates model fit statistics for a svyglm weighted regression model
Description
Model fit statistics for a svyglm weighted regression model
Usage
fit.svyglm(svyglm, digits = 3)
Arguments
svyglm An object of type svyglm. This object is the output of the svyglm functon.
digits Number of digits to report after decimal place, optional (default = 3).
Value
Returns a numeric vector of R-Squared and Adjusted R-sSquared statistics.
Examples
library(poliscidata)
Description
Generates frequency distribution table and bar chart to describe distribution of variable values.
Based on freq function in descr package.
Usage
freqC(x, w, plot = TRUE)
Arguments
x A vector of variable values, should be in form dataset$var
w Sample weights (optional), should be in form dataset$weighvar
plot Do you want a bar chart? (default set to TRUE)
10 gss
Value
A frequency distribution table (a "freqtable" and "matrix" class object)
Examples
library(poliscidata)
freqC(gss$zodiac, gss$wtss)
freqC(x=gss$zodiac, w=gss$wtss)
Description
The General Social Survey polls individuals about their attitudes and beliefs. This dataset is used
to demonstrate application of R to political analysis. See book Appendix for variable names and
descriptions.
Usage
gss
Format
A data frame with 1974 rows and 221 variables.
Source
2012 General Social Survey. See Appendix Table A.1 of printed textbook for further information
Description
The General Social Survey polls individuals about their attitudes and beliefs. This design dataset
is used to demonstrate application of certain R functions to political analysis. See gss dataset
documentation for variable names and descriptions.
Usage
gssD
imeansC 17
Format
A design dataset version of the gss dataset used for certain weighted analyses. The variables element
has 1974 observations of 221 variables.
Source
2012 General Social Survey. See Appendix Table A.1 of printed textbook for further information
Description
Produces a controlled mean comparison table. Rows defined by values of independent variable and
columns defines by values of the control variable.
Usage
Arguments
Value
Examples
library(poliscidata)
Description
This function calculates predicted probability for a given logged odds value, often useful for plotting
or reporting predicted probabilities.
Usage
inverse.logit(logged_odds)
Arguments
logged_odds A numeric value, or vector of numeric values.
Value
Returns predicted probability corresponding the the logged odds value, a numeric value between 0
and 1.
Examples
inverse.logit(0)
inverse.logit(-5:5)
Description
Interaction plot uses brkdn.plot in plotrix package and svyby function from survey package.
Warnings suppressed so the function creates plot without generating intermediate results used to
create plot.
Usage
iplotC(function1 = NULL, function2 = NULL, data, function3 = NULL, ...)
Arguments
function1 A function in the form ~depvar
function2 A function. Here indepvar is typed before controlvar: ~indepvar + controlvar
data Design dataset (e.g. nesD, gssD, statesD, or worldD)
function3 A function. Here indepvar is typed after controlvar: ~controlvar + indepvar
... Further arguments to be passed to brkdn.plot function (plotrix package)
lineType 19
Value
No value returned
Examples
library(poliscidata)
Description
Displays line types for R plots. No values supplied to function.
Usage
lineType()
Value
No value returned
Examples
lineType()
Description
Logistic regression model statistics
Usage
logregR2(model, digits = 3)
20 nes
Arguments
model An estimated logistic regression model
digits Number of digits to be displayed after decimal points
Value
Returns list of statistics about model (a "LogRegR2" class object)
Examples
library(poliscidata)
obama_state_model <- glm(obama_win12 ~ secularism + gunlaw_rank, data=states, family=binomial)
summary(obama_state_model)
logregR2(obama_state_model)
Description
The American National Election Survey polls individuals about their political beliefs and behavior.
This dataset is used to demonstrate application of R to political analysis. See book Appendix for
variable names and descriptions.
Usage
nes
Format
A data frame with 5916 rows and 399 variables.
dhsinvolv_relig Civic engagement: Has Respondent in past 4 years: given money to religious
organization
discrim_blacks Discrimination: Amount against Blacks
discrim_blacks_r Discrimination: Against Blacks? (yes/no)
discrim_gays Discrimination: Amount against Gays and Lesbians?
discrim_gays_r Discrimination: Against gays? (yes/no)
discrim_hispanics Discrimination: Amount against Hispanics
discrim_hispanics_r Discrimination: Against Hispanics? (yes/no)
discrim_scale Discrimination: How much discrimination against blacks, gays, Hispanics, women?
(Sum of yes answers)
discrim_self Discrimination: How much discrimination faced personally?
discrim_whites Discrimination: Amount against Whites
discrim_women Discrimination: Amount against Women
discrim_women_r Discrimination: Against women? (yes/no)
discuss_disc Ever discuss politics with family or friends
discuss_discpstwk Days in past week discussed politics
ecblame_fmpr Economy: How much is former President to blame for poor economy?
ecblame_pres Economy: How much is President to blame for poor economy?
econ_ecnext_x Economy: U.S. economy better or worse 1 year from now
econ_ecnextamt Economy: How much better/worse next 12 months
econ_ecnow Economy: Currently good or bad
econ_ecpast Economy: Better/worse in last year
econ_ecpast_x Economy: Better or worse than 1 year ago
econ_ecpastamt Economy: How much better/worse in last year
econ_unlast Economy: How much unemployment better/worse in last year
econ_unnext Economy: More/less unemployment in next year
econ_unpast Economy: Unemployment better/worse in last year
econ_unpast_x Economy: Unemployment better/worse than 1 year ago
econcand_dwin Economy: Better/worse if Democratic Presidential candidate wins
econcand_rwin Economy: Better/worse if Republican Presidential candidate wins
ecperil_home How do you pay for your home?
effic_carerev Political efficacy: Public officials don’t care what people think
effic_carestd Political efficacy: Public officials don’t care what people think
effic_complicrev Political efficacy: Politics/government too complicated to understand
effic_complicstd Political efficacy: Politics/government too complicated to understand
effic_external Political efficacy: External political efficacy (numeric scale)
effic_external3 Political efficacy: External political efficacy (3 categories)
effic_internal Political efficacy: Internal political efficacy (numeric scale)
24 nes
trad_lifestyle Traditional values: Agree/disagree are newer lifestyles are breaking down society
trad_tolerant Traditional values: Agree/disagree that one should be more tolerant of other moral
standards
trad_values_scale Traditional values: Moral traditionalism scale
trust_social Trust: How often can people be trusted?
trustgov_bigintrst Trust: Is government run by a few big interests or for benefit of all?
trustgov_corrpt Trust: How many in government are corrupt?
trustgov_trustgrev Trust: How often trust gov’t in Wash to do what is right? (reversed)
trustgov_trustgstd Trust: How often trust government in Wash to do what is right?
trustgov_waste Trust: Does government waste much tax money?
trustgvpo_crook Trust: How many in government are crooked?
usworld_stay International relations: Country better off if we just stayed home
usworld_stronger International relations: During last year, U.S. position in world is weaker/stronger/same?
version ANES 2012 Time Series Release Version
voted2008 Did Respondent vote for President in 2008? (Recode of interest_voted2008)
voted2012 Did Respondent vote in 2012?
voter_type Voter type (non, new, voter)
weight_ftf Post-stratified weight for face-to-face cases, preliminary
weight_full Post-stratified weight for full sample, preliminary release
weight_web Post-stratified weight for web cases, preliminary release
white Is Respondent white?
wiretap_warrant Wiretaps: Favor or oppose authority to wiretap terrorism suspects?
wiretappo_toofar Wiretaps: Has government power gone too far?
women_bond_x Working women: Harder to establish bond with child?
women_role Working women: Women’s role (numeric scale)
women_role_2 Working women: Women’s role at home or work?
women_works_x Working women: Better if man works and woman takes care of home and fam-
ily?
wpres_gdbd_x How good/bad to have woman president in next 20 years?
wt Sampling weight
year ANES year
Source
2012 American National Election Survey. See Appendix Table A.2 of printed textbook for further
information
32 orci
Description
The American National Election Survey polls individuals about their political beliefs and behavior.
This design dataset is used to demonstrate application of certain R functions to political analysis.
See nes dataset documentation for variable names and descriptions.
Usage
nesD
Format
A design dataset version of the nes dataset used for certain weighted analyses. The variables element
has 5916 observations of 399 variables.
Source
2012 American National Election Survey. See Appendix Table A.2 of printed textbook for further
information
Description
Generates odds-ratios based on logistic regression model coefficients
Usage
orci(model, digits = 3)
Arguments
model An estimated logistic regression model
digits Number of digits after decimal to display
Value
Returns odds rations and confidence intervals in columns (a matrix class object)
pchisqC 33
Examples
library(poliscidata)
obama_state_model <- glm(obama_win12 ~ secularism + gunlaw_rank, data=states, family=binomial)
summary(obama_state_model)
orci(obama_state_model)
Description
Comparing Logistic Regression Models with Chi-Squared Test
Usage
pchisqC(reduced, full, digits = 3)
Arguments
reduced The reduced logisitic regression model as an object. This is model with fewer
independent variables.
full The full logisitic regression model as an object. This is model with more inde-
pendent variables.
digits The number of digits to display after decimal point, default is 3.
Value
The chi-squared statistic, df, and p-value as a vector of numbers to test null hypothesis that full
model no better than reduced model.
Examples
library(poliscidata)
Description
Displays plotting characters available in R. No values supplied to function.
Usage
plotChar()
Value
No return
Examples
plotChar()
Description
Plots the mean values of a dependent variable at different values of nominal or ordinal independent
variable. Makes use of survey package’s svy
Usage
plotmeansC(data, function1 = NULL, function2 = NULL, function3, w = 1, ...)
Arguments
data A dataset (e.g. gss, nes, states, or world) or design dataset (e.g. gssD, nesD,
statesD, or worldD)
function1 A function in the form of ~ depvar
function2 A formula in the form of ~ indepvar
function3 A formula in the form of depvar ~ indepvar
w Weights, in the form ~ weightvar (optional, not needed if you use a design
dataset)
... Additonal arguments passed to gplots package’s plotmeans function
Value
No return
printC 35
Examples
library(poliscidata)
plotmeansC(nes,~envir,~pid_3,envir~pid_3,w=~wt,
xlab="Party Identification",
ylab="Percent Pro-Environment",
main="Percentage Favoring Environment over Jobs,\n by Party ID")
Description
Prints html-ready table to local working directory. Makes use of xtable package’s print.xtable
function. See pp. 22 of An R Companion to Political Analysis for example and more information.
Usage
printC(objx)
Arguments
objx A table or data frame
Value
No return
Description
Difference of proportions test with optional sample weights. Reports P-value of two-tailed signifi-
cance test.
Usage
prop.testC(y, x, w = NULL, digits = 3)
36 quickConsolePrint
Arguments
Value
No return
Examples
library(poliscidata)
Description
Prints string to console quickly, but still scolls for visual effect
Usage
quickConsolePrint(linetoprint)
Arguments
Value
No value returned
SetTextContrastColor 37
Description
Sets color for text that effectively contrasts with the background color specified. Used by the Colors
function.
Usage
SetTextContrastColor(color)
Arguments
color A color
Value
Returns either "black" or "white"
Description
Prints string to console slowly to make text more readable to the user. Used by welcome function.
Usage
slowConsolePrint(linetoprint, slow = 0.05)
Arguments
linetoprint Text to be printed to console
slow Time, in milliseconds, to wait between characters printed to console (default is
.05).
Value
No value returned
38 sortC
Description
This function calculates the Somer’s D measure of association statistic. This function makes use of
the svytable function from the survey package.
Usage
somersD(formula, data)
Arguments
formula A formula in the form ~ indepvar + depvar
data A design dataset (e.g. gssD, nesD, statesD, or worldD)
Value
Return Somer’s D measure of association statistic, a number between 0 and 1.
Examples
library(poliscidata)
Description
Returns case-level information in order specified by user.
Usage
sortC(data, id, by, descending = TRUE)
Arguments
data Dataset to be sorted.
id A variable in the dataset (data) that identfies individual cases, typically the name
of states, countries, etc.
by Variable the dataset should be sorted by.
descending Should the cases be sorted in descending order? By default, set to TRUE.
states 39
Value
A data frame of sorted observations.
Examples
library(poliscidata)
Description
A dataset with variables about the 50 states. This dataset is used to demonstrate application of R to
political analysis. See book Appendix for variable names and descriptions.
Usage
states
Format
A data frame with 50 rows and 135 variables.
permit Percent public that would always permit abortion (2004 NES)
pop_18_24 Percent population aged 18-24 (2004)
pop_18_24_10 Percent population aged 18-24 (2010)
pop2000 State population, 2000
pop2010 State population, 2010
pop2010_hun_thou State population, 2010 (in 100k)
popchng0010 State population, 2000-2012
popchngpct State population percentage, 2000-2010
pot_policy Marijuana laws
prcapinc Per capita income
prochoice Percent public pro-choice
prolife Percent public pro-life
region Census region (4 categories)
relig_cath Percentage Catholic (2012)
relig_high Percentage high religiosity (2012)
relig_import Percent religion "A great deal of guidance"
relig_low Percentage low religiosity (2012)
relig_prot Percentage Protestant (2012)
religiosity Religious observance-belief scale (Pew)
religiosity3 Religiosity (3 categories)
reppct_m Percent mass public Republican
romney2012 Romney vote share in 2012
rtw Right to work state?
secularism Secularism scale (Pew)
secularism3 3 quantiles of secularism
seniority_sen2 Does state have influential US Senator?
smokers12 Percentage of population who smoke
south Southern state?
state State name
stateid Two letter postal abbreviation for state name
to_0004 Percentage point change in turnout from 2000 to 2004
to_0408 Percentage point change in turnout from 2004 to 2008
to_0812 Percentage point change in turnout from 2008 to 2012
trnout00 Turnout in 2000 presidential election
trnout04 Turnout in 2004 presidential election
unemploy Unemployment rate (2004)
uninsured_pct Percentage without health insurance (2012)
statesD 43
Source
Data sources vary. See Appendix Table A.3 of printed textbook for further information.
Description
This is a design dataset with variables about the 50 states. This design dataset is used to demon-
strate application of certain R functions to political analysis. See states dataset documentation for
variable names and descriptions.
Usage
statesD
Format
A design dataset version of the states dataset used for certain weighted analyses. The variables
element has 50 observations of 135 variables.
Source
Sources vary. See Appendix Table A.3 of printed textbook for further information
44 svychisqC
Description
Computes statistics for controlled mean comparison table. Used by imeansC function.
Usage
svybyC(formula1 = NULL, formula2 = NULL, data, ...)
Arguments
formula1 A formula
formula2 A formula
data Dataset
... Further arguments to be passed to svyby function.
Value
A svyby-type object
Description
This function reports chi-squared test statistic based on weighted dataset
Usage
svychisqC(formula, design)
Arguments
formula Formula expressing the relationship between variables in the form ~ depvar +
indepvar
design Weighted design dataset (like gssD, nesD, statesD, or worldD)
Value
No return
tablesomersDC 45
Examples
library(poliscidata)
Description
This function is called by somersD function.
Usage
tablesomersDC(x, dep = 2)
Arguments
x A svytable
dep which dimension stands for the dependent variable (1 = ROWS, 2 = COLS),
default is 2.
Value
No return
Description
Welcomes users to Companion Package to Political Analysis and provides basic information about
using Companion functions and datasets.
Usage
welcome()
Value
No value returned
46 world
Description
A dataset with variables about countries in the world. This dataset is used to demonstrate application
of R to political analysis. See book Appendix for variable names and descriptions.
Usage
world
Format
A data frame with 167 rows and 103 variables.
votevap00s Turnout: most recent election in 2000s (Institute for Democracy and Electoral Assis-
tance)
votevap90s Turnout: elections in 1990s (Institute for Democracy and Electoral Assistance)
women05 Percent women in lower house of legislature, democracies only, 2005 (Inter-Parliamentary
Union)
women09 Percent women in lower house of legislature, democracies only, 2009 (Inter-Parliamentary
Union)
women13 Percent Women in lower house of legislature, democracies only, 2013 (Inter-Parliamentary
Union)
womyear Year women first enfranchised (Inter-Parliamentary Union)
womyear2 Women’s suffrage (Inter-Parliamentary Union)
Source
Sources vary. See Appendix Table A.4 of printed textbook for further information.
Description
This is a design dataset with variables about countries in the world. This dataset is used to demon-
strate application of R to political analysis. See world dataset documentation for variable names
and descriptions.
Usage
worldD
Format
A design dataset version of the world dataset used for certain weighted analyses. The variables
element has 167 observations of 103 variables.
Source
Sources vary. See Appendix Table A.4 of printed textbook for further information
50 wtd.median
Description
The wtd.boxplot function is no longer being used by the poliscidata package. Please use the svy-
boxplot function instead. See svyhist documentation for details; also see pp. 67-69 of The R
Companion to Political Analysis, 2nd Edition.
Usage
wtd.boxplot(...)
Arguments
... Any arguments used will yield same warning message.
Value
Warning message only.
Description
Takes in variable and finds median, works with sampling weights
Usage
wtd.median(x, weights = NULL)
Arguments
x A variable
weights Sampling weights of variable (optional)
Details
Makes use of the wtd.quantile function, part of the Hmisc package
Value
Returns the median value of the variable
wtd.mode 51
Examples
library(poliscidata)
wtd.median(nes$budget_deficit_x, nes$wt)
Description
Usage
Arguments
x A variable
weights Sampling weights of variable (optional)
Details
Value
Examples
library(poliscidata)
wtd.mode(gss$zodiac, gss$wtss)
52 wtd.ttestC
Description
Takes in variable and calculates standard deviation, works with sampling weights.
Usage
wtd.sd(x, weights = NULL)
Arguments
x A variable (must be numeric), should be in dataset$var form.
weights Sampling weights of variable (optional), should be in dataset$weightvar form.
Details
Makes use of the freq function, part of the descr package.
Value
Returns the standard deviation of the variable, a numeric value.
Examples
library(poliscidata)
wtd.sd(nes$polknow_combined, nes$wt)
Description
This function conducts a weighted t-test
Usage
wtd.ttestC(f1, f2, data, digits = 3)
Arguments
f1 Function identifying interval-level dependent variable in the form ~ depvar
f2 A function that defines groups to be compared in the form ~ indepvar
data A design dataset such as gssD, nesD, statesD, or worldD
digits Number of digits to report after decimal place, optional (default = 3).
xtabC 53
Value
No return
Examples
library(poliscidata)
Description
Usage
Arguments
Value
Examples
library(poliscidata)
Description
Generates cross-tabulation of dependent and indendent variables, also creates a mosiac plot. Makes
use of the crosstab function in the descr package.
Usage
xtp(
data,
y,
x,
w = NULL,
ylab = NULL,
xlab = NULL,
main = NULL,
digits = 2,
chisq = FALSE
)
Arguments
data Dataset (like gss, nes, states, or world)
y Dependent variable
x Independent variable
w Weights (optional)
ylab Y-axis label (optional)
xlab X-axis label (optional)
main Main label for plot (optional)
digits Number of digits to report after decimal place, optional (default = 2)
chisq Do you want Chi-Squared test reported? (default is FALSE)
Value
A data frame of the cross tabulation results
Examples
library(poliscidata)
Description
This function makes use of the crosstab function from the descr package
Usage
xtp.chi2(data, y, x, w = NULL, digits = 1, prop.c = FALSE)
Arguments
data Dataset to be sorted
y Dependent variable
x Independent variable
w Weights (optional)
digits Number of digits to report after decimal place, optional (default = 1).
prop.c Do you want column percentages reported in table? (default is FALSE)
Value
Returns a data frame of cross tabulation results
Examples
library(poliscidata)
∗ datasets fit.svyglm, 2, 9
gss, 10 freq, 3, 9
gssD, 16 freq (available.imported.functions), 3
nes, 20 freqC, 9
nesD, 32
states, 39 gss, 10, 16
statesD, 43 gssD, 16
world, 46
worldD, 49 imeansC, 17, 44
inverse.logit, 18
AdjR2, 2 iplotC, 18
available.imported.functions, 3
lineType, 19
brkdn.plot, 18 logregR2, 19
CI95, 5 nes, 20, 32
CI99, 6 nesD, 32
Colors, 7, 37
colPercents, 7 orci, 32
compADPQ, 8
compmeans, 3 pchisqC, 33
compmeans plotChar, 34
(available.imported.functions), plotmeans, 3, 34
3 plotmeans
CramersV, 8 (available.imported.functions),
crosstab, 3 3
crosstab plotmeansC, 34
(available.imported.functions), print.xtable, 35
3 printC, 35
csv.get, 3 prop.testC, 35
csv.get (available.imported.functions),
3 quickConsolePrint, 36
cut2, 3
cut2 (available.imported.functions), 3 scatterplot, 3
scatterplot
ddply, 3 (available.imported.functions),
ddply (available.imported.functions), 3 3
describe, 3 SetTextContrastColor, 37
describe slowConsolePrint, 37
(available.imported.functions), somersD, 38, 45
3 sortC, 38
56
INDEX 57
tablesomersDC, 8, 45
welcome, 37, 45
world, 46, 49
worldD, 49
wtd.boxplot, 50
wtd.chi.sq, 4
wtd.chi.sq
(available.imported.functions),
3
wtd.cor, 4