Question

In: Statistics and Probability

Data: Linear Regression x=c(1,4,8,19,6,20) y=c(32,13,67,18,15,29) Using R, Plot the 95% prediction and confidence bands. How would...

Data: Linear Regression

x=c(1,4,8,19,6,20)

y=c(32,13,67,18,15,29)

Using R, Plot the 95% prediction and confidence bands. How would you plot these bands? Can you please provide an example picture of the plot?

Solutions

Expert Solution

The following R code can be used to plot the 95% confidence bands and the 95% prediction bands respectively.

**********************************************************************************************************************************************

x=c(1,4,8,19,6,20)
y=c(32,13,67,18,15,29)

fit = lm(y ~ x)

#### plot 95% confidence band:
newx = seq(min(x), max(x), length.out=100)
preds = predict(mod, newdata = data.frame(x=newx), interval = 'confidence')

plot(y ~ x, type = 'n')

polygon(c(rev(newx), newx), c(rev(preds[ ,3]), preds[ ,2]), col = 'grey90', border = NA) ### adding fill to the plot
abline(mod) ## plotting the model in the graph

lines(newx, preds[ ,3], lty = 'dashed', col = 'red') ## plotting intervals
lines(newx, preds[ ,2], lty = 'dashed', col = 'red') ## plotting intervals

                                                                          *********************************************

x=c(1,4,8,19,6,20)
y=c(32,13,67,18,15,29)

fit = lm(y ~ x)

#### plot 95% prediction band:
newx = seq(min(x), max(x), length.out=100)
preds = predict(fit, newdata = data.frame(x=newx), interval = 'prediction')

plot(y ~ x, type = 'n')

polygon(c(rev(newx), newx), c(rev(preds[ ,3]), preds[ ,2]), col = 'grey90', border = NA) ### adding fill to the plot
abline(fit) ## plotting the model in the graph

lines(newx, preds[ ,3], lty = 'dashed', col = 'red') ## plotting intervals
lines(newx, preds[ ,2], lty = 'dashed', col = 'red') ## plotting intervals

*********************************************************************************************************************************************

PLEASE COMMENT ON ANY FURTHER QUERIES REGARDING THIS CODE. PLEASE UPVOTE.


Related Solutions

In simple linear regression, at what value of the independent variable, X, will the 95% confidence...
In simple linear regression, at what value of the independent variable, X, will the 95% confidence interval for the average value of Y be narrowest? At what value will the 95% prediction interval for the value of Y for a single new observation be narrowest?
For the data set below, calculate r, r 2, and a 95% confidence interval in r...
For the data set below, calculate r, r 2, and a 95% confidence interval in r units. Then write a one- to two-sentence conclusion statement that includes whether the null hypothesis was rejected or not. Assume a two-tailed hypothesis and α = .05. Case 1 Case 2 Case 3 Case 4 Case 5 Case 6 X 1.05 1.15 1.30 2.00 1.75 1.00 Y 2 2 3 4 5 2
Using R and the data in the table below, perform the regression of D on C...
Using R and the data in the table below, perform the regression of D on C (i.e., report the regression equation). C D 3 2 6 7 8 5 9 4 1 0 3 4 Hint: The code to enter the vectors C and D into R is: C <- c(3, 6, 8, 9, 1, 3) D <- c(2, 7, 5, 4, 0, 4) You must figure out how to obtain the regression equation from R. Enter the code below...
Construct a? 95% confidence interval to estimate the population proportion using the data below. x =...
Construct a? 95% confidence interval to estimate the population proportion using the data below. x = 29 n = 90 N = 500 The? 95% confidence interval for the population proportion is? (_,_).
how do you test for regression in R studio with variables x and y
how do you test for regression in R studio with variables x and y
Plot the original data and the regression “line” ************USING Matlab************. "Submit plot" USING MATLAB! USING MATLAB!...
Plot the original data and the regression “line” ************USING Matlab************. "Submit plot" USING MATLAB! USING MATLAB! USING MATLAB! ONLY BY USING MATLAB!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 14.9 The concentration of E. coli bacteria in a swimming area is monitored after a storm: t (hr)                     4           8         12        16    20 24 c (CFU/100 mL) 1600     1320   1000     890 650 560 The time is measured in hours following the end of the storm and the unit CFU is a .colony forming unit.. Use this data to estimate (a)...
9) Use the following data to estimate a linear regression equation between y and x. Interpret...
9) Use the following data to estimate a linear regression equation between y and x. Interpret the estimated slope coefficient. Predict y for an x value of 9. Calculate and interpret the model’s R-squared. x y 21 12 17 10 11 8 3 5 13 15
Run a linear regression using Excel’s Data Analysis regression tool. Construct the linear regression equation and...
Run a linear regression using Excel’s Data Analysis regression tool. Construct the linear regression equation and determine the predicted total sales value if the number of promotions is 6. Is there a significant relationship? Clearly explain your reasoning using the regression results. Number of Promotions Total Sales 3 2554 2 1746 11 2755 14 1935 15 2461 4 2727 5 2231 14 2791 12 2557 4 1897 2 2022 7 2673 11 2947 11 1573 14 2980
.  Draw a plot of the following set of data and determine the linear regression equation.  What is...
.  Draw a plot of the following set of data and determine the linear regression equation.  What is the      value of the slope and intercept?   What is r and R2?  Are there any outlier values?   (15 points)                                 Age (X):     20  25  36  29  41  35  56  43  66  50  59  67  51  75  75  81  54  66  52  48            Total Body Water (Y):     61  57  52  59  53  58  48  51  37  44  42  41  48  38  41  39  47  42  51  50  
Running a linear regression produces the following : hat y =37.5-12.75x r = - 0.72 r...
Running a linear regression produces the following : hat y =37.5-12.75x r = - 0.72 r ^ 2 = 0.52 SE slope =2.85 n = 29 a) Is this a positive or negative correlation? How do you know? b) Without running the t-tests, does this appear to be a strong correlation? c) Based on the test statistic t = (slope)/(SESlope) can we claim there is correlation?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT