Question: Code the following in R Studio 4.1 Write a function which takes variables x and y as input and uses a loop to calculate the
Code the following in R Studio

4.1 Write a function which takes variables x and y as input and uses a loop to calculate the sample correlation coefficient r, where n (xi - x) (Vi - y ) r= n . SxSy i=1 You may use built-in functions for the means and the standard deviations. (code:5) 4.2 The p-value for the correlation test is calculated as follows: The formula for the test statistic is rvn - t = V1 -r2 The p-value = 2 x P(t > [t|) where the t-distribution has n - 2 degrees of freedom. Write a function that takes the correlation coefficient r and the sample size n as input and calculates the t-value and the p-value. (code:3) 4.3 Write a function that takes a p-value as input and determines the conclusion of the hypothesis test, i.e., if the population correlation coefficient differs significantly from 0 at the 5% significance level, The conclusion should state "Reject HO" if p
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
