An example for formatting model comparisons in R Markdown:

MODEL A: \(Outcome_i = \beta_0 + \beta_1Var1_i + \beta_2Var2_i + \epsilon_i\)

MODEL C: \(Outcome_i = \beta_0 + \epsilon_i\)

\(H_0\): \(\beta_1 = \beta_2 = 0\)

Question 1

Pollsters are hired to do an analysis of the latest approval ratings for a candidate for state senator. Using a questionnaire approach, they measure scores of APPROVAL ratings for this candidate from a sample of 300 people from around the state. Once they have collected their data, they hire you to do the analysis which would tell them whether the candidate should be “aiming his pitch” at certain voter groups in the 4 months remaining until election day. The variables/groups of concern are: SEX (female or male), ETHNICITY (minority or not-minority), and EDUCATION LEVEL (high school, some college, or college degree). Give 1) Models A & C for the following questions and 2) write out the null hypothesis. Make sure to define your variables (e.g. instead of C1, C2… write sex*eth or Ed_lin).

Use the same model A for all questions.

  1. Define a set of orthogonal codes for the factors (How many groups? How many codes do you need?). Define the codes for each factor in isolation (e.g. Factor 1: -1, 0, +1; Factor 2: -1 +1 etc…), as well as the orthogonal set of contrast codes.

SEX: sex (1 contrast) Female=1, Male= -1

ETHNICITY: eth (1 contrast) Minority= 1, Non-minority= -1

EDUCATION: ed (2 orthogonal contrasts):
Ed_lin: HS: -1, Some College (SC): 0, College Degree (CD): -1 Ed_quad: HS: -1, SC: +2, CD: -1

  1. Do more educated people report greater approval (i.e., is there a linear effect)?

Model A: \(APPROVAL_i = \beta_0 + \beta_1SEX_i + \beta_2eth_i + \beta_3ed\_lin + \beta_4edu\_quad + \beta_5(sex*eth)_i + \beta_6(sex*edu\_lin) + beta_7(sex*edu\_quad) + \beta_8(eth*edu\_lin) + \beta_9(eth*edu\_quad) + \beta_10(sex*ethnicity*edu\_lin)_i + \beta_11(sex*ethnicity*edu\_quad) +\epislon_i\)

Model C: \(APPROVAL_i = \beta_0 + \beta_1SEX_i + \beta_2eth_i + \beta_4edu_quad + \beta_5(sex*eth)_i + \beta_6(sex*edu_lin) + beta_7(sex*edu_quad) + \beta_8(eth*edu_lin) + \beta_9(eth*edu_quad) + \beta_10(sex*ethnicity*edu_lin)_i + \beta_11(sex*ethnicity*edu_quad) +\epislon_i\)

Null: \(\beta_3 = 0\)

  1. Is there a quadratic effect of education on approval?

Model A: \(APPROVAL_i = \beta_0 + \beta_1SEX_i + \beta_2eth_i + \beta_3ed\_lin + \beta_4edu\_quad + \beta_5(sex*eth)_i + \beta_6(sex*edu\_lin) + beta_7(sex*edu\_quad) + \beta_8(eth*edu\_lin) + \beta_9(eth*edu\_quad) + \beta_10(sex*ethnicity*edu\_lin)_i + \beta_11(sex*ethnicity*edu\_quad) +\epislon_i\)

Model C: \(APPROVAL_i = \beta_0 + \beta_1SEX_i + \beta_2eth_i + \beta_3ed\_lin + \beta_5(sex*eth)_i + \beta_6(sex*edu\_lin) + beta_7(sex*edu\_quad) + \beta_8(eth*edu\_lin) + \beta_9(eth*edu\_quad) + \beta_10(sex*ethnicity*edu\_lin)_i + \beta_11(sex*ethnicity*edu\_quad) +\epislon_i\)

Null: \(\beta_4 = 0\)

  1. Does the tendency for more educated people to report greater approval depend on the respondent’s ethnicity?

Model A: \(APPROVAL_i = \beta_0 + \beta_1SEX_i + \beta_2eth_i + \beta_3ed\_lin + \beta_4edu\_quad + \beta_5(sex*eth)_i + \beta_6(sex*edu\_lin) + beta_7(sex*edu\_quad) + \beta_8(eth*edu\_lin) + \beta_9(eth*edu\_quad) + \beta_10(sex*ethnicity*edu\_lin)_i + \beta_11(sex*ethnicity*edu\_quad) +\epislon_i\)

Model C:\(APPROVAL_i = \beta_0 + \beta_1SEX_i + \beta_2eth_i + \beta_3ed\_lin + \beta_4edu\_quad + \beta_5(sex*eth)_i + \beta_6(sex*edu\_lin) + beta_7(sex*edu\_quad) + \beta_9(eth*edu\_quad) + \beta_10(sex*ethnicity*edu\_lin)_i + \beta_11(sex*ethnicity*edu\_quad) +\epislon_i\)

Null: \(\beta_8 = 0\)

  1. Is there any evidence that the effects of education (linear or quadratic) depend on sex?

Model A:\(APPROVAL_i = \beta_0 + \beta_1SEX_i + \beta_2eth_i + \beta_3ed\_lin + \beta_4edu\_quad + \beta_5(sex*eth)_i + \beta_6(sex*edu\_lin) + beta_7(sex*edu\_quad) + \beta_8(eth*edu\_lin) + \beta_9(eth*edu\_quad) + \beta_10(sex*ethnicity*edu\_lin)_i + \beta_11(sex*ethnicity*edu\_quad) +\epislon_i\)

Model C:\(APPROVAL_i = \beta_0 + \beta_1SEX_i + \beta_2eth_i + \beta_3ed\_lin + \beta_4edu\_quad + \beta_5(sex*eth)_i + \beta_8(eth*edu\_lin) + \beta_9(eth*edu\_quad) + \beta_10(sex*ethnicity*edu\_lin)_i + \beta_11(sex*ethnicity*edu\_quad) +\epislon_i\)

Null: \(\beta_6 = \beta_7 = 0\)

  1. Is the interaction of sex and the linear effects of education equivalent for minorities and non-minorities?

Model A: \(APPROVAL_i = \beta_0 + \beta_1SEX_i + \beta_2eth_i + \beta_3ed\_lin + \beta_4edu\_quad + \beta_5(sex*eth)_i + \beta_6(sex*edu\_lin) + beta_7(sex*edu\_quad) + \beta_8(eth*edu\_lin) + \beta_9(eth*edu\_quad) + \beta_10(sex*ethnicity*edu\_lin)_i + \beta_11(sex*ethnicity*edu\_quad) +\epislon_i\)

Model C: \(APPROVAL_i = \beta_0 + \beta_1SEX_i + \beta_2eth_i + \beta_3ed\_lin + \beta_4edu\_quad + \beta_5(sex*eth)_i + \beta_6(sex*edu\_lin) + beta_7(sex*edu\_quad) + \beta_8(eth*edu\_lin) + \beta_9(eth*edu\_quad) + \beta_11(sex*ethnicity*edu\_quad) +\epislon_i\)

Null: \(\beta\_10 = 0\)

Question 2

From Jaccard & Becker, 1990, p. 435. Social psychologists have studied extensively the variables that influence the ability of a speaker to persuade an audience to take the speaker’s position on an issue. One important factor influencing the amount of attitude change a speaker can generate is the discrepancy between the position advocated by the speaker relative to the position of the audience. Up to a point, the more discrepant the speaker’s position, the greater the attitude change that will result. However, if the speaker’s position becomes too discrepant, the speaker loses credibility and the persuasiveness of the message decreases. It has been hypothesized that the relationship between message discrepancy and attitude change differs depending on the experience of the speaker. According to this perspective, speakers with high expertise can take much more discrepant positions than speakers with low expertise and still obtain large amounts of attitude change. As an example of how this proposition could be tested, consider the following hypothetical experiment.

College students evaluated the quality of a passage of poetry on a 21-point scale and then listened to a recorded message concerning this passage that was either slightly discrepant, moderately discrepant or highly discrepant from the subjects’ initial quality rating. Additionally, the message was attributed to either an expert or a non-expert. After listening to the message, subjects re-rated the poetry. The dependent variable is the absolute value of the change in ratings from pre to post. The following mean values were obtained for each condition.

The within-group, or ERROR, sum of squares is 12 for these data, and there are 5 observations per cell for a total of 30 observations. The contrasts that were used to code Speaker Expertise and Message Discrepancy are also given below.

  1. Complete the source table below. Show your work as necessary / for partial credit!

SUM OF SQUARES

total SS = 80 + 12= 92

numerators = (sum of contrast codes * group means)^2 denominators = (contrast codes and sum)^2 / n per group

expertise SS = (13 + 15 + 15 + 11 - 13 - 11)^2 /((1^2 + 1^2 + 1^2 + (-1)^2 + (-1)^2 + (-1)^2/5) expertise SS= 53.333

discrepancy linear SS= (15 + 11 + 05 + 03 + -13 -11)2/((12 + 1^2 + 0^2 + 0^2 + (-1)^2 + (-1)^2)/5) discrepancy linear SS= 5

overall discrepancy SS =15+5 (discrepancy linear and quadratic SS)= 20

expertise* quad expertise SS= ((1-13) + (125) (1-15) +(-123) + (-1-11))2/(((1-1)^2 + (12)2 + (1-1)^2 + (-12)^2 +(-1*-1)^2)/5) = 1.667

overall interaction SS = (epertise* discrepancy linear)+ (expertise* quad discrepancy quad) overall interaction SS = 5 + 1.667 = 6.667

53.333 + 20 + 6.667 = 92

MEAN SQUARES

SS = MS when df= 1

divide SS by df for other MS in table

overall discrepancy MS= 20/2 = 10

Interaction MS= 6.667/2 = 3.334

error MS = 24/12 = 2

F STAT

F= MS/ MSerror for each row

MSerror= 0.5

PRE

PRE= Effect SS / (Effect SS + SSerror)

# expertise effect 
pf(106.667, 1, 24, lower.tail = FALSE)
## [1] 2.607577e-10
#overall discrepancy p 
pf(20, df1 = 2, df2 = 24, lower.tail = FALSE)
## [1] 7.733484e-06
#linear discrepancy 
pf(10, 1, 24, lower.tail = FALSE)
## [1] 0.00420732
#quad discrepancy 
pf(30, 1, 24, lower.tail = FALSE)
## [1] 1.248047e-05
#interaction 
pf(6.667, df1 = 2, df2 = 24, lower.tail = FALSE)
## [1] 0.004980588
#exp * linear discrepancy
pf(10, 1, 24, lower.tail = FALSE)
## [1] 0.00420732
#exp * quad discrepancy
pf(3.333, 1, 24, lower.tail = FALSE)
## [1] 0.08037232
  1. Write a summary paragraph, including a (simple) graph, that addresses the questions raised in the introduction to this problem. You can look at some of the previous code we’ve gone through in class for graphing examples, but it’s up to you to find an informative way to show the data. This should read like something you might find in a published manuscript (there are some examples in the text that might help guide you in terms of what should be included).

Participants’ changes in message quality ratings differed based on both speaker expertise and degree in discrepancy in the messages themselves.On average, hearing from speakers with high expertise produced larger changes in quality rating (M= 4.333)Compared to speakers with low expertise (M=1.667, F= 106.667, PRE= 0.580, p<0.05). Discrepancy showed a quadratic relationship with change in quality rating, with moderate discrepancies producing the largest rating changes (M=4) and low and high discrepancies produced smaller shifts. The interaction between expertise and discrepancy shows the same pattern. High-expertise speakers are most persausive under moderate discrepancy, while low expertise speakers produced consistently small effects across discrepancy levels. The graph below plots mean change in quality ratings on the y-axis and discrepancy levels on the x axis with seperate lines for the low and high speaker expertise. The line for high expertise shows a quadratic relationship, with the ratings increasing and then leveling off at moderate and high discrepancy. The low expertise line shows an increase to moderate discrepancy and decrease to high discrepancy. The graph highlights that both high speaker expertise and moderate discrepancy produced the greatest impact of persausion.

library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(ggplot2)

#use group means to make data for graph 
hw10b = tibble(
  expertise = rep(c(-1, 1), each= 15),
  discrepancy_lin = rep(-1:1, each = 5, times = 2),
  discrepancy_quad = rep(c(-1, 2, -1), each = 5, times = 2),
  rating = rep(c(1,3,1,3,5,5), each = 5)
) |>
  
# code factors 
  mutate(
    expertise = factor(expertise, c(-1, 1), c("Low", "High")),
    discrepancy= factor(discrepancy_lin, c(-1:1), c("Low", "Moderate", "High"))
  )
#make graph
ggplot(hw10b, aes(discrepancy, rating, color= expertise, group = expertise)) +
  geom_point() +
  geom_line()+
  labs(
    x= "Discrepancy",
    y= "Change in Rating",
    color = "Speaker Expertise"
  )

Cell Means

Cell means for change in ratings from pre to post:

Message Discrepancy High Speaker Expertise Low Speaker Expertise
Low 3 1
Moderate 5 3
High 5 1

Note

The tables above and below are markdown tricks you may have noticed in some homework assignments last semester. This syntax renders as a nice looking table when knitted. It is limited in functionality, but can work in basic ways. See this link for a rundown. And this tool might also be useful.

Definition of Expertise and Discrepancy Contrast Codes

Expertise Code: +1 if High; -1 if Low

Discrepancy Linear Code: +1 if High; 0 if Moderate; -1 if Low

Discrepancy Quadratic Code: -1 if Low or High; +2 if Moderate

Source Table

To complete this source table, add text in the blank cells. It can help to add or remove spaces to keep everything in line, but this will render whether or not the pipes line up. If you don’t like working with the table in this format, you can also fill out the table in “Visual” instead of “Source” mode; you can move between these modes in the top left corner of your code window.

b df SS MS F* p PRE
Model NA 5 80 16 32 p<.05 0.870
Expertise 1 53.333 53.333 106.667 p<0.001 0.816
Discrepancy NA 2 20 10 20 p<0.005 0.625
linear 1 5 5 10 p<0.05 0.294
quadratic .5 1 15 15 30 p<.05 0.556
Interaction NA 2 6.667 3.334 6.667 p=0.053 0.357
Exp*lin .5 1 5 5 10 p<.05 0.294
Exp*quad 1 1.667 1.667 3.333 p=0.08 0.122
Error NA 24 12 0.5 NA NA NA
Total NA 29 92 NA NA NA NA