Question

I need help plotting the question below in R

Plot a summary of the predictive distribution (i.e., predictive mean and 90% interval. You will find lines command very helpful.) for VIX returns ranging from-20% to 20%.

Date SPX 1/4/10 0 1132.99 19.351136.52 19.16 1137.14 9.06 1141.69 18.131144.98 17.55 1146.98 18.25 1136.22 17.85 1145.68 17.63 1148.46 17.91 1136.03 17.58 1150.23 18.68 1138.04 22.27 1116.48 1091.76 25.41 1096.78 24.55 1092.17 1/27/1023.14 1097.5 23.73 1084.53 24.62 1073.87 22.59 1089.19 21.48 1103.32 21.6 1097.28 1063.11 26.11 1066.19 26.51 1056.74 261070.52 25.41068.13 1078.47 22.73 1075.51 22.251094.87 21.721099.51 20.63 1106.75 0.02 1109.17 19.94 1108.02 21.371094.6 20.27 1105.24 01 1102.94 1/5/10 1/12/10 1/19/10 1/20/10 27.31 1 1/29/10 2/5/10 2/8/10 2/9/10 2/10/10 2/12/10 2/19/10 2/23/10 2/25/10 2

0 0
Add a comment Improve this question Transcribed image text
Answer #1

We solve this using the open source statistical package R , the R snippet is as below

# read the data into R dataframe
df<- read.csv("VIX.csv",header=TRUE)
str(df)


fit <- lm(cost~VIX,data=df)
summary(fit)


newdata = data.frame(VIX=15)


predict(fit, newdata, interval="predict")


# 1. Add predictions
pred.int <- predict(fit, interval = "prediction")
mydata <- cbind(df, pred.int)
# 2. Regression line + confidence intervals
library("ggplot2")
p <- ggplot(mydata, aes(VIX, SPX)) + geom_point() + stat_smooth(method = lm)
# 3. Add prediction intervals
p + geom_line(aes(y = lwr), color = "red", linetype = "dashed")+ geom_line(aes(y = upr), color = "red", linetype = "dashed")

The results are

> summary(fit)

Call:

lm(formula = SPX ~ VIX, data = df)

Residuals:

Min 1Q Median 3Q Max

-284.70 -88.06 -13.35 82.68 223.65

Coefficients:

Estimate Std. Error t value Pr(>|t|)   

(Intercept) 270.23 58.37 4.629 0.000208 ***

VIX 74.56 11.54 6.460 4.46e-06 ***

---

Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 149.2 on 35 degrees of freedom

Multiple R-squared: 0.6986, Adjusted R-squared: 0.6819

F-statistic: 41.73 on 1 and 35 DF, p-value: 4.459e-06

> predict(fit, newdata, interval="predict")

fit lwr upr

1 1388.613 973.4366 1803.79

Add a comment
Know the answer?
Add Answer to:
I need help plotting the question below in R Plot a summary of the predictive distribution...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT