Computers and Technology

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)

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 19:20, manny2085
Amedian in the road will be marked with a white sign that has a black arrow going to the left of the median. true false
Answers: 1
image
Computers and Technology, 23.06.2019 22:30, reaganphelps3
What would be the address of the cell, which is at the intersection of the second row and the third column in a worksheet?
Answers: 1
image
Computers and Technology, 24.06.2019 09:00, lisacarter0804
Why might you chose to crest a function resume
Answers: 1
image
Computers and Technology, 24.06.2019 23:00, Kaziyah461
People should never use telepresence when virtually meeting with a group of co-workers. true false
Answers: 1
Do you know the correct answer?
A) Write a function named diagnostics that takes as input the arguments: model, an object of class...

Questions in other subjects:

Konu
Mathematics, 27.05.2020 03:00
Konu
English, 27.05.2020 03:00