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("mixreg-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('mixreg') > > assign(".oldSearch", search(), env = .CheckExEnv) > assign(".oldNS", loadedNamespaces(), env = .CheckExEnv) > cleanEx(); ..nameEx <- "bootcomp" > > ### * bootcomp > > flush(stderr()); flush(stdout()) > > ### Name: bootcomp > ### Title: Perform a bootstrap test for the number of components in a > ### mixture of regressions. > ### Aliases: bootcomp > ### Keywords: models regression > > ### ** Examples > > TS1 <- list(list(beta=c(3.0,0.1),sigsq=16,lambda=0.5), + list(beta=c(0.0,0.0),sigsq=16,lambda=0.5)) > TS2 <- list(list(beta=c(3.0,0.1),sigsq=9,lambda=1/3), + list(beta=c(1.5,0.05),sigsq=9,lambda=1/3), + list(beta=c(0.0,0.0),sigsq=9,lambda=1/3)) > data(aphids) > x <- aphids$n.aphids > y <- aphids$n.inf > ## Not run: > ##D nboot <- 1000 > ## End(Not run) > ## Don't show: > nboot <- 10 > ## End Don't show > boot.23 <- bootcomp(x,y,nboot=nboot,ts1=TS1,ts2=TS2) 1 2 3 4 5 6 7 8 9 10 > > > > cleanEx(); ..nameEx <- "cband" > > ### * cband > > flush(stderr()); flush(stdout()) > > ### Name: cband > ### Title: Calculate confidence and prediction bands for mixtures of > ### one-variable regressions. > ### Aliases: cband > ### Keywords: models regression > > ### ** Examples > > #See mixreg for examples. > > > > cleanEx(); ..nameEx <- "covmix" > > ### * covmix > > flush(stderr()); flush(stdout()) > > ### Name: covmix > ### Title: Calculate the covariance matrix of the parameter estimates for a > ### mixture of regressions. > ### Aliases: covmix > ### Keywords: models regression > > ### ** Examples > > #See mixreg for examples. > > > > cleanEx(); ..nameEx <- "mixreg" > > ### * mixreg > > flush(stderr()); flush(stdout()) > > ### Name: mixreg > ### Title: Fit a mixture of linear regressions. > ### Aliases: mixreg > ### Keywords: models regression > > ### ** Examples > > data(aphids) > x <- aphids$n.aphids > y <- aphids$n.inf > TS <- list(list(beta=c(3.0,0.1),sigsq=16,lambda=0.5), + list(beta=c(0.0,0.0),sigsq=16,lambda=0.5)) > fit <- mixreg(x,y,ncomp=2,theta.start=TS,data.name='aphids') EM step 1: max abs. change in coef.: 6.401772 EM step 2: max abs. change in coef.: 4.782379 EM step 3: max abs. change in coef.: 1.928931 EM step 4: max abs. change in coef.: 0.8011878 EM step 5: max abs. change in coef.: 0.4412921 EM step 6: max abs. change in coef.: 0.2338419 EM step 7: max abs. change in coef.: 0.0984745 EM step 8: max abs. change in coef.: 0.0351786 EM step 9: max abs. change in coef.: 0.0192962 EM step 10: max abs. change in coef.: 0.0115015 EM step 11: max abs. change in coef.: 0.0058445 EM step 12: max abs. change in coef.: 0.0027783 EM step 13: max abs. change in coef.: 0.0012812 EM step 14: max abs. change in coef.: 0.0005823 EM step 15: max abs. change in coef.: 0.0002628 EM step 16: max abs. change in coef.: 0.0001181 EM step 17: max abs. change in coef.: 5.3e-05 EM step 18: max abs. change in coef.: 2.37e-05 EM step 19: max abs. change in coef.: 1.06e-05 EM step 20: max abs. change in coef.: 4.8e-06 EM step 21: max abs. change in coef.: 2.1e-06 EM step 22: max abs. change in coef.: 1e-06 > cvm <- covmix(fit,x,y) > cbd <- cband(fit,cvm,x,y) > plot(cbd) > r <- resid.mix(fit,x,y) > plot(r) > r <- resid.mix(fit,x,y,std=TRUE) > qq.mix(r) > > > > cleanEx(); ..nameEx <- "plot.cband" > > ### * plot.cband > > flush(stderr()); flush(stdout()) > > ### Name: plot.cband > ### Title: Plot confidence bands for a mixture of regressions. > ### Aliases: plot.cband > ### Keywords: models regression > > ### ** Examples > > #See mixreg for examples. > > > > cleanEx(); ..nameEx <- "plot.mresid" > > ### * plot.mresid > > flush(stderr()); flush(stdout()) > > ### Name: plot.mresid > ### Title: Plot residuals for a fitted mixture of linear regressions. > ### Aliases: plot.mresid > ### Keywords: models regression hplot > > ### ** Examples > > #See mixreg for examples. > > > > cleanEx(); ..nameEx <- "qq.mix" > > ### * qq.mix > > flush(stderr()); flush(stdout()) > > ### Name: qq.mix > ### Title: Draw a normal quantile-quantile plot of the residuals from a > ### fitted mixture of linear regressions. > ### Aliases: qq.mix > ### Keywords: models regression hplot > > ### ** Examples > > #See mixreg for examples. > > > > cleanEx(); ..nameEx <- "resid.mix" > > ### * resid.mix > > flush(stderr()); flush(stdout()) > > ### Name: resid.mix > ### Title: Calculate the residuals of a mixture of linear regressions. > ### Aliases: resid.mix > ### Keywords: models regression > > ### ** Examples > > #See mixreg for examples. > > > > ### *