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("bayesmix-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('bayesmix') Loading required package: coda > > assign(".oldSearch", search(), env = .CheckExEnv) > assign(".oldNS", loadedNamespaces(), env = .CheckExEnv) > cleanEx(); ..nameEx <- "BMMmodel" > > ### * BMMmodel > > flush(stderr()); flush(stdout()) > > ### Name: BMMmodel > ### Title: Creates text for .bug-file and data for -inits.R and > ### -data.R-file > ### Aliases: BMMmodel print.JAGSmodel > ### Keywords: utilities > > ### ** Examples > > data(fish) > model <- BMMmodel(fish, k = 4, priors = list(kind = "independence", + parameter = "priorsFish", hierarchical = "tau"), + initialValues = list(S0 = 2)) > model Data for nodes: b0, B0inv, nu0Half, g0Half, g0G0Half, k, N, e, y Initial values for nodes: eta, mu, tau, S0 Model specification in BUGS language: var b0, B0inv, nu0Half, g0Half, g0G0Half, k, N, eta[4], mu[4], tau[4], S0, nu0S0Half, e[4], y[256], S[256]; model { for (i in 1:N) { y[i] ~ dnorm(mu[S[i]],tau[S[i]]); S[i] ~ dcat(eta[]); } for (j in 1:k) { mu[j] ~ dnorm(b0,B0inv); tau[j] ~ dgamma(nu0Half,nu0S0Half); } S0 ~ dgamma(g0Half,g0G0Half); nu0S0Half <- nu0Half * S0; eta[] ~ ddirch(e[]); } > > > > cleanEx(); ..nameEx <- "BMMpriors" > > ### * BMMpriors > > flush(stderr()); flush(stdout()) > > ### Name: BMMpriors > ### Title: Creates a 'BMMpriors' object > ### Aliases: BMMpriors > ### Keywords: utilities > > ### ** Examples > > data(fish) > priors <- BMMpriors(y = fish) > > > > cleanEx(); ..nameEx <- "JAGScontrol" > > ### * JAGScontrol > > flush(stderr()); flush(stdout()) > > ### Name: JAGScontrol > ### Title: Creates text for .cmd file > ### Aliases: JAGScontrol print.JAGScontrol > ### Keywords: utilities > > ### ** Examples > > control <- JAGScontrol(variables = "mu") > control Commands for JAGS: model in "jags.bug" data in "jags-data.R" compile inits in "jags-inits.R" initialize monitor set mu update 1000 coda * exit > > > > cleanEx(); ..nameEx <- "JAGSrun" > > ### * JAGSrun > > flush(stderr()); flush(stdout()) > > ### Name: JAGSrun > ### Title: MCMC sampling of Bayesian models > ### Aliases: JAGSrun print.jags jags > ### Keywords: utilities > > ### ** Examples > > data(fish) > prefix <- "fish" > variables <- c("mu","tau","eta") > k <- 3 > modelFish <- BMMmodel(k = k, priors = list(kind = "independence", + parameter = "priorsFish", hierarchical = "tau")) > controlFish <- JAGScontrol(variables = c(variables, "S"), draw = 100, seed = 1) > ## Installation of JAGS necessary for applying these functions > if (haveJAGS()) { + z1 <- JAGSrun(fish, prefix, model = modelFish, initialValues = list(S0 = 2), + control = controlFish, cleanup = TRUE, tmp = FALSE) + zSort <- Sort(z1, "mu") + BMMposteriori(zSort) + } > data(darwin) > prefix <- "darwin" > k <- 2 > modelDarwin <- BMMmodel(k = k, priors = list(kind = "independence", + parameter = "priorsUncertain"), aprioriWeights = c(1, 15), + no.empty.classes = TRUE, restrict = "tau") > ## Installation of JAGS necessary for applying these functions > if (haveJAGS()) { + z2 <- JAGSrun(darwin, prefix, model = modelDarwin, control = + JAGScontrol(variables = variables, draw = 3000, burnIn = 1000, + seed = 1), cleanup = TRUE, tmp = FALSE) + plot(z2, variables = "mu") + } > > > > cleanEx(); ..nameEx <- "darwin" > > ### * darwin > > flush(stderr()); flush(stdout()) > > ### Name: darwin > ### Title: Differences in heights between plants > ### Aliases: darwin > ### Keywords: datasets > > ### ** Examples > > data(darwin) > ## Estimated sample density > plot(density(darwin[[1]]), ylim = c(0, 0.02), main = "Outlier modelling") > ss <- seq(-100, 100, by = 1) > ## Normal density with estimated mean and sd of whole sample > lines(ss, dnorm(ss, mean = mean(darwin), sd = sd(darwin)), col = "red") > ## Normal density with estimated mean and sd of sample, where the 2 > ## extremely small values are removed > lines(ss, dnorm(ss, mean = mean(darwin[-c(1:2),1]), sd = sd(darwin[-c(1:2),1])), + col = "green") > > > > cleanEx(); ..nameEx <- "fish" > > ### * fish > > flush(stderr()); flush(stdout()) > > ### Name: fish > ### Title: Fish length data > ### Aliases: fish > ### Keywords: datasets > > ### ** Examples > > data(fish) > ss <- seq(-3, 13, by = 0.01) > hist(fish[[1]], 20, freq = FALSE, main = "Fish data") > lines(ss, dnorm(ss, mean(fish), sd(fish)), col = "red") > > > > ### *