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 12:00
Which of the following does 3d animation create an illusion of on the screen? a. depth b. emotion c. length d. dialogue
Answers: 1
question
Computers and Technology, 22.06.2019 19:00
In he example code, what does the title attribute create? a tool tip an element a source a markup
Answers: 1
question
Computers and Technology, 23.06.2019 02:00
As with any small island country, cuba has fewer natural resources than countries such as brazil. this affects their economy in that cuba a) exports only manufactured products. b) exports more products than it imports.. c) must import more products than it exports. d) has imposed trade barriers against the united states.
Answers: 3
question
Computers and Technology, 23.06.2019 09:30
Write an essay on online collaboration, how to do it, the challenges, resolving the challenges, and consider whether the risks are greater than rewards. ( need )
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
Mathematics, 17.05.2021 21:40
question
Mathematics, 17.05.2021 21:40
question
Chemistry, 17.05.2021 21:40
question
History, 17.05.2021 21:40
question
Mathematics, 17.05.2021 21:40
Questions on the website: 13722367