EVOLUTION-MANAGER
Edit File: Predict.matrix.soap.film.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Prediction matrix for soap film smooth</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for Predict.matrix.soap.film {mgcv}"><tr><td>Predict.matrix.soap.film {mgcv}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Prediction matrix for soap film smooth</h2> <h3>Description</h3> <p> Creates a prediction matrix for a soap film smooth object, mapping the coefficients of the smooth to the linear predictor component for the smooth. This is the <code><a href="Predict.matrix.html">Predict.matrix</a></code> method function required by <code><a href="gam.html">gam</a></code>. </p> <h3>Usage</h3> <pre> ## S3 method for class 'soap.film' Predict.matrix(object,data) ## S3 method for class 'sw' Predict.matrix(object,data) ## S3 method for class 'sf' Predict.matrix(object,data) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>object</code></td> <td> <p>A class <code>"soap.film"</code>, <code>"sf"</code> or <code>"sw"</code> object.</p> </td></tr> <tr valign="top"><td><code>data</code></td> <td> <p>A list list or data frame containing the arguments of the smooth at which predictions are required.</p> </td></tr> </table> <h3>Details</h3> <p>The smooth object will be largely what is returned from <code><a href="smooth.construct.so.smooth.spec.html">smooth.construct.so.smooth.spec</a></code>, although elements <code>X</code> and <code>S</code> are not needed, and need not be present, of course. </p> <h3>Value</h3> <p> A matrix. This may have an <code>"offset"</code> attribute corresponding to the contribution from any known boundary conditions on the smooth. </p> <h3>Author(s)</h3> <p> Simon N. Wood <a href="mailto:s.wood@bath.ac.uk">s.wood@bath.ac.uk</a></p> <h3>References</h3> <p><a href="http://www.maths.bris.ac.uk/~sw15190/">http://www.maths.bris.ac.uk/~sw15190/</a> </p> <h3>See Also</h3> <p><code><a href="smooth.construct.so.smooth.spec.html">smooth.construct.so.smooth.spec</a></code></p> <h3>Examples</h3> <pre> ## This is a lower level example. The basis and ## penalties are obtained explicitly ## and `magic' is used as the fitting routine... require(mgcv) set.seed(66) ## create a boundary... fsb <- list(fs.boundary()) ## create some internal knots... knots <- data.frame(x=rep(seq(-.5,3,by=.5),4), y=rep(c(-.6,-.3,.3,.6),rep(8,4))) ## Simulate some fitting data, inside boundary... n<-1000 x <- runif(n)*5-1;y<-runif(n)*2-1 z <- fs.test(x,y,b=1) ind <- inSide(fsb,x,y) ## remove outsiders z <- z[ind];x <- x[ind]; y <- y[ind] n <- length(z) z <- z + rnorm(n)*.3 ## add noise ## plot boundary with knot and data locations plot(fsb[[1]]$x,fsb[[1]]$y,type="l");points(knots$x,knots$y,pch=20,col=2) points(x,y,pch=".",col=3); ## set up the basis and penalties... sob <- smooth.construct2(s(x,y,bs="so",k=40,xt=list(bnd=fsb,nmax=100)), data=data.frame(x=x,y=y),knots=knots) ## ... model matrix is element `X' of sob, penalties matrices ## are in list element `S'. ## fit using `magic' um <- magic(z,sob$X,sp=c(-1,-1),sob$S,off=c(1,1)) beta <- um$b ## produce plots... par(mfrow=c(2,2),mar=c(4,4,1,1)) m<-100;n<-50 xm <- seq(-1,3.5,length=m);yn<-seq(-1,1,length=n) xx <- rep(xm,n);yy<-rep(yn,rep(m,n)) ## plot truth... tru <- matrix(fs.test(xx,yy),m,n) ## truth image(xm,yn,tru,col=heat.colors(100),xlab="x",ylab="y") lines(fsb[[1]]$x,fsb[[1]]$y,lwd=3) contour(xm,yn,tru,levels=seq(-5,5,by=.25),add=TRUE) ## Plot soap, by first predicting on a fine grid... ## First get prediction matrix... X <- Predict.matrix2(sob,data=list(x=xx,y=yy)) ## Now the predictions... fv <- X%*%beta ## Plot the estimated function... image(xm,yn,matrix(fv,m,n),col=heat.colors(100),xlab="x",ylab="y") lines(fsb[[1]]$x,fsb[[1]]$y,lwd=3) points(x,y,pch=".") contour(xm,yn,matrix(fv,m,n),levels=seq(-5,5,by=.25),add=TRUE) ## Plot TPRS... b <- gam(z~s(x,y,k=100)) fv.gam <- predict(b,newdata=data.frame(x=xx,y=yy)) names(sob$sd$bnd[[1]]) <- c("xx","yy","d") ind <- inSide(sob$sd$bnd,xx,yy) fv.gam[!ind]<-NA image(xm,yn,matrix(fv.gam,m,n),col=heat.colors(100),xlab="x",ylab="y") lines(fsb[[1]]$x,fsb[[1]]$y,lwd=3) points(x,y,pch=".") contour(xm,yn,matrix(fv.gam,m,n),levels=seq(-5,5,by=.25),add=TRUE) </pre> <hr /><div style="text-align: center;">[Package <em>mgcv</em> version 1.8-28 <a href="00Index.html">Index</a>]</div> </body></html>