R : Copyright 2005, The R Foundation for Statistical Computing Version 2.1.1 (2005-06-20), ISBN 3-900051-07-0 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for a HTML browser interface to help. Type 'q()' to quit R. > ### *
> ### > attach(NULL, name = "CheckExEnv") > assign(".CheckExEnv", as.environment(2), pos = length(search())) # base > ## add some hooks to label plot pages for base and grid graphics > setHook("plot.new", ".newplot.hook") > setHook("persp", ".newplot.hook") > setHook("grid.newpage", ".gridplot.hook") > > assign("cleanEx", + function(env = .GlobalEnv) { + rm(list = ls(envir = env, all.names = TRUE), envir = env) + RNGkind("default", "default") + set.seed(1) + options(warn = 1) + delayedAssign("T", stop("T used instead of TRUE"), + assign.env = .CheckExEnv) + delayedAssign("F", stop("F used instead of FALSE"), + assign.env = .CheckExEnv) + sch <- search() + newitems <- sch[! sch %in% .oldSearch] + for(item in rev(newitems)) + eval(substitute(detach(item), list(item=item))) + missitems <- .oldSearch[! .oldSearch %in% sch] + if(length(missitems)) + warning("items ", paste(missitems, collapse=", "), + " have been removed from the search path") + }, + env = .CheckExEnv) > assign("..nameEx", "__{must remake R-ex/*.R}__", env = .CheckExEnv) # for now > assign("ptime", proc.time(), env = .CheckExEnv) > grDevices::postscript("SemiPar-Examples.ps") > assign("par.postscript", graphics::par(no.readonly = TRUE), env = .CheckExEnv) > options(contrasts = c(unordered = "contr.treatment", ordered = "contr.poly")) > options(warn = 1) > library('SemiPar') Loading required package: cluster Loading required package: nlme Loading required package: MASS > > assign(".oldSearch", search(), env = .CheckExEnv) > assign(".oldNS", loadedNamespaces(), env = .CheckExEnv) > cleanEx(); ..nameEx <- "age.income" > > ### * age.income > > flush(stderr()); flush(stdout()) > > ### Name: age.income > ### Title: Age/income data > ### Aliases: age.income > ### Keywords: datasets > > ### ** Examples > > library(SemiPar) > data(age.income) > attach(age.income) > plot(age,log.income) > > > > cleanEx(); ..nameEx <- "bpd" > > ### * bpd > > flush(stderr()); flush(stdout()) > > ### Name: bpd > ### Title: Bronchopulmonary dysplasia data > ### Aliases: bpd > ### Keywords: datasets > > ### ** Examples > > library(SemiPar) > data(bpd) > attach(bpd) > plot(birthweight,BPD) > boxplot(split(birthweight,BPD),col="green") > > > > cleanEx(); ..nameEx <- "calif.air.poll" > > ### * calif.air.poll > > flush(stderr()); flush(stdout()) > > ### Name: calif.air.poll > ### Title: California air polution data > ### Aliases: calif.air.poll > ### Keywords: datasets > > ### ** Examples > > library(SemiPar) > data(calif.air.poll) > pairs(calif.air.poll) > > > > cleanEx(); ..nameEx <- "copper" > > ### * copper > > flush(stderr()); flush(stdout()) > > ### Name: copper > ### Title: Copper data > ### Aliases: copper > ### Keywords: datasets > > ### ** Examples > > library(SemiPar) > data(copper) > pairs(copper[,4:7]) > > > > cleanEx(); ..nameEx <- "elec.temp" > > ### * elec.temp > > flush(stderr()); flush(stdout()) > > ### Name: elec.temp > ### Title: Electricity usage and temperature data > ### Aliases: elec.temp > ### Keywords: datasets > > ### ** Examples > > library(SemiPar) > data(elec.temp) > attach(elec.temp) > plot(usage,temp) > > > > cleanEx(); ..nameEx <- "ethanol" > > ### * ethanol > > flush(stderr()); flush(stdout()) > > ### Name: ethanol > ### Title: Ethanol data > ### Aliases: ethanol > ### Keywords: datasets > > ### ** Examples > > library(SemiPar) > data(ethanol) > pairs(ethanol) > > > > cleanEx(); ..nameEx <- "fitted.spm" > > ### * fitted.spm > > flush(stderr()); flush(stdout()) > > ### Name: fitted.spm > ### Title: Fitted values for semiparametric regression. > ### Aliases: fitted.spm > ### Keywords: models smooth regression > > ### ** Examples > > library(SemiPar) > data(fossil) > attach(fossil) > fit <- spm(strontium.ratio~f(age)) > plot(fit) > points(age,fitted(fit),col="red") > > > > cleanEx(); ..nameEx <- "fossil" > > ### * fossil > > flush(stderr()); flush(stdout()) > > ### Name: fossil > ### Title: Fossil data > ### Aliases: fossil > ### Keywords: datasets > > ### ** Examples > > library(SemiPar) > data(fossil) > attach(fossil) > plot(age,strontium.ratio) > > > > cleanEx(); ..nameEx <- "fuel.frame" > > ### * fuel.frame > > flush(stderr()); flush(stdout()) > > ### Name: fuel.frame > ### Title: Automobile data from consumer reports > ### Aliases: fuel.frame > ### Keywords: datasets > > ### ** Examples > > library(SemiPar) > data(fuel.frame) > pairs(fuel.frame) > par(mfrow=c(2,2)) > fuel.fit <- lm(Fuel ~ Weight + Disp.,fuel.frame) > plot(fuel.fit,ask=FALSE) > par(mfrow=c(1,1)) > > > > graphics::par(get("par.postscript", env = .CheckExEnv)) > cleanEx(); ..nameEx <- "janka" > > ### * janka > > flush(stderr()); flush(stdout()) > > ### Name: janka > ### Title: Janka hardness data > ### Aliases: janka > ### Keywords: datasets > > ### ** Examples > > library(SemiPar) > data(janka) > attach(janka) > plot(dens,hardness) > > > > cleanEx(); ..nameEx <- "lidar" > > ### * lidar > > flush(stderr()); flush(stdout()) > > ### Name: lidar > ### Title: LIDAR data > ### Aliases: lidar > ### Keywords: datasets > > ### ** Examples > > library(SemiPar) > data(lidar) > attach(lidar) > plot(range,logratio) > > > > cleanEx(); ..nameEx <- "lines.spm" > > ### * lines.spm > > flush(stderr()); flush(stdout()) > > ### Name: lines.spm > ### Title: Add a curves to an existing plot. > ### Aliases: lines.spm > ### Keywords: models smooth regression > > ### ** Examples > > library(SemiPar) > data(fossil) > attach(fossil) > fit <- spm(strontium.ratio~f(age)) > plot(fossil,type="n") > lines(fit) > points(fossil) > > # Now do several customisations > > op <- par(bg="white") > par(bg="honeydew") > plot(fossil,type="n") > lines(fit,col="green",lwd=5,shade.col="mediumpurple1") > points(fossil,col="orange",pch=16) > par(op) > > > > > graphics::par(get("par.postscript", env = .CheckExEnv)) > cleanEx(); ..nameEx <- "milan.mort" > > ### * milan.mort > > flush(stderr()); flush(stdout()) > > ### Name: milan.mort > ### Title: Milan mortality data > ### Aliases: milan.mort > ### Keywords: datasets > > ### ** Examples > > library(SemiPar) > data(milan.mort) > pairs(milan.mort,pch=".") > > > > cleanEx(); ..nameEx <- "monitor.mercury" > > ### * monitor.mercury > > flush(stderr()); flush(stdout()) > > ### Name: monitor.mercury > ### Title: Mercury biomonintoring data > ### Aliases: monitor.mercury > ### Keywords: datasets > > ### ** Examples > > library(SemiPar) > data(monitor.mercury) > pairs(monitor.mercury) > > > > cleanEx(); ..nameEx <- "onions" > > ### * onions > > flush(stderr()); flush(stdout()) > > ### Name: onions > ### Title: Onions data > ### Aliases: onions > ### Keywords: datasets > > ### ** Examples > > library(SemiPar) > data(onions) > attach(onions) > points.cols <- c("red","blue") > plot(dens,yield,col=points.cols[location+1],pch=16) > legend(100,250,c("Purnong Landing","Virginia"),col=points.cols,pch=rep(16,2)) > > > > cleanEx(); ..nameEx <- "pig.weights" > > ### * pig.weights > > flush(stderr()); flush(stdout()) > > ### Name: pig.weights > ### Title: Pig weight data > ### Aliases: pig.weights > ### Keywords: datasets > > ### ** Examples > > library(SemiPar) > data(pig.weights) > library(lattice) > xyplot(weight~num.weeks,data=pig.weights,groups=id.num,type="b") > > > > cleanEx(); ..nameEx <- "plot.spm" > > ### * plot.spm > > flush(stderr()); flush(stdout()) > > ### Name: plot.spm > ### Title: Semiparametric regression plotting > ### Aliases: plot.spm > ### Keywords: models smooth regression > > ### ** Examples > > library(SemiPar) > data(fossil) > attach(fossil) > fit <- spm(strontium.ratio~f(age)) > plot(fit) > > # Now do several customisations > > op <- par(bg="white") > par(bg="honeydew") > plot(fit,ylim=range(strontium.ratio),col="green", + lwd=5,shade.col="mediumpurple1",rug.col="blue") > points(age,strontium.ratio,col="orange",pch=16) > par(op) > > > > > graphics::par(get("par.postscript", env = .CheckExEnv)) > cleanEx(); ..nameEx <- "predict.spm" > > ### * predict.spm > > flush(stderr()); flush(stdout()) > > ### Name: predict.spm > ### Title: Semiparametric regression prediction. > ### Aliases: predict.spm > ### Keywords: models smooth regression > > ### ** Examples > > library(SemiPar) > data(fossil) > attach(fossil) > fit <- spm(strontium.ratio~f(age)) > newdata.age <- data.frame(age=c(90,100,110,120,130)) > preds <- predict(fit,newdata=newdata.age,se=TRUE) > print(preds) $fit [1] 0.7072402 0.7074086 0.7073363 0.7074190 0.7073856 $se [1] 4.352286e-05 1.241221e-05 6.764213e-06 8.208272e-06 1.818117e-04 > > plot(fit,xlim=c(90,130)) > points(unlist(newdata.age),preds$fit,col="red") > points(unlist(newdata.age),preds$fit+2*preds$se,col="blue") > points(unlist(newdata.age),preds$fit-2*preds$se,col="green") > > > > cleanEx(); ..nameEx <- "print.spm" > > ### * print.spm > > flush(stderr()); flush(stdout()) > > ### Name: print.spm > ### Title: Prints semiparametric regression fit object. > ### Aliases: print.spm > ### Keywords: models smooth regression > > ### ** Examples > > library(SemiPar) > data(fossil) > attach(fossil) > fit <- spm(strontium.ratio~f(age)) > print(fit) This is an spm() fit object; a list with components named: fit info aux The names() function can be used to obtain names of components and sub-components. The summary() function can be used to summarise the fit aspects of the object. > > > > cleanEx(); ..nameEx <- "ragweed" > > ### * ragweed > > flush(stderr()); flush(stdout()) > > ### Name: ragweed > ### Title: Ragweed data > ### Aliases: ragweed > ### Keywords: datasets > > ### ** Examples > > library(SemiPar) > data(ragweed) > pairs(ragweed,pch=".") > > > > cleanEx(); ..nameEx <- "residuals.spm" > > ### * residuals.spm > > flush(stderr()); flush(stdout()) > > ### Name: residuals.spm > ### Title: Residuals for semiparametric regression. > ### Aliases: residuals.spm > ### Keywords: models smooth regression > > ### ** Examples > > library(SemiPar) > data(fossil) > attach(fossil) > fit <- spm(strontium.ratio~f(age)) > plot(age,residuals(fit)) > abline(0,0) > > > > cleanEx(); ..nameEx <- "retire.plan" > > ### * retire.plan > > flush(stderr()); flush(stdout()) > > ### Name: retire.plan > ### Title: Retirement plan data > ### Aliases: retire.plan > ### Keywords: datasets > > ### ** Examples > > library(SemiPar) > data(retire.plan) > pairs(retire.plan) > > > > cleanEx(); ..nameEx <- "salinity" > > ### * salinity > > flush(stderr()); flush(stdout()) > > ### Name: salinity > ### Title: Salinity data > ### Aliases: salinity > ### Keywords: datasets > > ### ** Examples > > library(SemiPar) > data(salinity) > pairs(salinity) > > > > cleanEx(); ..nameEx <- "sausage" > > ### * sausage > > flush(stderr()); flush(stdout()) > > ### Name: sausage > ### Title: Sausage data > ### Aliases: sausage > ### Keywords: datasets > > ### ** Examples > > library(SemiPar) > data(sausage) > attach(sausage) > points.cols <- c("red","blue","green") > plot(sodium,calories,col=points.cols[type],pch=16) > legend(200,180,c("beef","pork","poultry"),col=points.cols,pch=rep(16,3)) > > > > cleanEx(); ..nameEx <- "scallop" > > ### * scallop > > flush(stderr()); flush(stdout()) > > ### Name: scallop > ### Title: Scallop abundance data > ### Aliases: scallop > ### Keywords: datasets > > ### ** Examples > > library(SemiPar) > data(scallop) > pairs(scallop) > > > > cleanEx(); ..nameEx <- "sitka" > > ### * sitka > > flush(stderr()); flush(stdout()) > > ### Name: sitka > ### Title: Sitka spruce data > ### Aliases: sitka > ### Keywords: datasets > > ### ** Examples > > library(SemiPar) > data(sitka) > attach(sitka) > library(lattice) > ozone.char <- rep("control",nrow(sitka)) > ozone.char[ozone==1] <- "ozone" > xyplot(log.size~days|ozone.char,data=sitka,groups=id.num,type="b") > > > > cleanEx(); ..nameEx <- "spm" > > ### * spm > > flush(stderr()); flush(stdout()) > > ### Name: spm > ### Title: Fit a SemiParametric regression Model > ### Aliases: spm > ### Keywords: nonlinear models smooth regression > > ### ** Examples > > library(SemiPar) > data(fossil) > attach(fossil) > fit <- spm(strontium.ratio~f(age)) > plot(fit) > summary(fit) Summary for non-linear components: df spar knots f(age) 12.14 2.929 25 Note this includes 1 df for the intercept. > > data(calif.air.poll) > attach(calif.air.poll) > fit <- spm(ozone.level ~ f(daggett.pressure.gradient)+ + f(inversion.base.height) + + f(inversion.base.temp)) > summary(fit) Summary for non-linear components: df spar knots f(daggett.pressure.gradient) 4.697 88.80 31 f(inversion.base.height) 4.198 2741.00 39 f(inversion.base.temp) 3.248 57.98 38 > par(mfrow=c(2,2)) > plot(fit) > > # The SemiPar User Manual contains several other examples > # and details of plotting parameters. > # > # The current version of the manual is posted on the web-site: > # > # www.maths.unsw.edu.au/~wand/papers.html > > > > graphics::par(get("par.postscript", env = .CheckExEnv)) > cleanEx(); ..nameEx <- "summary.spm" > > ### * summary.spm > > flush(stderr()); flush(stdout()) > > ### Name: summary.spm > ### Title: Semiparametric regression summary > ### Aliases: summary.spm > ### Keywords: models smooth regression > > ### ** Examples > > library(SemiPar) > data(onions) > attach(onions) > log.yield <- log(yield) > fit <- spm(log.yield~location+f(dens)) > summary(fit) Summary for linear components: coef se ratio p-value intercept 5.3880 0.24230 22.24 0 location -0.3325 0.02388 -13.92 0 Summary for non-linear components: df spar knots f(dens) 4.213 63.02 17 > > > > cleanEx(); ..nameEx <- "term.structure" > > ### * term.structure > > flush(stderr()); flush(stdout()) > > ### Name: term.structure > ### Title: Term structure data > ### Aliases: term.structure > ### Keywords: datasets > > ### ** Examples > > library(SemiPar) > data(term.structure) > attach(term.structure) > plot(time.to.maturity,price) > > > > cleanEx(); ..nameEx <- "trade.union" > > ### * trade.union > > flush(stderr()); flush(stdout()) > > ### Name: trade.union > ### Title: Trade union data > ### Aliases: trade.union > ### Keywords: datasets > > ### ** Examples > > library(SemiPar) > data(trade.union) > pairs(trade.union,pch=".") > > > > cleanEx(); ..nameEx <- "ustemp" > > ### * ustemp > > flush(stderr()); flush(stdout()) > > ### Name: ustemp > ### Title: U.S. temperature data > ### Aliases: ustemp > ### Keywords: datasets > > ### ** Examples > > library(SemiPar) > data(ustemp) > attach(ustemp) > grey.levs <- min.temp+20 > col.vec <- paste("grey",as.character(grey.levs),sep="") > plot(-longitude,latitude,col=col.vec,pch=16,cex=3,xlim=c(-130,-60)) > text(-longitude,latitude,as.character(city)) > > > > ### *