library(wooldridge)
# Load the VOTE1 dataset
data("vote1")
This part requires interpreting coefficients after estimating the model.
# Estimate the model with interaction between expendA and expendB
model <- lm(voteA ~ prtystrA + expendA + expendB + I(expendA * expendB), data = vote1)
# Display the summary to report results and check if the interaction term is significant
summary(model)
##
## Call:
## lm(formula = voteA ~ prtystrA + expendA + expendB + I(expendA *
## expendB), data = vote1)
##
## Residuals:
## Min 1Q Median 3Q Max
## -28.9999 -8.7632 -0.1726 8.2310 29.7325
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 3.212e+01 4.591e+00 6.995 5.99e-11 ***
## prtystrA 3.419e-01 8.799e-02 3.886 0.000146 ***
## expendA 3.828e-02 4.960e-03 7.718 1.00e-12 ***
## expendB -3.172e-02 4.588e-03 -6.915 9.32e-11 ***
## I(expendA * expendB) -6.629e-06 7.186e-06 -0.923 0.357584
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 11.13 on 168 degrees of freedom
## Multiple R-squared: 0.5708, Adjusted R-squared: 0.5606
## F-statistic: 55.86 on 4 and 168 DF, p-value: < 2.2e-16
expendA
and Estimated Effect of
Additional Spending by Candidate B# Calculate the average of expendA
avg_expendA <- mean(vote1$expendA, na.rm = TRUE)
avg_expendA
## [1] 310.611
# Set expendA at 300 and estimate the effect of an additional $100,000 on expendB
expendA_val <- 300
expendB_val <- 100 # Assuming an additional $100,000 means expendB + 100
new_data <- data.frame(prtystrA = mean(vote1$prtystrA, na.rm = TRUE),
expendA = expendA_val,
expendB = expendB_val,
expendA_expendB = expendA_val * expendB_val)
# Predict voteA with new values
predicted_effect <- predict(model, new_data)
predicted_effect
## 1
## 57.24437
expendB
at 100 and Estimate the Effect of
Change in expendA
# Fix expendB at 100, and check effect of expendA increasing by 100
expendB_fixed <- 100
expendA_change <- 100
# Predict with expendA + 100
new_data_expendA <- data.frame(prtystrA = mean(vote1$prtystrA, na.rm = TRUE),
expendA = expendA_val + expendA_change,
expendB = expendB_fixed,
expendA_expendB = (expendA_val + expendA_change) * expendB_fixed)
# Predict with expendA unchanged
new_data_original <- data.frame(prtystrA = mean(vote1$prtystrA, na.rm = TRUE),
expendA = expendA_val,
expendB = expendB_fixed,
expendA_expendB = expendA_val * expendB_fixed)
# Calculate difference in predictions
predicted_diff <- predict(model, new_data_expendA) - predict(model, new_data_original)
predicted_diff
## 1
## 3.761799
This involves calculating the partial derivative of
voteA
with respect to expendB
given specific
values.
# Define expendA = 300 and expendB = 0 for calculation
expendA_val <- 300
expendB_val <- 0
# Calculate the partial effect (derivative with respect to expendB)
partial_effect <- coef(model)["expendB"] + coef(model)["I(expendA * expendB)"] * expendA_val
partial_effect
## expendB
## -0.03371269