Run prediction for one vote
predict_single_vote.Rd
This function can be used to predict the outcome of one vote based on a trained model, generated by using the plausi::train_prediction_model(). To create replicable examples, use the function together with set.seed().
Arguments
- model
A trained model, generated using plausi::train_prediction_model().
- testdata
Dataset on which the prediction should be run. The data must contain all columns of the training data of the model
model$trainingData
.
Examples
# Set seed for reproducibility
set.seed(42)
test_model <- train_prediction_model("Eidg1", vote_data, to_exclude_vars = "Kant1")
#> Loading required package: ggplot2
#> Loading required package: lattice
predict_single_vote(test_model, vote_data)
#> # A tibble: 171 × 5
#> gemeinde v_gemwkid pred real vorlage
#> <chr> <dbl> <dbl> <dbl> <chr>
#> 1 Adlikon 21 23.4 21.5 Eidg1
#> 2 Adliswil 131 47.4 48.3 Eidg1
#> 3 Aesch 241 30.0 30.9 Eidg1
#> 4 Aeugst am Albis 1 33.2 31.5 Eidg1
#> 5 Affoltern am Albis 2 40.7 39.8 Eidg1
#> 6 Altikon 211 28.9 29.8 Eidg1
#> 7 Andelfingen 30 33.0 32.1 Eidg1
#> 8 Bachenbülach 51 38.3 39.9 Eidg1
#> 9 Bachs 81 31.4 30.5 Eidg1
#> 10 Bäretswil 111 32.6 33.3 Eidg1
#> # ℹ 161 more rows