Basic Statistics Lab

Load Libraries

# remember, you might need to install packages

library(psych) # for the describe() command
library(expss) # for the cross_cases() command

Load Data

# WILL NEED TO UPDATE THIS FOR THE HW!!! USE MYDATA
d <- read.csv(file="Data/labdata.csv", header=T)
names(d)
[1] "pet"     "mhealth" "iou"     "rse"     "phq"     "pss"    

Univariate Plots: Histograms & Tables

table(d$pet)

                 bird                   cat           cat and dog 
                    5                   211                   136 
                  dog                  fish multiple types of pet 
                  246                    35                   104 
              no pets                 other 
                  396                    68 
table(d$mhealth)

             anxiety disorder                       bipolar 
                          128                             5 
                   depression              eating disorders 
                           31                            28 
                   none or NA obsessive compulsive disorder 
                          927                            26 
                        other                          ptsd 
                           34                            22 
# 
hist(d$iou)

hist(d$rse)

hist(d$phq)

hist(d$pss)

Univariate Normality

Check skew and kurtosis.

describe(d)
         vars    n mean   sd median trimmed  mad  min max range  skew kurtosis
pet*        1 1201 4.94 2.05   5.00    4.99 2.97 1.00   8  7.00 -0.13    -1.49
mhealth*    2 1201 4.62 1.42   5.00    4.86 0.00 1.00   8  7.00 -1.41     2.38
iou         3 1201 2.57 0.90   2.41    2.51 0.99 1.04   5  3.96  0.51    -0.57
rse         4 1201 2.63 0.72   2.70    2.64 0.74 1.00   4  3.00 -0.21    -0.72
phq         5 1201 2.09 0.87   1.89    2.01 0.99 1.00   4  3.00  0.61    -0.74
pss         6 1201 2.95 0.95   3.00    2.94 1.11 1.00   5  4.00  0.07    -0.77
           se
pet*     0.06
mhealth* 0.04
iou      0.03
rse      0.02
phq      0.02
pss      0.03

Bivariate Plots

Crosstabs

cross_cases(d, pet, mhealth)
 mhealth 
 anxiety disorder   bipolar   depression   eating disorders   none or NA   obsessive compulsive disorder   other   ptsd 
 pet 
   bird  1 1 3
   cat  29 1 4 3 164 4 3 3
   cat and dog  19 1 6 99 4 5 2
   dog  32 3 12 6 176 4 5 8
   fish  3 1 30 1
   multiple types of pet  12 3 3 76 2 4 4
   no pets  25 1 8 9 326 9 14 4
   other  7 2 53 2 3 1
   #Total cases  128 5 31 28 927 26 34 22

Scatterplots

plot(d$iou, d$rse,
     main="Scatterplot of Intolerance of Uncertainty and Self-Esteem",
     xlab = "Intolerance of Uncertainty",
     ylab = "Self-Esteem")

plot(d$iou, d$phq,
     main="Scatterplot of Intolerance of Uncertainty and Depression",
     xlab = "Intolerance of Uncertainty",
     ylab = "Depression")

plot(d$iou, d$pss,
     main="Scatterplot of Intolerance of Uncertainty and Stress",
     xlab = "Intolerance of Uncertainty",
     ylab = "Stress")

plot(d$rse, d$phq,
     main="Scatterplot of Self-Esteem and Depression",
     xlab = "Self-Esteem",
     ylab = "Depression")

plot(d$rse, d$pss,
     main="Scatterplot of Self-Esteem and Stress",
     xlab = "Self-Esteem",
     ylab = "Stress")

plot(d$phq, d$pss,
     main="Scatterplot of Depression and Stress",
     xlab = "Depression",
     ylab = "Stress")

Boxplots

# remember that continuous variale comes first, CONTINUOUS~CATEGORICAL
boxplot(data=d, iou~pet,
        main="Boxplot of Intolerance of Uncertainty and Pet Type",
        xlab = "Pet Type",
        ylab = "Intolerance of Uncertainty")

boxplot(data=d, iou~mhealth,
        main="Boxplot of Intolerance of Uncertainty and Mental Health Diagnosis",
        xlab = "Mental Health Diagnosis",
        ylab = "Intolerance of Uncertainty")

Write-Up

Once again, you need to create a write-up reviewing the most important things you did here. Again, it should be suitable for inclusion in a manuscript. Make sure you include your review of skewness and kurtosis. I have given you two potential templates you can follow below, depending upon your needs – you should delete the other text in this section and only include your write-up.

If skew and kurtosis are good: We reviewed plots and descriptive statistics for our six chosen variables. All four of our continuous variables had skew and kurtosis within the accepted range (-2/+2).

If skew and kurtosis have issues: We reviewed plots and descriptive statistics for our six chosen variables. [Placeholder] variables had issues with skew and/or kurtosis: worry scores were negatively skewed (-3.15) and self-esteem scores were kurtotic (2.50). The other [placeholder] variables had skew and kurtosis within the accepted range (-2/+2).