[R] Error in backSpline.npolySpline(sp) : spline must be monotone

Bazman76 h_a_patience at hotmail.com
Mon May 23 23:36:21 CEST 2011


I get the following error:

Error in backSpline.npolySpline(sp) : spline must be monotone

Has anyone had this error before? any ideas on a workaround?


> 
> vols=read.csv(file="C:/Documents and Settings/Hugh/My
> Documents/PhD/Swaption vols.csv" 
+ , header=TRUE, sep=",")
> X<-ts(vols[,2])
> #X
> 
> 
> dcOU<-function(x,t,x0,theta,log=FALSE){
+ Ex<-theta[1]/theta[2]+(x0-theta[1]/theta[2])*exp(-theta[2]*t)
+ Vx<-theta[3]^2*(1-exp(-2*theta[2]*t))/(2*theta[2])
+ dnorm(x,mean=Ex,sd=sqrt(Vx),log=log)
+ }
> OU.lik<-function(theta1,theta2,theta3){
+ n<-length(X)
+ dt<-deltat(X)
+ -sum(dcOU(X[2:n],dt,X[1:(n-1)],c(theta1,theta2,theta3),log=TRUE))
+ }
> 
> require(stats4)
Loading required package: stats4
> require(sde)
Loading required package: sde
Loading required package: MASS
Loading required package: fda
Loading required package: splines
Loading required package: zoo

To check the errata corrige of the book, type vignette("sde.errata")

Attaching package: 'sde'

The following object(s) are masked _by_ '.GlobalEnv':

    dcOU

> set.seed(1)
> #X<-sde.sim(model="OU",theta=c(3,1,2),N=10000,delta=1)
> mle(OU.lik,start=list(theta1=1,theta2=1,theta3=1),
+ method="L-BFGS-B",lower=c(-Inf,-Inf,-Inf),upper=c(Inf,Inf,Inf))->fit
> summary(fit)
Maximum likelihood estimation

Call:
mle(minuslogl = OU.lik, start = list(theta1 = 1, theta2 = 1, 
    theta3 = 1), method = "L-BFGS-B", lower = c(-Inf, -Inf, -Inf), 
    upper = c(Inf, Inf, Inf))

Coefficients:
         Estimate  Std. Error
theta1 0.03595581 0.013929892
theta2 4.30910365 1.663781710
theta3 0.02120220 0.004067477

-2 log L: -5136.327 
> 
> #ex3.01 R
> prof<-profile(fit)
> par(mfrow=c(1,3))
> plot(prof)
Error in backSpline.npolySpline(sp) : spline must be monotone

--
View this message in context: http://r.789695.n4.nabble.com/Error-in-backSpline-npolySpline-sp-spline-must-be-monotone-tp3545579p3545579.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list