Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please use R. 2) The command Im(y-x) fits this model: y = a + b x. In this exercise, you're going to explore what happens
Please use R.
2) The command Im(y-x) fits this model: y = a + b x. In this exercise, you're going to explore what happens when you fit this model and yet the data do not follow. a) In the last homework you wrote a function that generates data that follow the linear model. Write a new function that generates data that has a quadratic trend between x and y: a + bx + cx^2 Input to this function should be a,b,c, sigma, x=rep(1:10, by= 1,4), random.seed Output is a vector of length(x). The model is y = f(x) + epsilon where epsilon is N(o, sigma), and f(x) is any non-linear function you choose. Produce a scatterplot showing the relationship between y and x for any values of the input parameters you choose. b) Now fit a linear model using Im() function applied to the x variable and your generated y variable. This model is not correct (because it assumes the trend is linear but the data you have generated do not follow a linear trend.) Make a plot of the residuals against the x variable. Describe what you see c) In class we discussed that if the residual plot shows no features, then this indicates that the correct model was fitted. How can we use the residual plot to tell if the trend is non-linear? d) Now write a function that generates data that follows a linear trend but has non-constant standard deviation in the error terms. Specifically: y = a + bx + epsilon where epsilon is N(o, sigma*x^2) for a scalar sigma. Input: a, b, x, sigma, random.seed Use x = rep (1:10, by = 1,4), a = 1, b = 200, sigma = 5, random.seed=123 Make a scatterplot of y versus x and describe it. 2) The command Im(y-x) fits this model: y = a + b x. In this exercise, you're going to explore what happens when you fit this model and yet the data do not follow. a) In the last homework you wrote a function that generates data that follow the linear model. Write a new function that generates data that has a quadratic trend between x and y: a + bx + cx^2 Input to this function should be a,b,c, sigma, x=rep(1:10, by= 1,4), random.seed Output is a vector of length(x). The model is y = f(x) + epsilon where epsilon is N(o, sigma), and f(x) is any non-linear function you choose. Produce a scatterplot showing the relationship between y and x for any values of the input parameters you choose. b) Now fit a linear model using Im() function applied to the x variable and your generated y variable. This model is not correct (because it assumes the trend is linear but the data you have generated do not follow a linear trend.) Make a plot of the residuals against the x variable. Describe what you see c) In class we discussed that if the residual plot shows no features, then this indicates that the correct model was fitted. How can we use the residual plot to tell if the trend is non-linear? d) Now write a function that generates data that follows a linear trend but has non-constant standard deviation in the error terms. Specifically: y = a + bx + epsilon where epsilon is N(o, sigma*x^2) for a scalar sigma. Input: a, b, x, sigma, random.seed Use x = rep (1:10, by = 1,4), a = 1, b = 200, sigma = 5, random.seed=123 Make a scatterplot of y versus x and describe itStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started