All problems
Factor Loadings from Correlation
Problem
Return the first principal component loadings of the 2-item correlation matrix [[1, r], [r, 1]]. For r >= 0 return [sqrt((1+r)/2), sqrt((1+r)/2)]; for r < 0 return [sqrt((1-r)/2), -sqrt((1-r)/2)].
Hint
Loadings equal the eigenvector scaled by the square root of its eigenvalue.
Test cases
case 1
in: [0.5]
expected: [0.8660254037844386,0.8660254037844386]
case 2
in: [0]
expected: [0.7071067811865476,0.7071067811865476]
case 3
in: [-0.5]
expected: [0.8660254037844386,-0.8660254037844386]
case 4
in: [1]
expected: [1,1]
case 5
in: [-1]
expected: [1,-1]
Starter codePython
def factor_loadings(r):
# Your code here
pass5 test cases · run your code against them in the editor