Modeling US Presidential Election w/ Polling

Hi @AlexAndorra, I’ve picked back up my model and wrote it up in a blog post here. I have been trying to implement your suggestion of using a multinomial and also doing an HGSP. I’ve been trying for a few days but haven’t been able to get either to work, maybe I am missing something obvious. :slight_smile: I gave you a citation at the bottom.

For me the multinomial is the most pressing, just because of the implications in the correlations between outputs. Right now I have the following binomial repeated thrice:

    dem_vote = pm.Binomial(
        "dem_vote",
        p = dem_polling,
        n = df["sample_size"],
        observed = df['sample_size'] * df['DEM'],
        dims = "observation",
    )

How can I re-write this for a multi-nomial? I tried using the three polling vars and stacking them to make an array for “p” but I keep getting a shape issue.

Here is my random walk component that should be re-written for HGSP, it’s also repeated for ‘gop’ and for ‘oth’ as well as ‘dem’.

    epsilon = 1e-6

    dem_sigma       = pm.HalfNormal("dem_sigma", sigma=0.1) + epsilon
    dem_rho         = pm.Normal("dem_rho", mu=0, sigma=0.7)
    dem_ar          = pm.AR("dem_ar",
                            rho=[dem_rho] * 7,
                            sigma=dem_sigma,
                            init_dist=pm.Normal.dist(mu=0, sigma=0.05),
                            dims="day"
                           )
    dem_sigma_rw    = pm.HalfNormal("dem_sigma_rw", sigma=0.1) + epsilon
    dem_random_walk = pm.GaussianRandomWalk("dem_random_walk",
                                            sigma=dem_sigma_rw,
                                            init_dist=pm.Normal.dist(mu=0, sigma=0.3),
                                            dims="day")
    dem_day_effect  = pm.Deterministic("dem_day_effect", dem_ar + dem_random_walk, dims="day")

Thanks!

2 Likes