subject

A) Write a function named diagnostics that takes as input the arguments: model, an object of class lm(), that is a model fit via lm()
pcol, for controlling point colors in plots, with a default value of grey
lcol, for controlling line colors in plots, with a default value of dodgerblue
alpha, the significance level of any test that will be performed inside the function, with a default value of 0.05
plotit, a logical value for controlling display of plots with default value TRUE
testit, a logical value for controlling outputting the results of tests with default value TRUE
The function should output:
A list with two elements when testit is TRUE:
p_val, the p-value for the Shapiro-Wilk test for assessing normality
decision, the decision made when performing the Shapiro-Wilk test using the alpha value input to the function. "Reject" if the null hypothesis is rejected, otherwise "Fail to Reject."
Two plots, side-by-side, when plotit is TRUE:
A fitted versus residuals plot that adds a horizontal line at y=0, and labels the x-axis "Fitted" and the y-axis "Residuals." The points and line should be colored according to the input arguments. Give the plot a title.
A Normal Q-Q plot of the residuals that adds the appropriate line using qqline(). The points and line should be colored according to the input arguments. Be sure the plot has a title.
Consider using this function to help with the remainder of the assignment as well.
B) Run the following code.
set. seed(40)
data_1 = data. frame(x = runif(n = 30, min = 0, max = 10),
y = rep(x = 0, times = 30))
data_1$y = with(data_1, 2 + 1 * x + rexp(n = 30))
fit_1 = lm(y ~ x, data = data_1)
data_2 = data. frame(x = runif(n = 20, min = 0, max = 10),
y = rep(x = 0, times = 20))
data_2$y = with(data_2, 5 + 2 * x + rnorm(n = 20))
fit_2 = lm(y ~ x, data = data_2)
data_3 = data. frame(x = runif(n = 40, min = 0, max = 10),
y = rep(x = 0, times = 40))
data_3$y = with(data_3, 2 + 1 * x + rnorm(n = 40, sd = x))
fit_3 = lm(y ~ x, data = data_3)
diagnostics(fit_1, plotit = FALSE)$p_val
diagnostics(fit_2, plotit = FALSE)$decision
diagnostics(fit_1, testit = FALSE, pcol = "black", lcol = "black")
diagnostics(fit_2, testit = FALSE, pcol = "grey", lcol = "green")
diagnostics(fit_3)

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 04:00
Which of the following kinds of programs displays an online advertisement in a banner or pop-up window on webpages, email, or other internet service? e
Answers: 2
question
Computers and Technology, 23.06.2019 15:30
Hey so i was just trying out some game hacks so i took a paste from online and built it in my visual studio and then suddenly my computer was working or clicking on stuff on its own am i hacked?
Answers: 1
question
Computers and Technology, 23.06.2019 22:20
If i uninstall nba 2k 19 from my ps4 will my career be gone forever?
Answers: 2
question
Computers and Technology, 24.06.2019 02:00
What is a loop? a. a collection of function definitions at the top of a program b. a line of code that defines a variable and assigns it a value c. a program that opens the turtle graphics window d. a block of code that repeats a specific number of times
Answers: 1
You know the right answer?
A) Write a function named diagnostics that takes as input the arguments: model, an object of class...
Questions
question
Business, 24.03.2022 01:00
question
Mathematics, 24.03.2022 01:00
Questions on the website: 13722367