gbm confidence intervals in R? - r

Anybody know how to calculate confidence intervals from the gbm.predict() function? I'd like a method to ascertain a 95% confidence band on my gbm predictions.

Related

Difference between confint and predict

I'm analyzing a linear model with 2 factors and I need to find a confidence interval for the response variable. As I understand it confint() and predict(, interval='confidence') both find confidence intervals so what is the difference between them?
confint() finds confidence intervals on the model parameters
predict(., interval="confidence") finds confidence intervals on the model predictions

plotting bootstrapped confidence intervals

I am attempting to plot a bootstrapped linear model and I would like to include the models upper and lower confidence intervals and am not sure I am calculating the bootstrapped upper and lower bounds correctly. Below is an example using the cars dataset in r in conjunction with the boot library.
library(boot)
plot(speed~dist,cars,pch=21,bg="grey")
## standard linear model
mod<-lm(speed~dist,cars)
new.dat=seq(0,120,10)
mod.fit<-predict(mod,newdata=data.frame(dist=new.dat),interval="confidence")
lines(new.dat,mod.fit[,1]);#line fit
lines(new.dat,mod.fit[,2],lty=2);#lower confidence interval
lines(new.dat,mod.fit[,3],lty=2);#upper confidence interval
##Bootstrapped Confidence Intervals
lm.boot=function(formula, data, indices) {
d <- data[indices,] # allows boot to select sample
fit <- lm(formula, data=d)
return(coef(fit))
}
results <- boot(data=cars, statistic=lm.boot,
R=100, formula=speed~dist)
N.mod<-nrow(cars)
x.val<-new.dat
y.boot.fit<-(mean(results$t[,2])*x.val)+mean(results$t[,1])
y.boot.fit.uCI<-y.boot.fit+qt(0.975,N.mod-2)*sd(results$t[,2])
y.boot.fit.lCI<-y.boot.fit-qt(0.975,N.mod-2)*sd(results$t[,2])
lines(new.dat,y.boot.fit,col="red")
lines(new.dat,y.boot.fit.lCI,lty=2,col="red");#lower confidence interval
lines(new.dat,y.boot.fit.uCI,lty=2,col="red");#upper confidence interval
legend("bottomright",legend=c("Linear Model","Bootstrapped Model"),lty=1,
col=c("black","red"),ncol=1,cex=1,bty="n",y.intersp=1.5,x.intersp=0.75,
xpd=NA,xjust=0.5)
Using this code I get this output where the bootstrapped confidence interval is on top of the bootstrapped fitted line.
Any help/direction is appreciated. Granted this might be better suited for Cross Validated or other statistic specific boards.

Setting the confidence interval in acf plots

I plotted the autocorrelation function of a given set of residuals I obtained from estimating a linear regression model:
> require("stats")
> acf(Reg$residuals)
It resulted in the following graphic:
I then wanted to look up what kind of confidence interval (95%, 99%) is displayed, but there is no information on that within the help section of the function. In addition to that I could not find a way to adjust the confidence interval manually.
Is there a way to manually set the confidence interval displayed?
See ?plot.acf:
plot(x, ci = 0.95, ...)
and:
ci: coverage probability for confidence interval. Plotting of the confidence interval is suppressed if ci is zero or negative.
That is, the default is 95% confidence intervals, and e.g.:
plot(acf(Reg$residuals), ci = 0.99)
should plot the 99% confidence intervals.

Calculating 95% confidence intervals in quantile regression in R using rq function for polynomial

This is an extension from this question about 95% confidence intervals for quantile regression using rquant:
Calculating 95% confidence intervals in quantile regression in R using rq function
Here, the goal is to determine 95% confidence intervals for quantile regression for a polynomial fit.
Data:
x<-1:50
y<-c(x[1:50]+rnorm(50,0,5))^2
Attempt using the approach in the aforementioned question:
QR.b <- boot.rq(cbind(1,x,x^2),y,tau=0.5, R=1000)
t(apply(QR.b, 2, quantile, c(0.025,0.975)))
2.5% 97.5%
[1,] -14.9880661 126.906083
[2,] -20.5603779 5.424308
[3,] 0.8608203 1.516513
But this of course determines the 95% CI for each coefficient independently, and would appear to overestimates the interval (see image below).
I had another idea for an approach simply determining the coefficients from a bootstrap sample of the data (i.e. rq(y~x+I(x^2)) on thousands of samples of y and x), but wanted to see if there is something build it to the package.

Profile likelihood based confidence intervals for gamma cdf

Can anyone please help me with the construction of the point-wise profile likelihood based confidence intervals for the gamma cdf?
I'm aware of the construction of profile likelihood based confidence intervals for the estimated gamma parameters but not for the estimated cdf. Help me with the theory and the coding using R programming!!
Thanks in advance.

Resources