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("boolean-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('boolean') Loading required package: rgenoud > > assign(".oldSearch", search(), env = .CheckExEnv) > assign(".oldNS", loadedNamespaces(), env = .CheckExEnv) > cleanEx(); ..nameEx <- "boolean" > > ### * boolean > > flush(stderr()); flush(stdout()) > > ### Name: boolean > ### Title: Partial-Observability Logit or Probit Models for Testing Boolean > ### Hypotheses > ### Aliases: boolean Boolean > ### Keywords: logic optimize distribution models > > ### ** Examples > > library("boolean") > set.seed(50) > x1<-rnorm(1000) > x2<-rnorm(1000) > x3<-rnorm(1000) > x4<-rnorm(1000) > x5<-rnorm(1000) > x6<-rnorm(1000) > y<-1-(1-pnorm(-2+0.33*x1+0.66*x2+1*x3)*1-(pnorm(1+1.5*x4-0.25*x5)*pnorm(1+0.2*x6))) > y <- y>runif(1000) > answer <- boolean(y ~( ((cons+x1+x2+x3)|((cons+x4+x5)&(cons+x6))) ), method="probit") > > ## Examine coefficients, standard errors, etc. > summary(answer) Model: y~(((cons+x1+x2+x3)|((cons+x4+x5)&(cons+x6)))) LogLik Iterations 1 -467.1378 32 Vars Coefs StdErrs Zscore ProbZ CI95Lo CI95Hi 1 cons -1.73611 0.35400 4.904 0.0000 -2.42996 -1.04226 2 x1 0.35630 0.15680 2.272 0.0115 0.04896 0.66363 3 x2 0.69787 0.18042 3.868 0.0001 0.34425 1.05150 4 x3 1.21986 0.26612 4.584 0.0000 0.69826 1.74145 5 cons 0.90127 0.15563 5.791 0.0000 0.59624 1.20631 6 x4 1.58494 0.18725 8.464 0.0000 1.21793 1.95196 7 x5 -0.27452 0.07694 3.568 0.0002 -0.42533 -0.12372 8 cons 1.15816 0.12672 9.139 0.0000 0.90979 1.40653 9 x6 0.21024 0.09606 2.189 0.0143 0.02197 0.39852 > > ## Examine "summary" output plus Hessian, gradient, etc. > show(answer) Model: y~(((cons+x1+x2+x3)|((cons+x4+x5)&(cons+x6)))) LogLik Iterations 1 -467.1378 32 Vars Coefs StdErrs Zscore ProbZ CI95Lo CI95Hi 1 cons -1.73611 0.35400 4.904 0.0000 -2.42996 -1.04226 2 x1 0.35630 0.15680 2.272 0.0115 0.04896 0.66363 3 x2 0.69787 0.18042 3.868 0.0001 0.34425 1.05150 4 x3 1.21986 0.26612 4.584 0.0000 0.69826 1.74145 5 cons 0.90127 0.15563 5.791 0.0000 0.59624 1.20631 6 x4 1.58494 0.18725 8.464 0.0000 1.21793 1.95196 7 x5 -0.27452 0.07694 3.568 0.0002 -0.42533 -0.12372 8 cons 1.15816 0.12672 9.139 0.0000 0.90979 1.40653 9 x6 0.21024 0.09606 2.189 0.0143 0.02197 0.39852 Hessian: [,1] [,2] [,3] [,4] [,5] [,6] [1,] 48.227065 11.7733066 25.452749 41.261633 39.9504756 -22.207223 [2,] 11.773307 50.4195611 -9.426805 13.292399 3.1173670 -1.352251 [3,] 25.452749 -9.4268046 54.164292 13.438779 14.2507190 -7.310498 [4,] 41.261633 13.2923988 13.438779 53.345202 20.6095187 -9.478340 [5,] 39.950476 3.1173670 14.250719 20.609519 172.6610606 -84.535046 [6,] -22.207223 -1.3522513 -7.310498 -9.478340 -84.5350461 85.902646 [7,] 4.791269 3.5183632 3.002026 -2.221444 26.4654830 7.763311 [8,] 24.765682 3.7521922 10.164038 15.173612 79.2356578 -6.780162 [9,] -6.651578 0.6850428 -2.836254 -5.127811 0.5952359 1.744116 [,7] [,8] [,9] [1,] 4.791269 24.765682 -6.6515781 [2,] 3.518363 3.752192 0.6850428 [3,] 3.002026 10.164038 -2.8362535 [4,] -2.221444 15.173612 -5.1278106 [5,] 26.465483 79.235658 0.5952359 [6,] 7.763311 -6.780162 1.7441156 [7,] 192.395498 4.766118 4.9517553 [8,] 4.766118 138.275025 -38.4204932 [9,] 4.951755 -38.420493 129.5816617 Gradient: [,1] [,2] [,3] [,4] [,5] [1,] "cons" "x1" "x2" "x3" "cons" [2,] "-0.000101205" "-0.00025608" "0.000134435" "-3.6626e-05" "-0.000146656" [,6] [,7] [,8] [,9] [1,] "x4" "x5" "cons" "x6" [2,] "6.6134e-05" "1.711e-05" "-0.000115978" "-0.000166438" > > ## Plot first differences for model > plot(answer) > > ## Plot profiles > plot(answer, panel="boolprof") > > > > cleanEx(); ..nameEx <- "boolfirst" > > ### * boolfirst > > flush(stderr()); flush(stdout()) > > ### Name: boolfirst > ### Title: Graph First Differences after Boolean Logit/Probit > ### Aliases: boolfirst > ### Keywords: logic optimize distribution models > > ### ** Examples > > library("boolean") > set.seed(50) > x1<-rnorm(1000) > x2<-rnorm(1000) > x3<-rnorm(1000) > x4<-rnorm(1000) > x5<-rnorm(1000) > x6<-rnorm(1000) > e1<-rnorm(1000)/3 > e2<-rnorm(1000)/3 > e3<-rnorm(1000)/3 > y<-1-(1-pnorm(-2+0.33*x1+0.66*x2+1*x3+e1)*1-(pnorm(1+1.5*x4-0.25*x5+e2)*pnorm(1+0.2*x6+e3))) > y <- y>runif(1000) > answer <- boolean(y ~( ((cons+x1+x2+x3)|((cons+x4+x5)&(cons+x6))) ), method="probit") > boolfirst(answer, "x4") > boolprof(answer, "x1", instance=2) > > > > cleanEx(); ..nameEx <- "boolprep" > > ### * boolprep > > flush(stderr()); flush(stdout()) > > ### Name: boolprep > ### Title: Generate Functional Form for Boolean Logit or Probit > ### Aliases: boolprep > ### Keywords: logic optimize distribution models > > ### ** Examples > > boolprep("a&b", "y", "x1+x2", "x3+x4+x5") [1] "(a&b)" [1] "y ~( ((cons+x1+x2)&(cons+x3+x4+x5)) )" > > boolprep("a|(b&c)", "y", "x1+x2+x3", "x4+x5", "x6") [1] "(a|(b&c))" [1] "y ~( ((cons+x1+x2+x3)|((cons+x4+x5)&(cons+x6))) )" > > boolprep("(a|b|c)&(d|e)&f", "y", "x1+x2", "x3+x4+x5", "x6", "x7+x8", "x9+x10+x11", "x12+x13") [1] "((a|b|c)&(d|e)&f)" [1] "y ~( (((cons+x1+x2)|(cons+x3+x4+x5)|(cons+x6))&((cons+x7+x8)|(cons+x9+x10+x11))&(cons+x12+x13)) )" > > > > cleanEx(); ..nameEx <- "boolprof" > > ### * boolprof > > flush(stderr()); flush(stdout()) > > ### Name: boolprof > ### Title: Graph Profile Likelihoods for Boolean Logit/Probit > ### Aliases: boolprof > ### Keywords: logic optimize distribution models > > ### ** Examples > > library("boolean") > set.seed(50) > x1<-rnorm(1000) > x2<-rnorm(1000) > x3<-rnorm(1000) > x4<-rnorm(1000) > x5<-rnorm(1000) > x6<-rnorm(1000) > e1<-rnorm(1000)/3 > e2<-rnorm(1000)/3 > e3<-rnorm(1000)/3 > y<-1-(1-pnorm(-2+0.33*x1+0.66*x2+1*x3+e1)*1-(pnorm(1+1.5*x4-0.25*x5+e2)*pnorm(1+0.2*x6+e3))) > y <- y>runif(1000) > answer <- boolean(y ~( ((cons+x1+x2+x3)|((cons+x4+x5)&(cons+x6))) ), method="probit") > boolprof(answer, "x1") > boolprof(answer, "cons", instance=2) > > > > ### *