[The Homework Assignments]
Homework Assignment 8

The purpose of this assignment is to give you practice in doing (and realizing why you may need to do) weighted least squares regression. Recall a purpose of weighted least squares regression is to allow for the data values to have different levels of precision. This is important when the data are generated from cluster processes, such as in voting. People who live near each other tend to vote similarly. When votes are aggregated, the vote counts are not Binomially distributed; the votes (Bernoulli random variables) are not independent.

 

A Ruritanian Update

[a new flag] Our patron, King Rudolf II, died. His grandson, Rudolph V, ascended the Leonine Throne. However, instead of continuing the autocracy, King Rudolph V decided to introduce democracy to the people. Whether or not this was done to increase the probability that Ruritania joined the European Union depends on whom you ask. Regardless, the first (allegedly) free and fair elections were held just one month into Rudolph’s reign. The election pitted the Král a Země party (a conservative party that strongly supports the monarchy) against several other parties, including a the republican (anti-monarchy) Republikánská Strana party.

According to official results, the Král a Země party won handily. Ivanović, the leader of the Republikánská Strana party, gracefully conceded on election night just before taking a vacation in Copenhagen. No one in the government suggested the presence of electoral fraud. The state-run newspaper, Řurité Noviny, lauded the outcome of the election and the maturity of the voters:

Voliči jsou splatné v jejich demokracii. Mají zru šil osobní prospěch a hlasovali pro nejlepší budoucnost této země. Ať žije Rudolph!

Regardless of this praise, Ruritania’s exile community in Denmark claimed the election was fraudulent and that the government stuffed many of the ballot boxes, thus ensuring the Král a Země party’s win.

To show the world that Ruritania is dedicated to democracy, King Rudolph V hired us to determine if there is evidence that the election was unfair in favor of Král a Země. Because of the data available, we are able to do an important test. Election theory tells us that if the election was unfairly in favor of a candidate then the correlation between the invalidation rate and the candidate support rate would be significant and negative.

And so, that will be our goal: Analyze the Ruritanian parliamentary election of 2024.

 

The Assignment

For this assignment, use the xr2024parl dataset located in the expected place:

https://rur.kvasaheim.com/data/xr2024parl.csv

This dataset contains the official results from the 2024 parliamentary election in Ruritania held among four parties and some independent candidates. The numbers refer to counts. There is no need to adjust the models below beyond what I request.
 

  1. Create the variable pInv as the ratio of the rejected to the total:
  2. pInv = INVALID/TOTAL

    This variable is the invalidation rate. Similarly, create the variable pCnd as the ratio of the number of votes for the Král a Země party members to the number of valid votes:

    pCnd = KaZ/(TOTAL-INVALID)

    This variable is the party support rate. Fit a simple linear regression model using ordinary least squares regression with the invalidation rate being the dependent variable and the party support rate being the explanatory variable. Name this model modA1. Provide the regression table and briefly interpret the results (a sentence or so).

  3. Now, create the variable lInv, which is the logit of the pInv variable:
  4. lInv = logit(pInv)

    Fit this logit model, modA2, with the logit of the invalidation rate as the dependent variable and the candidate support rate as the independentvariable. Again, use ordinary least squares regression. Provide the regression table and briefly interpret the results.

  5. Next, fit the logit model using weighted least squares (WLS) regression. Weight on the square root of the number of votes cast (TOTAL). Call this model modA3. Provide the regression table and briefly interpret the results.
     
  6. Create one graphic with the data shown and the regression curves for each of the models you fit. Use different colors for the curves. Provide a legend so that the reader knows which color corresponds to which model.
     
  7. For each of your models, predict the invalidation rate for a division in which the support for Král a Země is 60%. Also give 95% confidence intervals in all models.
     
  8. Finally, let us do what we were hired to do. Is there evidence of unfairness in this election? If so, does it favor Král a Země or not? Explain your answer using evidence and a nice-looking graphic. Make sure you are thorough and make sense.

 

Do Not Forget

Do not forget to include your code in the appendix. I should be able to run your code and achieve the same results as you.

 

This page was last modified on 3 January 2025.
All rights reserved by Ole J. Forsberg, PhDd, ©2008–2025. No reproduction of any of this material is allowed without explicit written permission of the copyright holder.