addcategorytopollsmargin: Title

Description Usage Arguments Examples

View source: R/priorgrouping.R

Description

Title

Usage

1
2
3
4
5
6
7
8
9
addcategorytopollsmargin(
  poll_data,
  marginloc,
  stateloc,
  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")
)

Arguments

poll_data
marginloc
stateloc
election_data
cutoffs
groupnames

Examples

 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)
set.seed(16)
data(polls2016)
poll1 = polls2016[sample(1:nrow(polls2016), 500) ,]
poll2 = polls2016[sample(1:nrow(polls2016), 500), ]
propnormpolls1 = propnormdf(poll1, c(2,3))
propnormpolls2 = propnormdf(poll2, c(2,3))
polls2016$margin = polls2016$Trump - polls2016$Clinton
marginloc = which(colnames(polls2016) == "margin")
stateloc = which(colnames(polls2016) == "State")
addcategorytopollsmargin(polls2016, marginloc = marginloc, stateloc = stateloc, election_data = electdata)

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