library(densEstBayes) ; data(OldFaithful2011)
# Obtain a density estimate for the `OldFaithful2011' data:
dest <- densEstBayes(OldFaithful2011,method = "SMFVB")
# Plot the density estimate:
plot(dest,xlab = "time interval between geyser eruptions (minutes)")
rug(jitter(OldFaithful2011,amount = 0.2),col = "dodgerblue")
# Obtain predictions at 60,70,80,90,100 and 110 seconds and
# add to them plot:
newdataVec <- seq(60,110,by = 10)
predictObj <- predict(dest,newdata = newdataVec,cred.fit = TRUE)
print(predictObj$fit)
points(newdataVec,predictObj$fit,col = "blue")
# Print and add to the plot the lower and upper limits of
# the pointwise 95% credible intervals:
print(predictObj$credLow.fit)
print(predictObj$credUpp.fit)
points(newdataVec,predictObj$credLow.fit,col = "red")
points(newdataVec,predictObj$credUpp.fit,col = "red")
Run the code above in your browser using DataLab