PERMA - HAPPY

setwd("/Users/levibrackman/Desktop/Adult_study")
data_pre <- read.csv("pre.csv")
data_post <- read.csv("post.csv")

table(data_pre$GROUP, dnn = "group")
## group
##  0  1 
## 35 32
data <- merge(data_pre, data_post, by = "ID", all = TRUE)

library(psych)
library(lattice)
t.test(data$PERMA17.x ~ GROUP.x, data = data)
## 
##  Welch Two Sample t-test
## 
## data:  data$PERMA17.x by GROUP.x
## t = -0.1446, df = 64.81, p-value = 0.8855
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.9655  0.8351
## sample estimates:
## mean in group 0 mean in group 1 
##           7.029           7.094
t.test(data$PERMA17.y ~ GROUP.x, data = data)
## 
##  Welch Two Sample t-test
## 
## data:  data$PERMA17.y by GROUP.x
## t = -1.718, df = 44.56, p-value = 0.09266
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -1.587  0.126
## sample estimates:
## mean in group 0 mean in group 1 
##           7.269           8.000

PERMA_HAPPI_ANCOVA <- lm(data$PERMA17.y ~ as.factor(GROUP.x) + data$PERMA17.x, 
    data = data)


# check assumptions visually
plot(PERMA_HAPPI_ANCOVA)

plot of chunk unnamed-chunk-1 plot of chunk unnamed-chunk-1 plot of chunk unnamed-chunk-1 plot of chunk unnamed-chunk-1

# see results
summary(PERMA_HAPPI_ANCOVA)
## 
## Call:
## lm(formula = data$PERMA17.y ~ as.factor(GROUP.x) + data$PERMA17.x, 
##     data = data)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -4.368 -0.399  0.272  0.632  1.334 
## 
## Coefficients:
##                     Estimate Std. Error t value Pr(>|t|)    
## (Intercept)            2.113      0.832    2.54    0.015 *  
## as.factor(GROUP.x)1    0.639      0.320    2.00    0.052 .  
## data$PERMA17.x         0.702      0.109    6.41  8.4e-08 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.09 on 44 degrees of freedom
##   (22 observations deleted due to missingness)
## Multiple R-squared:  0.513,  Adjusted R-squared:  0.491 
## F-statistic: 23.2 on 2 and 44 DF,  p-value: 1.34e-07

Now running the same tests but without 15 which was an outlier


PERMA_HAPPI_ANCOVA2 <- lm(PERMA17.y ~ as.factor(GROUP.x) + PERMA17.x, data = data, 
    -15)

summary(PERMA_HAPPI_ANCOVA2)
## 
## Call:
## lm(formula = PERMA17.y ~ as.factor(GROUP.x) + PERMA17.x, data = data, 
##     subset = -15)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -4.272 -0.284  0.231  0.712  1.247 
## 
## Coefficients:
##                     Estimate Std. Error t value Pr(>|t|)    
## (Intercept)            3.618      0.824    4.39  7.2e-05 ***
## as.factor(GROUP.x)1    0.503      0.281    1.79    0.081 .  
## PERMA17.x              0.519      0.107    4.87  1.6e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.95 on 43 degrees of freedom
##   (22 observations deleted due to missingness)
## Multiple R-squared:  0.382,  Adjusted R-squared:  0.353 
## F-statistic: 13.3 on 2 and 43 DF,  p-value: 3.19e-05

Now running the same tests but without 15, 39 which was an outlier


PERMA_HAPPI_ANCOVA3 <- lm(PERMA17.y ~ as.factor(GROUP.x) + PERMA17.x, data = data[-c(15, 
    39), ])

summary(PERMA_HAPPI_ANCOVA3)
## 
## Call:
## lm(formula = PERMA17.y ~ as.factor(GROUP.x) + PERMA17.x, data = data[-c(15, 
##     39), ])
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -1.7833 -0.3319  0.0468  0.4983  1.2167 
## 
## Coefficients:
##                     Estimate Std. Error t value Pr(>|t|)    
## (Intercept)           3.3949     0.5934    5.72  1.0e-06 ***
## as.factor(GROUP.x)1   0.7184     0.2051    3.50   0.0011 ** 
## PERMA17.x             0.5486     0.0768    7.14  9.1e-09 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.683 on 42 degrees of freedom
##   (22 observations deleted due to missingness)
## Multiple R-squared:  0.596,  Adjusted R-squared:  0.577 
## F-statistic:   31 on 2 and 42 DF,  p-value: 5.34e-09