getpriorassign: Prior Assignment This function completely fits the Iterative...

Description Usage Arguments Value Examples

View source: R/priorgrouping.R

Description

Prior Assignment 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.

Usage

1
2
3
4
5
6
7
getpriorassign(
  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"),
  weights = NULL
)

Arguments

election_data

the election data in df form. The first column must contain the name of that state.

cutoffs

the cutoffs used to split the data into the categories

groupnames

labels for the categories

weights

optional weights for a weighted average of the columns

Value

a data frame with the state in one column and the assignment in the other.

Examples

1
2
3
4
5
6
7
8
9
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
data1 = data.frame("state" = elect2008$state, "2008" =  elect2008$margin, "2012" = elect2012$margin)
getpriorassign(data1)
weight = c(0.25,0.75)
getpriorassign(data1 , weights = weight)

balexanderstats/bayesurvey documentation built on Sept. 20, 2020, 11:40 a.m.