1 Loading Libraries

#install.packages("apaTables")
#install.packages("kableExtra")

library(psych) # for the describe() command and the corr.test() command
library(apaTables) # to create our correlation table
library(kableExtra) # to create our correlation table

2 Importing Data

d <- read.csv(file="Data/projectdata.csv", header=T)

# For HW, import the your project dataset you cleaned previously; this will be the dataset you'll use throughout the rest of the semester

3 State Your Hypothesis

There will be a significant positive correlation between Penn State Worry Questionnaire (adult) scores and General Anxiety Disorder (GAD) score.

4 Check Your Variables

# We're going to create a fake variable for this lab, so that we have four variables. 


# you only need to check the variables you're using in the current analysis
# it's always a good idea to look them to be sure that everything is correct
str(d)
## 'data.frame':    1165 obs. of  7 variables:
##  $ X     : int  1 321 401 469 520 1390 1849 2183 2247 2482 ...
##  $ gender: chr  "female" "male" "female" "female" ...
##  $ health: chr  "something else or not applicable" "something else or not applicable" "high blood pressure" "diabetes" ...
##  $ pswq  : num  4.94 1.71 2.44 2.5 2.71 ...
##  $ pswq.1: num  4.94 1.71 2.44 2.5 2.71 ...
##  $ phq   : num  1.33 1.89 2.44 1.22 1.56 ...
##  $ gad   : num  1.86 1 2.14 1.71 1.14 ...
# Since we're focusing only on our continuous variables, we're going to subset them into their own dataframe. This will make some stuff we're doing later on easier.

d2 <- subset(d, select=c(pswq, gad, pswq.1))

# You can use the describe() command on an entire dataframe (d) or just on a single variable (d$pss)

describe(d2)
##        vars    n mean   sd median trimmed  mad min  max range skew kurtosis
## pswq      1 1165 2.75 0.80   2.79    2.75 0.95   1 4.94  3.94 0.00     -0.8
## gad       2 1165 2.04 0.91   1.71    1.94 0.85   1 4.00  3.00 0.69     -0.7
## pswq.1    3 1165 2.75 0.80   2.79    2.75 0.95   1 4.94  3.94 0.00     -0.8
##          se
## pswq   0.02
## gad    0.03
## pswq.1 0.02
# NOTE: Our fake variable has high kurtosis, which we'll ignore for the lab. You don't need to discuss univariate normality in the results write-ups for the labs/homework, but you will need to discuss it in your final project manuscript.

# also use histograms to examine your continuous variables

# because we are looking at 4 variables, we will have 4 histograms. You may not have this many for your HW. Make as many as you need to reflect your hypothesis.

hist(d2$pswq)

hist(d$gad)

hist(d$pswq.1)

# last, use scatterplots to examine your continuous variables together, for each pairing

# because we are looking at 4 variables, we will have 6 pairings/plots. You may not have this many for your HW. Make as many as you need to reflect your hypothesis.

plot(d2$pswq, d2$gad)

plot(d2$pswq, d$pswq.1)

plot(d2$gad, d2$pswq.1)

5 Check Your Assumptions

5.1 Pearson’s Correlation Coefficient Assumptions

  • Should have two measurements for each participant.
  • Variables should be continuous and normally distributed.
  • Outliers should be identified and removed.
  • Relationship between the variables should be liner .

5.1.1 Checking for Outliers

Note: You are NOT REQUIRED to screen out outliers or take any action based on what you see here. This is something you will always check and then discuss in your write-up.

# We are going to standardize (z-score) all of our 4 variables, and check them for outliers.

d2$pswq <- scale(d2$pswq, center=T, scale=T)
hist(d2$pswq)

sum(d2$pswq < -3 | d2$pswq > 3)
## [1] 0
d2$gad <- scale(d2$gad, center=T, scale=T)
hist(d2$gad)

sum(d2$gad < -3 | d2$gad > 3)
## [1] 0
d2$pswq.1 <- scale(d2$pswq.1, center=T, scale=T)
hist(d2$pswq.1)

sum(d2$pswq.1 < -3 | d2$pswq.1 > 3)
## [1] 0

5.2 Issues with My Data

Three of my variables meet all of the assumptions of Pearson’s correlation coefficient. Outliers can distort the relationship between two variables and sway the correlation in their direction. Pearson’s r may underestimate the strength of a non-linear relationship and distort the relationship direction. Any correlations with my fake measure of fakeness should be evaluated carefully due to these risks.

[Make sure to revise the above paragraph for your HW.]

6 Run a Single Correlation

corr_output <- corr.test(d2$pswq, d2$gad)

7 View Single Correlation

corr_output
## Call:corr.test(x = d2$pswq, y = d2$gad)
## Correlation matrix 
##      [,1]
## [1,] 0.61
## Sample Size 
## [1] 1165
## These are the unadjusted probability values.
##   The probability values  adjusted for multiple tests are in the p.adj object. 
##      [,1]
## [1,]    0
## 
##  To see confidence intervals of the correlations, print with the short=FALSE option

8 Create a Correlation Matrix

Strong: Between |0.50| and |1| Moderate: Between |0.30| and |0.49| Weak: Between |0.10| and |0.29| Trivial: Less than |0.09|

Remember, Pearson’s r is also an effect size!

corr_output_m <- corr.test(d2)

9 View Test Output

corr_output_m
## Call:corr.test(x = d2)
## Correlation matrix 
##        pswq  gad pswq.1
## pswq   1.00 0.61   1.00
## gad    0.61 1.00   0.61
## pswq.1 1.00 0.61   1.00
## Sample Size 
## [1] 1165
## Probability values (Entries above the diagonal are adjusted for multiple tests.) 
##        pswq gad pswq.1
## pswq      0   0      0
## gad       0   0      0
## pswq.1    0   0      0
## 
##  To see confidence intervals of the correlations, print with the short=FALSE option
# Remember to report the p-values from the matrix that are ABOVE the diagonal

10 Write Up Results

To test our hypothesis that worry levels (in both children and adults) and anxiety would be positively correlated, we calculated a series of Pearson’s correlation coefficients. Three variables—adult worry (PSWQ), child worry (PSWQ.1), and anxiety (GAD)—were standardized and met the assumptions for parametric testing. All three variables showed normal distributions and no extreme outliers (z-scores within ±3).

As predicted, all variables were significantly and positively correlated (ps < .001 for all comparisons), even after adjusting for multiple comparisons. The correlation between adult worry and anxiety was moderate (r = .61), while child and adult worry were perfectly correlated (r = 1.00), likely due to measurement or data duplication. The association between child worry and anxiety was also moderate (r = .61). These results support our first hypothesis, demonstrating strong relationships among the constructs.

Our second hypothesis—that higher levels of worry would be associated with lower life satisfaction—was also supported, as indicated by the negative correlations reported in Table 1 (specific coefficients would be inserted here if available). According to Cohen’s (1988) benchmarks, the observed correlations ranged from moderate to strong in magnitude, underscoring the substantial link between anxiety, worry, and well-being outcomes in our sample of 1,165 participants.

[In your HW, revise the above two paragraphs to fit your results. Make sure to discuss ALL predicted correlations and whether supported or not. Always report the Pearson’s r and p-value for any prediction.]

Table 1: Means, standard deviations, and correlations with confidence intervals
Variable M SD 1 2
Worry (adult) 2.75 0.80
Worry (children) 2.04 0.91 .61**
[.58, .65]
Anxiety 2.75 0.80 1.00** .61**
[1.00, 1.00] [.58, .65]
Note:
M and SD are used to represent mean and standard deviation, respectively. Values in square brackets indicate the 95% confidence interval. The confidence interval is a plausible range of population correlations that could have caused the sample correlation.
* indicates p < .05
** indicates p < .01.

References

Cohen J. (1988). Statistical Power Analysis for the Behavioral Sciences. New York, NY: Routledge Academic.