1 Loading Libraries

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

# import the dataset you cleaned previously
# this will be the dataset you'll use throughout the rest of the semester
# use ARC data downloaded previous for lab
d <- read.csv(file="data/eammi2_finalREAL.csv", header=T)

3 State Your Hypothesis

We predict that perceived social support (measured by support), need to belong (measured by belong), role transition (measured by moa_role), and maturity (measured by moa_maturity) will all be correlated with each other. Furthermore, we predict that support will be lower in participants who are higher in maturity or who report more role transition. using the four continuous variables, all four for the homework # Check Your Variables

# you only need to check the variables you're using in the current analysis
# although you checked them previously, it's always a good idea to look them over again and be sure that everything is correct
str(d)
## 'data.frame':    3075 obs. of  6 variables:
##  $ gender      : chr  "f" "m" "m" "f" ...
##  $ marriage5   : chr  "are currently divorced from one another" "are currently married to one another" "are currently married to one another" "are currently married to one another" ...
##  $ support     : num  6 6.75 5.17 5.58 6 ...
##  $ belong      : num  2.8 4.2 3.6 4 3.4 4.2 3.9 3.6 2.9 2.5 ...
##  $ moa_role    : num  3 2.67 2.5 2 2.67 ...
##  $ moa_maturity: num  3.67 3.33 3.67 3 3.67 ...
# since we're focusing on our continuous variables, we're going to subset them into their own dataframe. this will make some stuff we're doing later easier.
##NEW_DATAFRAME <- subset(d, select=c(FOUR CONTINUOUS VARIABLES))
d2 <- subset(d, select=c(support,belong,moa_role,moa_maturity))

# 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
## support         1 3075 5.54 1.13   5.75    5.66 0.99 0.0   7   7.0 -1.11
## belong          2 3075 3.23 0.61   3.30    3.25 0.59 1.3   5   3.7 -0.27
## moa_role        3 3075 2.97 0.72   3.00    3.00 0.74 1.0   4   3.0 -0.33
## moa_maturity    4 3075 3.59 0.43   3.67    3.65 0.49 1.0   4   3.0 -1.20
##              kurtosis   se
## support          1.48 0.02
## belong          -0.13 0.01
## moa_role        -0.85 0.01
## moa_maturity     1.89 0.01
# our fake variable has high kurtosis, which I'll ignore. 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 manuscript

# also use histograms to examine your continuous variables
#hist(VARIABLE 1)
hist(d2$support)

hist(d2$belong)

hist(d2$moa_role)

hist(d2$moa_maturity)

# last, use scatterplots to examine your continuous variables together, 6 plots to get all combos
#plot(VARIABLE 1, VARIABLE 2)
plot(d2$support, d2$belong)

plot(d2$support, d2$moa_role)

plot(d2$support, d2$moa_maturity)

plot(d2$belong, d2$moa_role)

plot(d2$belong, d2$moa_maturity)

plot(d2$moa_role, d2$moa_maturity)

4 Check Your Assumptions

4.1 Pearson’s Correlation Coefficient Assumptions

  • Should have one measurement for each score for each participant

In our Data Prep and Basic Stats lab, we dropped any participants with missing data. So we’re good for this assumption!

  • Variables should be continuous and normally distributed

Checked in the section above!

  • Relationship between the variables should be linear

This one is a bit tricky! We’ll talk about it in class; feel free to take notes here. Tricky because its the q with a correlation test, can get a feel from the scatterplots, need to use your judgement on a scatterplot and if there is mention it here

  • Outliers should be identified and removed

We’ll do this one below.

4.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 check and then discuss in your write-up. there are many ways to do this by turning into into a z score look at historgram to see if any are outside 3 or -3 if so you have to mention it

#VARIABLE 1_std <- scale(VARIABLE 1, center=T, scale=T)
#hist(VARIABLE 1_std)
#sum(VARIABLE 1_std < -3 | VARIABLE 1_std > 3)

d$support_std <- scale(d$support, center=T, scale=T)
hist(d$support_std)

sum(d$pss_support < -3 | d$pss_std > 3)
## [1] 0
#variable 1: support has no outliers 
#the sum code checks it its any variables are outside 3 to -3, ours says 0 so we're all good 
#copy and paste with new variable 
d$belong_std <- scale(d$belong, center=T, scale=T)
hist(d$belong_std)

sum(d$belong_std < -3 | d$belong_std > 3)
## [1] 7
#Variable 2: belong has 7 outliers 

d$moa_role_std <- scale(d$moa_role, center=T, scale=T)
hist(d$moa_role_std)

sum(d$moa_role_std < -3 | d$moa_role_std > 3)
## [1] 0
#variable 3: moa_role has no outliers

d$moa_maturity_std <- scale(d$moa_maturity, center=T, scale=T)
hist(d$moa_maturity_std)

sum(d$moa_maturity_std < -3 | d$moa_maturity_std > 3)
## [1] 21
#Variable 4: moa_maturity has 21 outliers

4.2 Issues with My Data

Half of my variables meet all of the assumptions of Pearson’s correlation coefficient- two do and two do not. My second variable,belong which measures a need to beling had low but not abnormal kurtosis (-0.13) and had 7 outliers. My fourth varibale, moa_maturity which measures maturity had a normal kurtosis (1.89) and 21 outliers Outliers can distort the relationship between two variables and sway the correlation in their direction. This variable also appears to have non-linear relationships with the other variables. 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.

5 Create a Correlation Matrix

##corr_output_m <- corr.test(NEW_DATAFRAME)
corr_output_m <- corr.test(d2)
#runs correlarion tests on all things in the new datafram which is only the four ones ones yayy! 

6 View Test Output

corr_output_m
## Call:corr.test(x = d2)
## Correlation matrix 
##              support belong moa_role moa_maturity
## support         1.00   0.09     0.15         0.11
## belong          0.09   1.00     0.06         0.00
## moa_role        0.15   0.06     1.00         0.36
## moa_maturity    0.11   0.00     0.36         1.00
## Sample Size 
## [1] 3075
## Probability values (Entries above the diagonal are adjusted for multiple tests.) 
##              support belong moa_role moa_maturity
## support            0   0.00        0         0.00
## belong             0   0.00        0         0.98
## moa_role           0   0.00        0         0.00
## moa_maturity       0   0.98        0         0.00
## 
##  To see confidence intervals of the correlations, print with the short=FALSE option
#gives us the corrlation matrix 
#there is a diagonial of 1.00s becuse thats when the variable is being compared to itself
#caps out at one or -1 

7 Write Up Results

To test our hypothesis that perceived social support (measured by support), need to belong (measured by belong), role transition (measured by moa_role), and maturity (moa_maturity) would be correlated with one another, we calculated a series of Pearson’s correlation coefficients. Half of our data met the assumptions of the test, with two variables meeting the standards of normality and no outliers. Two variables, belong and moa_maturity, did have outliers and less linear relationships with the other variables, and so any significant results involving that variable should be evaluated carefully. As predicted, we found that all four variables were significantly correlated (all ps < .001) except moa_maturity and belong (ps = 0.98) The effect sizes of all correlations were large (rs > .5; Cohen, 1988) except for the effect size between belong and moa_maturity (0.0 less than trivial) This test also supported our second hypothesis, that support will be lower in participants who are higher in maturity or who report more role transition, as can be seen by the correlation coefficient reported in Table 1. look at r values for correlation (bigger than 5 which is large) and will get code for that later

Table 1: Means, standard deviations, and correlations with confidence intervals
Variable M SD 1 2 3
perceived social support (support) 5.54 1.13
need to beling (belong) 3.23 0.61 .09**
[.06, .13]
role transition (moa_role) 2.97 0.72 .15** .06**
[.12, .19] [.03, .10]
maturity (moa_maturity) 3.59 0.43 .11** .00 .36**
[.07, .14] [-.03, .04] [.33, .39]
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.