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 HOMEWORK, USE MY DATA!!!!
d <- read.csv(file="Data/mydata.csv", header=T)
names(d)
[1] "age"       "education" "pswq"      "iou"       "phq"       "brs"      

Univariate Plots: Histograms & Tables

table(d$age)

         1 under 18 2 between 18 and 25 4 between 36 and 45           5 over 45 
                255                  30                   9                  13 
table(d$education)

             1 equivalent to not completing high school 
                                                     70 
                 2 equivalent to high school completion 
                                                    141 
3 equivalent to vocational/technical program completion 
                                                      3 
                       4 equivalent to AP/IB completion 
                                                     56 
                                 5 undergraduate degree 
                                                      9 
                            6 graduate degree or higher 
                                                      6 
                                      prefer not to say 
                                                     22 
hist(d$pswq)

hist(d$iou)

hist(d$phq)

hist(d$brs)

Univariate Normality

Check skew and kurtosis.

describe(d)
           vars   n mean   sd median trimmed  mad   min  max range  skew
age*          1 307 1.28 0.72   1.00    1.09 0.00  1.00 4.00  3.00  2.72
education*    2 307 2.67 1.70   2.00    2.39 1.48  1.00 7.00  6.00  1.24
pswq          3 307 0.27 0.92   0.38    0.33 0.98 -2.06 2.02  4.09 -0.44
iou           4 307 2.94 0.94   3.00    2.94 1.15  1.11 4.89  3.78  0.02
phq           5 307 2.55 0.88   2.56    2.55 0.99  1.00 4.00  3.00  0.00
brs           6 307 2.70 0.87   2.67    2.69 0.99  1.00 5.00  4.00  0.11
           kurtosis   se
age*           6.68 0.04
education*     0.68 0.10
pswq          -0.56 0.05
iou           -1.00 0.05
phq           -1.08 0.05
brs           -0.63 0.05

Bivariate Plots

Crosstabs

cross_cases(d, age, education)
 education 
 1 equivalent to not completing high school   2 equivalent to high school completion   3 equivalent to vocational/technical program completion   4 equivalent to AP/IB completion   5 undergraduate degree   6 graduate degree or higher   prefer not to say 
 age 
   1 under 18  70 136 2 26 21
   2 between 18 and 25  3 1 26
   4 between 36 and 45  1 2 4 2
   5 over 45  1 2 5 4 1
   #Total cases  70 141 3 56 9 6 22

Scatterplots

plot(d$pswq, d$iou,
     main="Scatterplot of Penn State Worry Questionnaire (Adult) and Intolerance of Uncertainty",
     xlab = "Penn State Worry Questionnare (Adult)",
     ylab = "Intolerance of Uncertainty")

plot(d$pswq, d$phq,
     main="Scatterplot of Penn State Worry Questionnaire (Adult) and Patient Health Questionnare",
     xlab = "Penn State Worry Questionnaire (Adult)",
     ylab = "Patient Health Questionnare")

plot(d$pswq, d$brs,
     main="Scatterplot of Penn State Worry Questionnaire (Adult) and Brief Resiliene Scale",
     xlab = "Scatterplot of Penn State Worry Questionnaire (Adult)",
     ylab = "Brief Resilience Scale")

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

plot(d$iou, d$brs,
     main="Scatterplot of Intolerance of Uncertainty and Brief Resilience Scale",
     xlab = "Intolerance of Uncertainty",
     ylab = "Brief Resilience Scale")

plot(d$phq, d$brs,
     main="Scatterplot of Patient Health Questionnare and Brief Resilience Scale",
     xlab = "Patient Health Questionnare",
     ylab = "Brief Resilience Scale")

Boxplots

#REMEMBER THAT CONTINUOUS VARIABLE COMES FIRST !!!
boxplot(data=d, brs~age,
        main="Boxplot of Brief Resilience Scale and Age",
        xlab = "Age",
        ylab = "Brief Resilience Scale")

boxplot(data=d, iou~education,
        main="Boxplot of Intolerance of Uncertainty and Education",
        xlab = "Education",
        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.

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).