library(tidyverse)library(DT)library(pander)library(readr)library(plotly)library(car)library(dplyr)library(data.table)library(lattice)EnvyData <-read_csv("../../data/EnvyData.csv")#If this code does not work: #Use the top menu from RStudio's window to select "Session, Set Working Directory, To Source File Location", and then play this R-chunk into your console to read the EnvyData data into R. ## In your Console run View(HSS) to ensure the data has loaded correctly.
The PSYCH 111 students were asked to imagine 5 different scenarios as either just after the event (Past) or just before the event occurred (Future). The scenarios were participants own dream vacation, dream date, dream house, dream job, and dream car. They were asked to imagine their own close friend having this scenario. In a 5 item 7 point likert scale survey for each of the 5 scenarios the students reported their responses. We received 235 respondents.
I am presenting this html with a data analysis for my fellow research teammates. I’m hoping to gather additional insight into the data we collected. Unfortunately, our original demographics of marital status and class standing were replaced with religious affiliation due to a different group’s lack of foresight. I will not be including any ANOVA of the religious affiliation demographic because there were only 3 responses from 3 different groups that do not identify as a latter-day saint.
I have included two ANOVA analyses on gender and age groups as listed below.
Using an independent samples t.test the true differences in the means will be tested. First, the normality of the distributions is shown using Q-Q Plots.
Q-Q Plots
Show the code
car::qqPlot(`Total Average`~ Tense, data = Envy, main ="Q-Q Plot of Total Envy in Future or Past")
Questions & Hypotheses
Is there a difference in reported envy of a dream vacation in the past or the future?
plot_ly(data = Envy, y =~Date_Avg,x =~Tense,type ="box", color =~Tense,colors =c("deeppink2","deeppink4")) %>%layout(title ="Friend Gets Dream Date: Happened or About To", yaxis =list(title ="Average Date Envy Score"),xaxis =list(title ="Group by Tense") )
plot_ly(data = Envy, y =~House_Avg,x =~Tense,type ="box", color =~Tense,colors =c("goldenrod1","goldenrod3")) %>%layout(title ="Friend Gets Dream House: Happened or About To", yaxis =list(title ="Average House Envy Score"),xaxis =list(title ="Group by Tense") )
# Load the plotly librarylibrary(plotly)# Assume your dataset 'Envy' is already loaded# Replace the below code with your actual dataset as necessary# Generate the plotly boxplotfig <-plot_ly(data = Envy,x =~interaction(Tense, Gender, sep =" * "),y =~`Total Average`,type ="box",color =~interaction(Tense, Gender),colors =c("hotpink1", "hotpink3", "royalblue1", "royalblue3"))# Customize the layoutfig <- fig %>%layout(title ="The Enviousness of Girls and Guys",xaxis =list(title =".", tickangle =45),yaxis =list(title ="Total Average"))# Display the plotfig
A closer look at the tenses and the overal envy scores between genders.
Show the code
xyplot(`Total Average`~as.factor(Tense), data = Envy, groups=Gender, type=c("p","a"), auto.key=TRUE, main="Females are More Envious than Males", ylab="Average Envy", xlab="Grouped by Tense")
Now to see the mean scores as represented in the plots and table below
Show the code
# Interaction plot to visualize group differencesinteraction.plot(Envy$Tense, Envy$Gender, Envy$`Total Average`, col =c("blue", "red"), legend =TRUE, xlab ="Tense", ylab ="Total Average")
Show the code
library(dplyr)library(ggplot2)# Assuming 'Envy' dataset exists and has a 'Gender' and 'Total Average' column.means <- Envy %>%group_by(Gender) %>%summarize(Mean =mean(`Total Average`, na.rm =TRUE), .groups ='drop')ggplot(means, aes(x = Gender, y = Mean, fill = Gender)) +geom_col(position ="dodge", color ="white") +scale_fill_manual(values =c("hotpink", "royalblue")) +labs(title ="Envy between Guys and Girls", x ="Gender", y ="Mean Total Average") +theme_minimal()
Show the code
aggregate(Envy$`Total Average`, by =list(Envy$Tense, Envy$Gender), mean)
Group.1 Group.2 x
1 Future Female 4.293333
2 Past Female 4.344471
3 Future Male 3.818824
4 Past Male 3.805000
We will run a post-hoc to view the significant findings in comparing the envy of the genders. A Scheffé correction is appropriate due to the unequal sample sizes of the between subjects design.
H_0: \text{The effect of age on the average envy score is consistent across both tenses}
H_a: \text{The effect of age on the average envy score differs across the tenses.}
Significance level is
\alpha = 0.10
Show the code
EnvyAge <- EnvyData %>%mutate(Age =case_when( Age ==18~"18", Age ==19~"19", Age ==20~"20", Age ==21~"21", Age ==22~"22", Age >=23& Age <=30~"23-30", Age >=31~"31+" ))EnvyAge.aov <-aov(`Total Average`~ Tense +as.factor(Age) + Tense:as.factor(Age), data = EnvyAge)summary(EnvyAge.aov) %>%pander()
The below boxplot demonstrates the ages and their envy
Show the code
boxplot(`Total Average`~ Age, data = EnvyAge, col =c("salmon1", "lightgoldenrod1", "seagreen1", "paleturquoise1", "skyblue1", "thistle1", "plum1"),main ="The Enviousness of the Ages",xlab =".",ylab ="Total Average",las =3)
I also want to see how the ages are represented in the past and future envy.
Show the code
xyplot(`Total Average`~as.factor(Tense), data = EnvyAge, groups=Age, type=c("p","a"), auto.key=TRUE, main="Enviousness of the Ages", ylab="Average Envy", xlab="Grouped by Tense")
I noticed that the 20 and 22 year olds had the most interesting data. Theirs appears to be most closely aligned with the original hypothesis that anticipation (future) is more envious than reflection (past). All other groups leaned towards higher past envy than future.
I ran a new ANOVA just to see the isolation of the 20 & 22 year olds.
Show the code
EnvyAge_filtered <-subset(EnvyAge, Age %in%c(20, 22))EnvyAge.aov <-aov(`Total Average`~ Tense +as.factor(Age) + Tense:as.factor(Age), data = EnvyAge_filtered)summary(EnvyAge.aov) %>%pander()
Analysis of Variance Model
Df
Sum Sq
Mean Sq
F value
Pr(>F)
Tense
1
12.2
12.2
12.3
0.001367
as.factor(Age)
1
0.2233
0.2233
0.225
0.6385
Tense:as.factor(Age)
1
0.595
0.595
0.5996
0.4444
Residuals
32
31.75
0.9923
NA
NA
There isn’t a difference between the 20 & 22 year olds. However, since we have them separated from the other groups we can see one interesting thing. There is significance in the tenses for these two age groups. The future tense is significantly more envious than the past group for 20 & 22 year olds from our sample of 235 PSYCH 311 students.
Show the code
boxplot(`Total Average`~ Tense * Age, data = EnvyAge_filtered, col =c("seagreen1", "seagreen3", "skyblue1", "skyblue3" ),main ="The Enviousness of the Ages",xlab =".",ylab ="Total Average",las =3)
H_0: \text{The effect of ethnicity on the average envy score is consistent across both tenses}
H_a: \text{The effect of ethnicity on the average envy score differs across the tenses.}
boxplot(`Total Average`~ Tense * Ethnicity, data = EnvyData, col =c("chocolate4", "lightsalmon4","seashell1", "seashell","peachpuff", "peachpuff2", "violetred1", "violetred3", "yellow1", "yellow3"),main ="Enviousness by Ethnicity",xlab =".",ylab ="Total Average",las =3)
Show the code
xyplot(`Total Average`~as.factor(Tense), data = EnvyData, groups=Ethnicity, type=c("p","a"), auto.key=TRUE, main="Enviousness by Ethnicity", ylab="Average Envy", xlab="Grouped by Tense")
Interpretation
There are a lot of graphs and a lot of analyses. With so much data there is so much to do and see. We did not find significance in any of our original hypotheses that are the t.tests but if we switch the job hypothesis to less instead of greater the p-value is actually p-value = 0.035 < \alpha. This is showing us that college students are actually more envious when their close friend has just received their dream job than if their friend were just about to receive it.
With the gender ANOVA we see that women are more envious than men on average. \mu = 4.32 females and \mu = 3.81 males with a p-value = 0.004437 < \alpha. Thats a 0.5 average mean score difference.
The Age Anova where age and tense were tested did show significance p-value = 0.08452 < \alpha = 0.1. At least one age group reported higher envy scores than another.
When we separated out the 20 and 22 year olds we found a difference for tense only, showing that testing just the 20 and 22 year olds did find significantly more enviousness in the future p-value = 0.00137. This was our original hypothesis and only the 20 & 22 year olds found anticipation to be more envious than reflection.
Finally we reached significance again in testing the ethnicity envy score p-value = 0.05149 < \alpha = 0.1. This shows us that at least one ethnicity is probably more envious than another. However, looking at the counts with 85% of our participants being White we probably don’t have enough participants of other ethnicities to conclude a significant difference.
Final Word
Again, all of this data will be presented to my teammates who are already quite familiar with the data and are running t.tests of their own. I am mostly showing them the graphs in r as well as running ANOVAs of my own to present. They are familiar with ANOVA so just seeing the data will be interesting. We ended up only presenting the mean differences between the men and women of the ANOVA results.