## DISP student paper ##

library(readr)
library(jmv)
library(corrplot)
library(ggplot2)
library(GGally)
library(ggpubr)

pp <- read.csv("personal.projects.cleaned.v3.csv")

pp$gender <- as.factor(pp$gender)
pp$ethnicity <- as.factor(pp$ethnicity)
pp$student <- as.factor(pp$student)

pp$gender <- factor(pp$gender, levels = c(1,2,4),
labels = c("female", "male", "other identity"))

pp$ethnicity <- factor(pp$ethnicity, levels = c(1,2,3,4,5,6),
labels = c("white", "black", "asian", "indigenous", "latin", "other"))

pp$student <- factor(pp$student, levels = c(1,2),
labels = c("full time", "part time"))

source("http://pcwww.liv.ac.uk/~william/R/crosstab.r")
crosstab(pp, row.vars = "mh", col.vars = "perf", type = "f")
##             perf adaptive maladaptive non-perfectionist Sum
## mh                                                         
## flourishing             2          19                18  39
## languishing             0           2                 0   2
## moderate               24          63                63 150
## Sum                    26          84                81 191
crosstab(pp, row.vars = "perf", col.vars = "mh", type = "f")
##                   mh flourishing languishing moderate Sum
## perf                                                     
## adaptive                       2           0       24  26
## maladaptive                   19           2       63  84
## non-perfectionist             18           0       63  81
## Sum                           39           2      150 191
## getting scores on mhc-sf by type of perfectionism
mhc.by.perf<-with(pp, tapply(mhc, perf, mean))
mhc.by.perf
##          adaptive       maladaptive non-perfectionist 
##          4.506551          3.870018          3.710128
## non-perf: 4.51  maladaptive = 3.87  adaptive = 3.71

## getting scores on aps by level of mental health
aps.by.mh<-with(pp, tapply(aps, mh, mean))
aps.by.mh
## flourishing languishing    moderate 
##    5.272136    6.239130    4.980463
#flourish: 5.27 languishing: 6.24 moderate: 4.98

## getting scores on aps subscales by level of mental health
s.by.mh<-with(pp, tapply(aps.standards, mh, mean))
s.by.mh
## flourishing languishing    moderate 
##    41.23077    44.50000    41.80000
#flourish: 41.23 languishing: 44.5 moderate: 41.8

d.by.mh<-with(pp, tapply(aps.discrepency, mh, mean))
d.by.mh
## flourishing languishing    moderate 
##    59.15385    77.00000    50.34000
#flourish: 59.15 languishing: 77 moderate: 50.34

mhc.perf.aov <- lm(mhc ~ perf, data = pp)
summary(mhc.perf.aov)
## 
## Call:
## lm(formula = mhc ~ perf, data = pp)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -2.4854 -0.7185  0.1360  0.6715  2.1300 
## 
## Coefficients:
##                       Estimate Std. Error t value Pr(>|t|)    
## (Intercept)             4.5066     0.1868  24.121  < 2e-16 ***
## perfmaladaptive        -0.6365     0.2138  -2.977 0.003292 ** 
## perfnon-perfectionist  -0.7964     0.2147  -3.709 0.000274 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.9527 on 188 degrees of freedom
## Multiple R-squared:  0.06845,    Adjusted R-squared:  0.05854 
## F-statistic: 6.907 on 2 and 188 DF,  p-value: 0.001275
## significantly different


descriptives(pp, aps.standards)
## 
##  DESCRIPTIVES
## 
##  Descriptives                 
##  ──────────────────────────── 
##               aps.standards   
##  ──────────────────────────── 
##    N                    191   
##    Missing                0   
##    Mean            41.71204   
##    Median                42   
##    Minimum               23   
##    Maximum               49   
##  ────────────────────────────
descriptives(pp, aps)
## 
##  DESCRIPTIVES
## 
##  Descriptives            
##  ─────────────────────── 
##               aps        
##  ─────────────────────── 
##    N               191   
##    Missing           0   
##    Mean       5.053199   
##    Median     5.000000   
##    Minimum    2.695652   
##    Maximum    7.000000   
##  ───────────────────────
cor.test(pp$mhc, pp$aps.standards, method=c("pearson"))
## 
##  Pearson's product-moment correlation
## 
## data:  pp$mhc and pp$aps.standards
## t = 3.0105, df = 189, p-value = 0.002965
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.07418523 0.34540067
## sample estimates:
##       cor 
## 0.2139115
#correlation of 0.21, p = .003, CI = [.074, .345]


#demographic descriptives
descriptives(pp, age)
## 
##  DESCRIPTIVES
## 
##  Descriptives            
##  ─────────────────────── 
##               age        
##  ─────────────────────── 
##    N               177   
##    Missing          14   
##    Mean       20.71186   
##    Median           20   
##    Minimum          17   
##    Maximum          33   
##  ───────────────────────
eth = table(pp$ethnicity)
eth
## 
##      white      black      asian indigenous      latin      other 
##        119          6         46          0          0          0
student = table(pp$student)
student
## 
## full time part time 
##       186         5
gender = table(pp$gender)
gender
## 
##         female           male other identity 
##            168             22              1
boxplot(mhc ~ perf, data = pp, xlab = "perfectionism type", ylab = "mental health", 
        plot = TRUE)

boxplot(aps.standards ~ perf, data = pp, xlab = "perfectionistic standards", ylab = "perfectionism type",
                plot= TRUE)

boxplot(aps.standards ~ mh, data = pp, xlab = "mental health level", ylab = "perfectionistic standards", 
        plot = TRUE)