Predict

package
v0.0.0-...-58fb9df Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 1, 2018 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Pre-computed in historical_optimize.go
	INCUMBENT_ADVANTAGE_PVI = 0.017291230141716508 // Average margin advantage to incumbent over what PVI would expect
	FUNDRAISING_MULTIPLIER  = 0.023715954257800112 // Gain to generic ballot per doubling of fundraising over your opponent
	PAST_PVI_WEIGHT         = 0.25506964600999965  // Weight of previous PVI in PVI calculation
	OVERALL_PVI_WEIGHT      = 0.270927780068467    // Weight of generic ballot average in PVI calculation
	FUNDAMENTALS_WEIGHT     = 22.90325456831519    // Multiplier to beta/dirichlet params for fundamentals margin in forecast. Larger means more confident
)
View Source
var (
	// Pre-computed in historical_optimize.go
	RAND_POLL_SHIFT  = 0.017280740746056285  // Base per-poll error
	DAILY_POLL_SHIFT = 0.0026921961074848465 // Per-day per-poll average drift
	POLLING_WEIGHT   = 0.7995439702676344    // Multiplier to beta/dirichlet params for polling average in forecast. Larger means more confident
)
View Source
var (
	// Pre-computed in historical_optimize.go
	RAND_NATIONAL_SHIFT  = 0.036811891821249415   // Base national error
	DAILY_NATIONAL_SHIFT = 1.0850935968504596e-05 // Per-day average national drift
	RAND_RACE_SHIFT      = 0.028265923390389497   // Base per-race error
	DAILY_RACE_SHIFT     = 1.2133332224145488e-05 // Per-day per-race average drift

	N = 1 << 22 // Number of race simulations. Can go lower without much loss of accuracy, or higher if you want.
)
View Source
var Senate2016results = map[string][2]float64{
	"AL": {748709, 1335104},
	"AK": {36200, 138149},
	"AZ": {1031245, 1359267},
	"AR": {400602, 661984},
	"CA": {7542753, 4701417},
	"CO": {1370710, 1215318},
	"CT": {1008714, 552621},
	"FL": {4122088, 4835191},
	"GA": {1599726, 2135806},
	"HI": {306604, 92653},
	"ID": {188249, 449017},
	"IL": {3012940, 2184692},
	"IN": {1158947, 1423991},
	"IA": {549460, 926007},
	"KS": {379740, 732376},
	"KY": {813246, 1090177},
	"LA": {578750, 984625},
	"MD": {1659907, 972557},
	"MO": {1300200, 1378458},
	"NV": {521994, 495079},
	"NH": {354649, 353632},
	"NY": {5221945, 2009335},
	"NC": {2128165, 2395376},
	"ND": {58116, 268788},
	"OH": {1996908, 3118567},
	"OK": {355911, 980892},
	"OR": {1105119, 651106},
	"PA": {2865012, 2951702},
	"SC": {757022, 1241609},
	"SD": {104125, 265494},
	"UT": {301860, 760241},
	"VT": {192243, 103637},
	"WA": {745421, 381004},
	"WI": {1380335, 1479471},
}

Functions

func AdjustRaceError

func AdjustRaceError(alpha, beta, days float64) (a, b float64)

func CombinePolls

func CombinePolls(polling_data []map[string][]Poll) map[string][]Poll

func CombineRatings

func CombineRatings(rating_data []map[string][2]float64, weights []float64) map[string][2]float64

func GetBetasFromPVIs

func GetBetasFromPVIs(pvis map[string]float64) map[string][2]float64

func GetConcentrationParams

func GetConcentrationParams(polls []Poll, parties map[string]string, electionDate time.Time) map[string]float64

func GetPollWeights

func GetPollWeights(polls []Poll, parties map[string]string, electionDate time.Time, divUsed bool) []float64

func GetPollingRatings

func GetPollingRatings(polls map[string][]Poll, election_date time.Time) map[string][2]float64

func LoadExperts

func LoadExperts(ftype string, E *RaceMapExperts) (error, time.Time)

func LoadForecast

func LoadForecast(ftype string, F *Forecast) (error, time.Time)

func LoadFundamentals

func LoadFundamentals(ftype string, F *RaceFundamentals) (error, time.Time)

func LoadHistoricalData

func LoadHistoricalData() (polls []map[string][]Poll, results []map[string][2]float64, electionDates []time.Time, experts_ratings [][]map[string][2]float64, incumbents []map[string]string, expert_pvis [][]map[string]float64, fundraising []map[string]float64, elasticities []map[string]float64)

func LoadPolls

func LoadPolls(ftype string, P *RaceMapPolls) (error, time.Time)

func LoadPollsWeightBias

func LoadPollsWeightBias()

func LoadPollsWeightBiasCustom

func LoadPollsWeightBiasCustom()

Not used

func MergePolls

func MergePolls(A, B []Poll) []Poll

func MergeRaces

func MergeRaces(races map[string]struct{}, unchallenged_races [2]map[string]struct{}, ratings map[string]map[string][2]float64, election_date, now time.Time) (r map[string][2]float64, sources map[string]map[string][2]float64)

func MergeRatings

func MergeRatings(rating_data []map[string][2]float64) map[string][2]float64

Same as CombineRatings but no weights

func OptimizeHistorical

func OptimizeHistorical()

func OptimizeNationalShift

func OptimizeNationalShift()

func OptimizePVIs

func OptimizePVIs()

func OptimizePollShift

func OptimizePollShift()

func OptimizeRaceShift

func OptimizeRaceShift()

func OptimizeSources

func OptimizeSources()

func Prob

func Prob(races map[string][2]float64, days, rw float64) ([]float64, map[string]RaceProbability)

func SaveExperts

func SaveExperts(name string, experts RaceMapExperts)

func SaveForecast

func SaveForecast(name string, forecast Forecast)

func SaveFundamentals

func SaveFundamentals(name string, fundamentals RaceFundamentals)

func SavePolls

func SavePolls(name string, polls RaceMapPolls)

Types

type Expert

type Expert struct {
	Expert              string             `json:"expert"`
	ConcentrationParams map[string]float64 `json:"concentration_params"`
	Weight              float64            `json:"weight"`
}

func (Expert) Compare

func (A Expert) Compare(B Expert) bool

type Experts

type Experts []Expert

func (Experts) GetText

func (E Experts) GetText(name string) []string

func (Experts) Len

func (E Experts) Len() int

func (Experts) Less

func (E Experts) Less(i, j int) bool

func (Experts) Swap

func (E Experts) Swap(i, j int)

type Forecast

type Forecast struct {
	ShortForecast
	DemSeatsLow       int                        `json:"dem_seats_lo"`
	DemSeatsHigh      int                        `json:"dem_seats_hi"`
	RaceProbabilities map[string]RaceProbability `json:"race_probabilities"`
	SeatProbabilities []SeatProbability          `json:"seat_probabilities"`
	Past              []ShortForecast            `json:"past"`
}

func GenForecast

func GenForecast(seats []float64, rp map[string]RaceProbability, past Forecast, now time.Time) Forecast

func (Forecast) GetText

func (F Forecast) GetText(name string) []string

type Fundamental

type Fundamental struct {
	StepName string  `json:"step_name"`
	Value    float64 `json:"value"`
	Weight   float64 `json:"weight"`
}

type Fundamentals

type Fundamentals []Fundamental

func (Fundamentals) GetText

func (F Fundamentals) GetText(name string) []string

type MapExperts

type MapExperts map[string]Expert

func (MapExperts) GetText

func (E MapExperts) GetText(name string) []string

type Polls

type Polls []Poll

func (Polls) GetText

func (P Polls) GetText(name string) []string

func (Polls) Len

func (P Polls) Len() int

func (Polls) Less

func (P Polls) Less(i, j int) bool

func (Polls) Swap

func (P Polls) Swap(i, j int)

type RaceFundamentals

type RaceFundamentals map[string]Fundamentals

func GetFundamentalsRatings

func GetFundamentalsRatings(incumbents map[string]string, fundraising_ratios map[string]float64, pvi_estimates []map[string]float64, pvi_weights []float64, pvi_names []string, elasticities map[string]float64, overall_pvi float64) (map[string][2]float64, RaceFundamentals)

type RaceMapExperts

type RaceMapExperts map[string]MapExperts

func CombineExpertRatings

func CombineExpertRatings(rating_data []map[string][2]float64, weights []float64, names []string) (map[string][2]float64, RaceMapExperts)

type RaceMapPolls

type RaceMapPolls map[string][]Poll

func (RaceMapPolls) GetText

func (P RaceMapPolls) GetText(name string) []string

type RacePoll

type RacePoll struct {
	Poll
	Race string `json:"race"`
}

type RacePolls

type RacePolls []RacePoll

func (RacePolls) GetText

func (P RacePolls) GetText(name string) []string

func (RacePolls) Len

func (P RacePolls) Len() int

func (RacePolls) Less

func (P RacePolls) Less(i, j int) bool

func (RacePolls) Swap

func (P RacePolls) Swap(i, j int)

type RaceProbabilities

type RaceProbabilities []RaceProbability

func (RaceProbabilities) Len

func (R RaceProbabilities) Len() int

func (RaceProbabilities) Less

func (R RaceProbabilities) Less(i, j int) bool

func (RaceProbabilities) Swap

func (R RaceProbabilities) Swap(i, j int)

type RaceProbability

type RaceProbability struct {
	ShortRaceProbability
	Race    string                 `json:"race"`
	Sources map[string][2]float64  `json:"sources"`
	Past    []ShortRaceProbability `json:"past,omitempty"`
}

func (*RaceProbability) Fix

func (R *RaceProbability) Fix(sources map[string][2]float64)

func (RaceProbability) GetText

func (R RaceProbability) GetText(name string) []string

type SeatProbabilities

type SeatProbabilities []SeatProbability

func (SeatProbabilities) Len

func (S SeatProbabilities) Len() int

func (SeatProbabilities) Less

func (S SeatProbabilities) Less(i, j int) bool

func (SeatProbabilities) Swap

func (S SeatProbabilities) Swap(i, j int)

type SeatProbability

type SeatProbability struct {
	DemSeats    int     `json:"dem_seats"`
	Probability float64 `json:"probability"`
}

type ShortForecast

type ShortForecast struct {
	Date                   time.Time `json:"date"`
	DemMajorityProbability float64   `json:"dem_maj_prob"`
	DemSeatsExpected       float64   `json:"dem_seats_exp"`
}

type ShortRaceProbability

type ShortRaceProbability struct {
	Date                time.Time          `json:"date"`
	DemWinProbability   float64            `json:"dem_win_prob"`
	DemVoteExpected     float64            `json:"dem_vote_exp"`
	DemVoteLow          float64            `json:"dem_vote_lo"`
	DemVoteHigh         float64            `json:"dem_vote_hi"`
	ConcentrationParams map[string]float64 `json:"concentration_params"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL