weight_polls {nzelect} | R Documentation |
Weight polls
Description
Create a vector of weights to use in calculating a weighted average
Usage
weight_polls(polldates, n = rep(1, length(polldates)), method = c("pundit",
"curia"), refdate = Sys.Date(), electiondate = as.Date("2017-09-23"))
Arguments
polldates |
a vector of dates of polls. |
n |
a vector of sample sizes of polls. |
method |
which weighting method to use; either that used in 2017 by Curia or Pundit (two New Zealand poll aggregators). |
refdate |
date against which to compare polling dates (both methods give more weight to more recent polls). |
electiondate |
date of the next election (the Curia weighting method gives more weight to polls close to the election). |
Details
This function is experimental and so far it has not been possible to match published results. Use with caution.
This function is to facilitate reproduction of existing poll aggregation methods.
Both methods provide weights proportional to the sample sizes.
The Pundit Poll of Polls states its method is an adaptation of that used by fivethirtyeight. It gives polls a half life of 30 days, so a poll that is 120 days old gets 0.125 the weight of one conducted today.
The Curia method gives weight of 1 to all polls that are seven or less days old; 0 to polls older than 38 days; and a linear interpolation for inbetween. Note that this method gives zero weight to many older surveys that would get a weight in the pundit method.
Caution - as at March 2017, this function had failed to exactly replicate results on the webpages of Curia and Pundit.
Value
a vector of weights, adding up to one, for use in calculating a weighted average of opinion polls
References
http://www.curia.co.nz/methodology/ http://www.pundit.co.nz/content/poll-of-polls
Examples
polldates <- tail(unique(polls$MidDate), 20)
weight_polls(polldates, method = "curia", refdate = as.Date("2017-09-22"))
weight_polls(polldates, method = "pundit", refdate = as.Date("2017-09-22"))