The objective of this question is to show how R can be applied in the context...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
The objective of this question is to show how R can be applied in the context of linear regression using matrices. Given n pairs of values {(₁, 1), (2, 32). (En, yn)), the sample (Pearson) correlation coefficient r is defined by Σ(x-2)(y-7) im1 72 72 Σ(x; - z), Σ( – g)" i=1 T= 71 The cor () function can input two vector arguments of the same length and output the correlation coefficient between them. Write a function called my_cor () that computes the correlation between two numeric vectors x and y without the cor (), cov(), var(), or sd() functions. Include a character argument called use that specifies whether to use all observations (use = "everything") or only pairwise complete observations (use = "pairwise.complete.obs") by removing a pair (ri, yi) if either r, or y; is missing. The output of my_cor (x, y) and cor(x, y) should be identical for any numeric vectors x and y. Hint: The cor() function also allows for matrix inputs x and y and computes the correlation matrix between columns of x and columns of y. Your my_cor () function does not need to include this functionality. (b) Assume there is a linear relationship between variables x and y. The least squares regression line is a linear model that predicts y from z. The equation of the regression line is denoted by y = a + bx. The coefficients of the regression line are computed by the formulas Sy b=r- and a=ỹ - ba, where I and ÿ and the respective means and s, and sy are the respective standard deviations for the data vectors x and y. Write a function called linreg() that inputs two numeric vectors x and y and outputs a numeric vector of length 2 that corresponds to the coefficients a and b of the least squares regression line that predicts y from x. Include a character argument called use that specifies whether to use all observations (use = "everything") or only pairwise complete observations (use = "pairwise.complete.obs") by removing a pair (*i, y₁) if either z, or y; is missing. The objective of this question is to show how R can be applied in the context of linear regression using matrices. Given n pairs of values {(₁, 1), (2, 32). (En, yn)), the sample (Pearson) correlation coefficient r is defined by Σ(x-2)(y-7) im1 72 72 Σ(x; - z), Σ( – g)" i=1 T= 71 The cor () function can input two vector arguments of the same length and output the correlation coefficient between them. Write a function called my_cor () that computes the correlation between two numeric vectors x and y without the cor (), cov(), var(), or sd() functions. Include a character argument called use that specifies whether to use all observations (use = "everything") or only pairwise complete observations (use = "pairwise.complete.obs") by removing a pair (ri, yi) if either r, or y; is missing. The output of my_cor (x, y) and cor(x, y) should be identical for any numeric vectors x and y. Hint: The cor() function also allows for matrix inputs x and y and computes the correlation matrix between columns of x and columns of y. Your my_cor () function does not need to include this functionality. (b) Assume there is a linear relationship between variables x and y. The least squares regression line is a linear model that predicts y from z. The equation of the regression line is denoted by y = a + bx. The coefficients of the regression line are computed by the formulas Sy b=r- and a=ỹ - ba, where I and ÿ and the respective means and s, and sy are the respective standard deviations for the data vectors x and y. Write a function called linreg() that inputs two numeric vectors x and y and outputs a numeric vector of length 2 that corresponds to the coefficients a and b of the least squares regression line that predicts y from x. Include a character argument called use that specifies whether to use all observations (use = "everything") or only pairwise complete observations (use = "pairwise.complete.obs") by removing a pair (*i, y₁) if either z, or y; is missing.
Expert Answer:
Answer rating: 100% (QA)
a Here is a function in R that computes the correlation coefficient between two n... View the full answer
Related Book For
Understandable Statistics Concepts And Methods
ISBN: 9781337119917
12th Edition
Authors: Charles Henry Brase, Corrinne Pellillo Brase
Posted Date:
Students also viewed these programming questions
-
What cost standards are implemented by the management in an organization/ in your own organization relevant to planning for profit. Why do you think these standards are important?
-
How can the management consistently keep its employees motivated to meet company standard particularly related on cost control? What effects would you expect this to have on the total productivity of...
-
Melissa buys an iPod for $120 and gets consumer surplus of $80. a. What is her willingness to pay? b. If she had bought the iPod on sale for $90, what would her consumer surplus have been? c. If the...
-
The central processing unit (CPU) of a microcomputer is a computer chip containing millions of transistors. Connecting the transistors are slender circuit paths only .5 to .85 micrometer wide. A...
-
On January 1, 20X1, the Dallas Auto Parts Company acquired nine identical assembly robots for a total of $594,000 cash. The robots had an expected useful life of 10 years and an expected residual...
-
What are the main causes of expatriate failure?
-
It has now been one month since you launched your business. You are meeting with a few investors soon to share your vision for the company and to ask for more funding. You will be sharing your...
-
Irna borrowed RM50,000 for her education purposes from PITIPITI Bank. The payments are to be made on an installment basis. The tenure of the loan is seven (7) years with 7 percent interest per annum....
-
Given a directed graph G = (V, E), explain how to create another graph G = (V, E) such that (a) G has the same strongly connected components as G, (b) G has the same component graph as G, and (c) E...
-
According to Catechism for Filipino Catholics (CFC) 51 "Our world vision as Catholic Filipinos are gradually transformed by Christ's Spirit-in-the-world in our Church community." Formulate a...
-
The cost of debt can be determined using the yield-to-maturity and the bond rating approaches. If the bond rating approach is used, the: A. coupon is the yield. B. yield is based on the interest...
-
What is the difference between a standard corporation (C corporation) and a benefit corporation (B corporation)?
-
Sometimes, there are slight differences in the liquidity of otherwise equivalent securities. Treasury bonds, i.e., bonds issued by sovereign governments, are issued and sold on markets at regular...
-
Why do religious questionssuch as What is the nature of the human spirit?lie outside of the domain of science?
-
What does the term healthcare finance mean?
-
Discuss the federal registration process and information of a new securities offering. Discuss two exemptions from registration.
-
A firm has the following balance sheet: Assets Cash Accounts receivable Inventory Plant and equipment $ 15,000 150,000 92,000 170,000 $427,000 Liabilities and Equity Accounts payable Long-term debt...
-
Consider a binomial distribution with n = 10 trials and the probability of success on a single trial p = 0.05. (a) Is the distribution skewed left, skewed right, or symmetric? (b) Compute the...
-
David E. Brown is an expert in wildlife conservation. In his book The Wolf in the Southwest: The Making of an Endangered Species (University of Arizona Press), he lists the following weights of adult...
-
The manager of Motel 11 has 316 rooms in Palo Alto, California. From observation over a long period of time, she knows that on an average night, 268 rooms will be rented. The long-term standard...
-
Bethany, who weighs 560 N, lies in a hammock suspended by ropes tied to two trees. One rope makes an angle of 45 with the ground; the other makes an angle of 30. Find the tension in each of the ropes.
-
In the Skycoaster amusement park ride, riders are suspended from a tower by a long cable. A second cable then lifts them until they reach the starting position indicated in Figure P5.3. The lifting...
-
A dump truck, whose bed is made of steel, holds an old steel watering trough. The bed of the truck is slowly raised until the trough begins to slide. What is the acceleration of the trough as it...
Study smarter with the SolutionInn App