Skip to content

Commit

Permalink
Update uni.smooth.const-with-po.r
Browse files Browse the repository at this point in the history
  • Loading branch information
tjmahr committed May 8, 2019
1 parent 8348c4c commit 9342f7c
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions R/uni.smooth.const-with-po.r
Expand Up @@ -167,7 +167,7 @@ smooth.construct.mpi.smooth.spec<- function(object, data, knots)
Predict.matrix.mpi.smooth<-function(object,data)
## prediction method function for the `mpi' smooth class
{ m <- object$m+1; # spline order, m+1=3 default for cubic spline
q <- object$df +1
q <- object$df ## +1
Sig <- matrix(0,q,q) # Define Matrix Sigma
# elements of matrix Sigma for increasing smooth
for (i in 1:q) Sig[i,1:i] <- 1
Expand All @@ -178,24 +178,25 @@ Predict.matrix.mpi.smooth<-function(object,data)
n <- length(x)
ind <- x<=ul & x>=ll ## data in range
if (sum(ind)==n) { ## all in range
X <- spline.des(object$knots,x,m)$design
X <- X%*%Sig
X <- splines::spline.des(object$knots,x,m)$design
X <- X[,2:(q+1)]%*%Sig ## X <- X%*%Sig
} else { ## some extrapolation needed
## matrix mapping coefs to value and slope at end points...
D <- spline.des(object$knots,c(ll,ll,ul,ul),m,c(0,1,0,1))$design
D <- splines::spline.des(object$knots,c(ll,ll,ul,ul),m,c(0,1,0,1))$design
X <- matrix(0,n,ncol(D)) ## full predict matrix
if (sum(ind)> 0) X[ind,] <- spline.des(object$knots,x[ind],m)$design ## interior rows
if (sum(ind)> 0) X[ind,] <- splines::spline.des(object$knots,x[ind],m)$design ## interior rows
## Now add rows for linear extrapolation...
ind <- x < ll
if (sum(ind)>0) X[ind,] <- cbind(1,x[ind]-ll)%*%D[1:2,]
ind <- x > ul
if (sum(ind)>0) X[ind,] <- cbind(1,x[ind]-ul)%*%D[3:4,]
X <- X%*%Sig
X <- X[,2:(q+1)]%*%Sig
}
X
}



########################################################
### Adding Monotone decreasing SCOP-spline construction
########################################################
Expand Down

0 comments on commit 9342f7c

Please sign in to comment.