Description Usage Arguments Value Examples
Gaussian Conjugate Prior Model for American Elections This function completely fits the Iterative Gaussian Proportional model in Alexander and Ellingson (2019) given raw poll data, election data, and basic parameters. Given polling data on congressional districts or senate seats this could make similar predictions.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | noniterativegaussianmodelprop(
poll_data,
stateloc,
proploc,
candidateloc,
varloc = NULL,
nloc,
npolls = NULL,
dateloc = NULL,
invgamma = F,
v0 = NULL,
a0 = NULL,
b0 = NULL,
logit = F,
election_data,
cutoffs = c(-0.2, -0.1, -0.025, 0.025, 0.1, 0.2),
groupnames = c("Strong Red", "Red", "Lean Red", "Competitive", "Lean Blue", "Blue",
"Strong Blue")
)
|
poll_data |
a data frame containing all necessary datat |
stateloc |
the column number that contains the states for the poll |
proploc |
the set of columns that contain poll results that need to be normalized |
candidateloc |
the location of the candidate of interest |
varloc |
the location of the variance if it is provided |
nloc |
the location of the sample sizes |
npolls |
the number of polls to include, default is all polls |
dateloc |
the location of the date used to determine the last npolls |
invgamma |
an indicator if an inverse gamma model is fit |
v0 |
the hyperparameter for the shift parameter of a normal gamma distribution (mean, v0, a, b) |
a0 |
the hyperparameter for the a paramater of a normal gamma distribution (mean, v0, a, b) |
b0 |
the hyperparameter for the b parameter of a normal gamma distribution (mean, v0, a, b) |
logit |
if a logit transformation is done. |
election_data |
the election data used to make the categorization decisions |
cutoffs |
the cutoffs to assign the prior categories |
groupnames |
the names of the prior categories |
a dataframe with the following rows: State with the state, Posterior Mean with the posterior mean, Posterior Variance with the posterior variance, and Posterior Standard Deviation with the posterior standard deviation.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | require(politicaldata)
elect2008 = subset(pres_results , year == 2008)
elect2008$margin = elect2008$dem - elect2008$rep
elect2012 = subset(pres_results , year == 2012)
elect2012$margin = elect2012$dem - elect2012$rep
electdata = data.frame("state" = elect2008$state, "2008" = elect2008$margin, "2012" = elect2012$margin)
data(polls2016)
polls = polls2016[complete.cases(polls2016[, c(2, 3, 12)]), ]
head(polls)
nloc = which(colnames(polls2016) == "observations")
stateloc = which(colnames(polls) == "State")
dateloc = which(colnames(polls) == "end_date")
noniterativegaussianmodelprop(polls, stateloc, c(2,3), 3, nloc = nloc, election_data = electdata)
noniterativegaussianmodelprop(polls, stateloc, c(2,3), 3, dateloc = 9, nloc = nloc, election_data = electdata, npolls = 10)
noniterativegaussianmodelprop(polls, stateloc, c(2,3), 3, nloc = nloc, invgamma = TRUE, v0 = 1, a0 = 0.0001, b0=0.0001, election_data = electdata)
noniterativegaussianmodelprop(polls, stateloc, c(2,3), 3, nloc = nloc, invgamma = TRUE, v0 = 1, a0 = 0.0001, b0=0.0001, logit = T, election_data = electdata)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.