[R] Re : AUC under spline curve

Simon Wood sw283 at maths.bath.ac.uk
Mon Apr 10 18:09:19 CEST 2006


## simulated data...
x <- runif(100)
y <- rnorm(100)
## spline fit...
m <- gam(y~s(x,k=6,fx=TRUE))
## trapezoidal integration ...
n <- 1000 ## number of points in trap. approx
pd <- data.frame(x=seq(0,1,length=n))
dx <- pd$x[2]-pd$x[1]
f <- predict.gam(m,pd)
w <- rep(dx,n);w[1]<-w[n] <- w[2]/2 ## trapezoidal weights
sum(w*f) ## integral

## ... same again with standard error...

Xf <- predict.gam(m,pd,type="lpmatrix")
t(w)%*%Xf%*%coef(m) ## integral
sqrt(t(w)%*%Xf%*%m$Vp%*%t(Xf)%*%w) ## its standard error

best,
Simon

>- Simon Wood, Mathematical Sciences, University of Bath, Bath BA2 7AY
>-             +44 (0)1225 386603         www.maths.bath.ac.uk/~sw283/


On Mon, 10 Apr 2006 ssim at lic.co.nz wrote:

>
> Dear R list,
>
> I  have fitted cubic regression spline with fixed degree of freedom to a
> set of data using package mgcv. Now I want to calculate the area under the
> spline curve. Someone has suggested me to use trapezoidal rule. Do you know
> if someone has written a package that will carry out that analysis, and
> where can I download it ?
>
> Thanks in advance.
>
>
> Stella
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>




More information about the R-help mailing list