# Lab exercise 3

Please upload your completed .pdf file on Moodle by 23:59pm.

1. Import the two data sets from the following links into the RStudio, and name the two objects as data1 and data2.
1. Suppose you want to create a function that returns the criterion-related validity. Complete the following code chunk.
cr_val <- function(test1, test2){
# total scores of the two tests
total1 <-
total2 <-
# the Pearson correlation between the total scores
rho_xy <-

return()
}
1. Complete the following code chunk to create a function that calculates the correlation between the true scores of two tests after correcting for attenuation.
true_cor <- function(test1, test2){
# validity
rho_xy <-
# reliability of the two tests
rho_xx <-
rho_yy <-
# correlation between the true scores
rho_txty <-

return(rho_txty)
}

hints:

• Inside the true_cor() function body, you can use cr_val() and coeff_alpha() functions to obtain $$\rho_{XY}$$, $$\rho_{XX'}$$, $$\rho_{YY'}$$.

• You need to include a code chunk defining a function (e.g., coeff.alpha) before using it. Otherwise, it will return an error message when knitting.

• The correlation between the true scores $$\rho_{T_X T_Y}$$ is:

$\rho_{T_X T_Y} = \frac{\rho_{XY}}{\sqrt{\rho_{XX'}} \sqrt{\rho_{YY'}}}$