├── .Rbuildignore
├── .gitignore
├── DESCRIPTION
├── Makefile
├── NAMESPACE
├── NEWS.md
├── R
├── Effect.nestedLogit.R
├── GSS.R
├── HealthInsurance.R
├── as.data.frame.predict.R
├── broomMethods.R
├── models.R
├── nested.R
├── nestedHypotheses.R
├── nestedMethods.R
└── plot.nested-ci.R
├── README.Rmd
├── README.md
├── _pkgdown.yml
├── cran-comments.md
├── data
├── GSS.RData
└── HealthInsurance.RData
├── docs
├── 404.html
├── apple-touch-icon-120x120.png
├── apple-touch-icon-152x152.png
├── apple-touch-icon-180x180.png
├── apple-touch-icon-60x60.png
├── apple-touch-icon-76x76.png
├── apple-touch-icon.png
├── articles
│ ├── fig
│ │ ├── wlf-alt-plot-1.png
│ │ ├── wlf-effect-plot-1-1.png
│ │ ├── wlf-effect-plot-2-1.png
│ │ ├── wlf-geomtextpath-1.png
│ │ ├── wlf-gglogits-1.png
│ │ ├── wlf-ggplot-1.png
│ │ ├── wlf-ggplot-alt1-1.png
│ │ ├── wlf-ggplot-dichot1-1.png
│ │ ├── wlf-ggplot-dichot2-1.png
│ │ ├── wlf-ggplot-logit-1.png
│ │ ├── wlf-ggplot-p1-1.png
│ │ ├── wlf-ggplot-p2-1.png
│ │ ├── wlf-logits-1.png
│ │ ├── wlf-matplot-1.png
│ │ └── wlf-plot-1.png
│ ├── index.html
│ ├── nested-psychiatric.png
│ ├── nested.jpg
│ ├── nestedLogit.html
│ ├── nestedLogits.html
│ ├── partials
│ │ ├── methods-2.html
│ │ └── methods.html
│ ├── plotting-ggplot.html
│ ├── plotting.html
│ └── standard-errors.html
├── authors.html
├── deps
│ ├── JetBrains_Mono-0.4.7
│ │ ├── font.css
│ │ └── tDbY2o-flEEny0FZhsfKu5WU4zr3E_BX0PnT8RD8yKxjPg.woff
│ ├── Roboto-0.4.7
│ │ ├── KFOmCnqEu92Fr1Me5g.woff
│ │ └── font.css
│ ├── Roboto_Slab-0.4.7
│ │ ├── BngbUXZYTXPIvIBgJJSb6s3BzlRRfKOFbvjojISWaw.woff
│ │ └── font.css
│ ├── bootstrap-5.2.2
│ │ ├── bootstrap.bundle.min.js
│ │ ├── bootstrap.bundle.min.js.map
│ │ └── bootstrap.min.css
│ ├── data-deps.txt
│ └── jquery-3.6.0
│ │ ├── jquery-3.6.0.js
│ │ ├── jquery-3.6.0.min.js
│ │ └── jquery-3.6.0.min.map
├── favicon-16x16.png
├── favicon-32x32.png
├── favicon.ico
├── index.html
├── link.svg
├── logo.png
├── news
│ └── index.html
├── pkgdown.js
├── pkgdown.yml
├── reference
│ ├── Effect.nestedLogit-1.png
│ ├── Effect.nestedLogit-2.png
│ ├── Effect.nestedLogit-3.png
│ ├── Effect.nestedLogit-4.png
│ ├── Effect.nestedLogit.html
│ ├── GSS.html
│ ├── HealthInsurance.html
│ ├── Rplot001.png
│ ├── Rplot002.png
│ ├── Rplot003.png
│ ├── Rplot004.png
│ ├── as.data.frame.predictNestedLogit.html
│ ├── broomMethods.html
│ ├── figures
│ │ ├── README-wlf-plot-1.png
│ │ └── logo.png
│ ├── index.html
│ ├── models-1.png
│ ├── models.html
│ ├── nestedHypotheses.html
│ ├── nestedLogit-1.png
│ ├── nestedLogit.html
│ ├── nestedMethods.html
│ ├── plot.nestedLogit-1.png
│ ├── plot.nestedLogit-2.png
│ └── plot.nestedLogit.html
├── search.json
└── sitemap.xml
├── examples
├── 00Index
├── BlauDuncan-example.R
├── Effect.nestedLogit-examples.R
├── GSS-example.R
├── HealthInsurance-example.R
├── HealthInsurance-plot-se.R
├── HealthInsurance-plot.R
├── check_dichotomies.R
├── createDichotomies-test.R
├── gators.R
├── ggeffects-test.R
├── nested-methods-examples.R
├── parameters-test.R
├── predict-test.R
├── predict-with-se-example-2.R
├── predict-with-se-example.R
├── predict-with-se-logit.png
├── predict-with-se-plot.png
├── predict.nested-test.R
├── wlf-ggplot.R
├── wlf-nested-example.R
├── wlf-nested-plot.R
└── wlf-nested-test.R
├── experimental
├── augment.nested-test.R
├── augment.nested.R
├── models.R
├── pkgdown-reference.yml.txt
├── plot.nested--with-conf-limits.R
├── predict-with-se.R
├── response-variances.pdf
└── test-SEs.R
├── inst
└── WORDLIST
├── man
├── Effect.nestedLogit.Rd
├── GSS.Rd
├── HealthInsurance.Rd
├── as.data.frame.predictNestedLogit.Rd
├── broomMethods.Rd
├── figures
│ ├── README-wlf-plot-1.png
│ └── logo.png
├── models.Rd
├── nestedHypotheses.Rd
├── nestedLogit.Rd
├── nestedMethods.Rd
├── partials
│ └── methods.Rmd
└── plot.nestedLogit.Rd
├── old
├── nestedMethods.R
├── plot.nested.R
├── plotting.Rmd
└── predict-nested.R
├── pkgdown
└── favicon
│ ├── apple-touch-icon-120x120.png
│ ├── apple-touch-icon-152x152.png
│ ├── apple-touch-icon-180x180.png
│ ├── apple-touch-icon-60x60.png
│ ├── apple-touch-icon-76x76.png
│ ├── apple-touch-icon.png
│ ├── favicon-16x16.png
│ ├── favicon-32x32.png
│ └── favicon.ico
├── revdep
├── README.md
├── checks
│ └── libraries.csv
├── cran.md
├── data.sqlite
├── failures.md
├── library
│ └── nestedLogit
│ │ ├── new
│ │ └── nestedLogit
│ │ │ ├── DESCRIPTION
│ │ │ ├── INDEX
│ │ │ ├── Meta
│ │ │ ├── Rd.rds
│ │ │ ├── data.rds
│ │ │ ├── features.rds
│ │ │ ├── hsearch.rds
│ │ │ ├── links.rds
│ │ │ ├── nsInfo.rds
│ │ │ └── package.rds
│ │ │ ├── NAMESPACE
│ │ │ ├── NEWS.md
│ │ │ ├── R
│ │ │ ├── nestedLogit
│ │ │ ├── nestedLogit.rdb
│ │ │ └── nestedLogit.rdx
│ │ │ ├── WORDLIST
│ │ │ ├── data
│ │ │ ├── Rdata.rdb
│ │ │ ├── Rdata.rds
│ │ │ └── Rdata.rdx
│ │ │ ├── help
│ │ │ ├── AnIndex
│ │ │ ├── aliases.rds
│ │ │ ├── figures
│ │ │ │ └── logo.png
│ │ │ ├── nestedLogit.rdb
│ │ │ ├── nestedLogit.rdx
│ │ │ └── paths.rds
│ │ │ └── html
│ │ │ ├── 00Index.html
│ │ │ └── R.css
│ │ └── old
│ │ └── nestedLogit
│ │ ├── DESCRIPTION
│ │ ├── INDEX
│ │ ├── MD5
│ │ ├── Meta
│ │ ├── Rd.rds
│ │ ├── data.rds
│ │ ├── features.rds
│ │ ├── hsearch.rds
│ │ ├── links.rds
│ │ ├── nsInfo.rds
│ │ ├── package.rds
│ │ └── vignette.rds
│ │ ├── NAMESPACE
│ │ ├── NEWS.md
│ │ ├── R
│ │ ├── nestedLogit
│ │ ├── nestedLogit.rdb
│ │ └── nestedLogit.rdx
│ │ ├── WORDLIST
│ │ ├── data
│ │ ├── Rdata.rdb
│ │ ├── Rdata.rds
│ │ └── Rdata.rdx
│ │ ├── doc
│ │ ├── index.html
│ │ ├── nestedLogit.R
│ │ ├── nestedLogit.Rmd
│ │ ├── nestedLogit.html
│ │ ├── plotting-ggplot.R
│ │ ├── plotting-ggplot.Rmd
│ │ ├── plotting-ggplot.html
│ │ ├── standard-errors.Rmd
│ │ └── standard-errors.html
│ │ ├── help
│ │ ├── AnIndex
│ │ ├── aliases.rds
│ │ ├── figures
│ │ │ └── logo.png
│ │ ├── nestedLogit.rdb
│ │ ├── nestedLogit.rdx
│ │ └── paths.rds
│ │ └── html
│ │ ├── 00Index.html
│ │ └── R.css
└── problems.md
├── tests
├── spelling.R
├── testthat.R
└── testthat
│ ├── test-Effect-method.R
│ ├── test-fitted-probs.R
│ ├── test-model-update.R
│ └── test-probs-SEs.R
└── vignettes
├── .gitignore
├── apa.csl
├── apalike.csl
├── fig
├── nested-ex.pptx
├── nested-psychiatric.png
├── nested-wlf.png
├── nested.jpg
├── wlf-alt-plot-1.png
├── wlf-directlabels-1.png
├── wlf-effect-plot-1-1.png
├── wlf-effect-plot-2-1.png
├── wlf-geomtextpath-1.png
├── wlf-gglogits-1.png
├── wlf-ggplot-1.png
├── wlf-ggplot-alt1-1.png
├── wlf-ggplot-dichot1-1.png
├── wlf-ggplot-dichot2-1.png
├── wlf-ggplot-logit-1.png
├── wlf-ggplot-p1-1.png
├── wlf-ggplot-p2-1.png
├── wlf-logits-1.png
├── wlf-matplot-1.png
└── wlf-plot-1.png
├── nested-psychiatric.png
├── nested.jpg
├── nestedLogit.Rmd
├── packages.bib
├── plotting-ggplot.Rmd
├── references.bib
└── standard-errors.Rmd
/.Rbuildignore:
--------------------------------------------------------------------------------
1 | ^.*\.Rproj$
2 | ^\.Rproj\.user$
3 | examples/
4 | experimental/
5 | README.*
6 | ^cran-comments\.md$
7 | ^_pkgdown\.yml$
8 | ^docs$
9 | ^pkgdown$
10 | ^CRAN-SUBMISSION$
11 | Makefile
12 | old/
13 | revdep/
14 |
15 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .Rproj.user
2 | .Rhistory
3 | .RData
4 | .Ruserdata
5 | *.Rproj
6 |
--------------------------------------------------------------------------------
/DESCRIPTION:
--------------------------------------------------------------------------------
1 | Package: nestedLogit
2 | Title: Nested Dichotomy Logistic Regression Models
3 | Version: 0.3.3
4 | Date: 2024-06-03
5 | Authors@R: c(
6 | person("John", "Fox", , "jfox@mcmaster.ca", role = "aut",
7 | comment = c(ORCID = "0000-0002-1196-8012")),
8 | person("Michael", "Friendly", , "friendly@yorku.ca", role = c("aut", "cre"),
9 | comment = c(ORCID = "0000-0002-3237-0941")),
10 | person("Achim", "Zeileis", , "Achim.Zeileis@uibk.ac.at", role = "ctb",
11 | comment = c(ORCID = "0000-0003-0918-3766"))
12 | )
13 | Description: Provides functions for specifying and fitting nested
14 | dichotomy logistic regression models for a multi-category response and
15 | methods for summarising and plotting those models. Nested dichotomies are
16 | statistically independent, and hence provide an additive decomposition
17 | of tests for the overall 'polytomous' response. When the dichotomies
18 | make sense substantively, this method can be a simpler alternative to
19 | the standard 'multinomial' logistic model which compares response
20 | categories to a reference level. See: J. Fox (2016), "Applied
21 | Regression Analysis and Generalized Linear Models", 3rd Ed., ISBN
22 | 1452205663.
23 | License: GPL (>=2)
24 | URL: https://github.com/friendly/nestedLogit
25 | BugReports: https://github.com/friendly/nestedLogit/issues
26 | Depends:
27 | R (>= 3.5.0)
28 | Imports:
29 | broom,
30 | car,
31 | dplyr,
32 | effects,
33 | graphics,
34 | grDevices,
35 | stats,
36 | stringr,
37 | tibble
38 | Suggests:
39 | carData,
40 | geomtextpath,
41 | ggplot2,
42 | ggeffects,
43 | here,
44 | lobstr,
45 | knitr,
46 | nnet,
47 | rmarkdown,
48 | scales,
49 | spelling,
50 | testthat,
51 | tidyr
52 | VignetteBuilder:
53 | knitr,
54 | rmarkdown
55 | Encoding: UTF-8
56 | Language: en-US
57 | LazyData: TRUE
58 | Roxygen: list(markdown = TRUE)
59 | RoxygenNote: 7.3.1
60 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 |
2 | document:
3 | Rscript -e "devtools::document()"
4 |
5 | documentrich:
6 | Rscript -e "Sys.setenv('pkgdown' = 'true');devtools::document()"
7 |
8 | check: document
9 | Rscript -e "devtools::check()"
10 |
11 | install: document
12 | Rscript -e "devtools::install()"
13 |
14 | buildsite: document
15 | Rscript -e "pkgdown::build_site()"
16 |
17 | # deploysite: document
18 | # Rscript -e "pkgdown::deploy_to_branch()"
19 |
20 | buildpdf: document
21 | R CMD Rd2pdf .
22 |
--------------------------------------------------------------------------------
/NAMESPACE:
--------------------------------------------------------------------------------
1 | # Generated by roxygen2: do not edit by hand
2 |
3 | S3method(Anova,nestedLogit)
4 | S3method(anova,nestedLogit)
5 | S3method(as.character,dichotomies)
6 | S3method(as.data.frame,predictDichotomies)
7 | S3method(as.data.frame,predictNestedLogit)
8 | S3method(as.dichotomies,matrix)
9 | S3method(as.matrix,continuationDichotomies)
10 | S3method(as.matrix,dichotomies)
11 | S3method(broom::glance,nestedLogit)
12 | S3method(broom::tidy,nestedLogit)
13 | S3method(car::Anova,nestedLogit)
14 | S3method(car::linearHypothesis,nestedLogit)
15 | S3method(coef,nestedLogit)
16 | S3method(confint,predictNestedLogit)
17 | S3method(effects::Effect,nestedLogit)
18 | S3method(fitted,nestedLogit)
19 | S3method(linearHypothesis,nestedLogit)
20 | S3method(logLik,nestedLogit)
21 | S3method(models,nestedLogit)
22 | S3method(plot,nestedLogit)
23 | S3method(predict,nestedLogit)
24 | S3method(print,Anova.nestedLogit)
25 | S3method(print,anova.nestedLogit)
26 | S3method(print,dichotomies)
27 | S3method(print,nestedLogit)
28 | S3method(print,predictDichotomies)
29 | S3method(print,predictNestedLogit)
30 | S3method(print,summary.nestedLogit)
31 | S3method(stats::logLik,nestedLogit)
32 | S3method(summary,nestedLogit)
33 | S3method(update,nestedLogit)
34 | S3method(vcov,nestedLogit)
35 | export(as.dichotomies)
36 | export(continuationLogits)
37 | export(dichotomy)
38 | export(logits)
39 | export(models)
40 | export(nestedLogit)
41 | importFrom(broom,glance)
42 | importFrom(broom,tidy)
43 | importFrom(car,Anova)
44 | importFrom(car,linearHypothesis)
45 | importFrom(dplyr,bind_cols)
46 | importFrom(dplyr,select)
47 | importFrom(effects,Effect)
48 | importFrom(grDevices,adjustcolor)
49 | importFrom(grDevices,palette)
50 | importFrom(graphics,arrows)
51 | importFrom(graphics,axis)
52 | importFrom(graphics,box)
53 | importFrom(graphics,matplot)
54 | importFrom(graphics,polygon)
55 | importFrom(graphics,title)
56 | importFrom(stats,anova)
57 | importFrom(stats,binomial)
58 | importFrom(stats,coef)
59 | importFrom(stats,confint)
60 | importFrom(stats,fitted)
61 | importFrom(stats,formula)
62 | importFrom(stats,glm)
63 | importFrom(stats,model.frame)
64 | importFrom(stats,model.matrix)
65 | importFrom(stats,model.response)
66 | importFrom(stats,na.omit)
67 | importFrom(stats,pchisq)
68 | importFrom(stats,predict)
69 | importFrom(stats,qnorm)
70 | importFrom(stats,update)
71 | importFrom(stringr,str_remove)
72 | importFrom(tibble,rownames_to_column)
73 |
--------------------------------------------------------------------------------
/NEWS.md:
--------------------------------------------------------------------------------
1 | # nestedLogit 0.3.3
2 |
3 | * Fixed documentation error in GSS.R
4 | * `createDichotomies` methods now explicitly internal
5 |
6 | # nestedLogit 0.3.2
7 |
8 | * new `Effect` method for `"nestedLogit"` objects to create effect displays.
9 | * add Effect example to vignette
10 |
11 |
12 | # nestedLogit 0.3.1
13 |
14 | * correct buglet in `as.data.frame` method when `newdata` has one column
15 | * `predict.nestedLogit()` now includes the `newdata` data frame as an additional component (`.data`) in its result. Consequently, the `newdata` argument is no longer required in the `as.data.frame` method.
16 |
17 | # nestedLogit 0.3.0
18 |
19 | This is a major enhancement to the package, adding computations of standard errors and confidence intervals to predicted probabilities and logits.
20 |
21 | ## Enhancements
22 | * The `predict()` method now computes standard errors for probabilities and logits using the delta method. These can be obtained for either the response probabilities (and equivalent logits) or for the predicted log odds of the individual dichotomies.
23 | * A `confint()` method for the result of `predict()` generates the corresponding confidence intervals.
24 | * `as.data.frame()` methods for predicted values, either for the nested logit model or for the separate dichotomies converts these to a data frame in long format, handy for using `ggplot()`.
25 | * Added a `confint()` method for predicted probabilities and logits
26 | * The `plot()` method for `"nestedLogit"` objects now plots confidence intervals for predicted probabilities.
27 | * A new vignette, "standard-errors", describes the mathematics behind the standard error calculations.
28 | * An old vignette on plotting methods was completely re-written using the new `predict()` methods and focusing exclusively on `ggplot2().
29 |
30 | ## Other
31 | * Added an example of `lobstr::tree()` to print nested lists
32 | * Now use `fig.show="hold"` to keep `par(op)` with the code.
33 |
34 | # nestedLogit 0.2.1
35 |
36 | * Reset all `par()` and `options()` calls so as to not alter user's workspace.
37 | * now document all return values.
38 | * added a reference to DESCRIPTION. It is a book, so no doi:, url, etc.
39 | * fixed one URL that win-builder (spuriously) complains about.
40 |
41 |
42 | # nestedLogit 0.2.0
43 |
44 | * Now allow dichotomies to be specified by a nested (recursive) of binary splits of the categories [suggestion of Achim Zeileis]
45 | * The model object is now of class "nestedLogit" for uniformity.
46 | * A basic `plot()` method now operational
47 | * Added a `linearHypothesis()` method to give Wald tests for hypotheses about coefficients or their linear combinations.
48 | * Expanded vignette to illustrate some other methods.
49 | * Added a `models()` generic and method to extract separate models from the `"nestedLogit"` object
50 | * Added a `logLike()` method, and through it, gets `AIC()` and `BIC()`
51 | * Reorganized documentation to separate nested hypothesis methods.
52 |
53 | # nestedLogit 0.1.0
54 |
55 | * Initial version
56 | * Added a `NEWS.md` file to track changes to the package.
57 |
58 |
--------------------------------------------------------------------------------
/R/GSS.R:
--------------------------------------------------------------------------------
1 | #' @name GSS
2 | #' @docType data
3 | #'
4 | #' @title Data From the U.S. General Social Survey 1972-2016
5 | #'
6 | #' @description This data set is drawn from the U.S. General Social Survey (GSS) for years
7 | #' between 1972 and 2016.
8 | #'
9 | #' @usage data("GSS", package = "nestedLogit")
10 | #'
11 | #' @format A data frame with 44091 rows and 3 columns.
12 | #' \describe{
13 | #' \item{parentdeg}{A factor representing parents' attained level of education
14 | #' (highest "degree" obtained), recording
15 | #' the higher of mother's and father's education, with levels \code{"l.t.highschool"},
16 | #' \code{"highschool"}, \code{"college"}, and \code{"graduate"}.}
17 | #' \item{degree}{The respondent's level of education, a factor with the same levels
18 | #' as \code{parentdeg}.}
19 | #' \item{year}{The year of the survey, between \code{1972} and
20 | #' \code{2016}.}
21 | #' }
22 | #'
23 | #' @source General Social Survey, NORC, The University of Chicago
24 | #' https://www.norc.org/Research/Projects/Pages/general-social-survey.aspx.
25 | #'
26 | #' @seealso \code{\link{nestedLogit}}.
27 | #'
28 | #' @examples
29 | #' round(100*with(GSS, prop.table(table(degree, parentdeg), 2)))
30 | #' m.GSS <- nestedLogit(degree ~ parentdeg*year,
31 | #' continuationLogits(c("l.t.highschool", "highschool",
32 | #' "college", "graduate")),
33 | #' data=GSS)
34 | #' car::Anova(m.GSS)
35 | #' summary(m.GSS)
36 | "GSS"
37 |
--------------------------------------------------------------------------------
/R/HealthInsurance.R:
--------------------------------------------------------------------------------
1 | #' @name HealthInsurance
2 | #' @docType data
3 | #'
4 | #' @title Choice of Health Insurance Product
5 | #'
6 | #' @description A company recently introduced a new health insurance provider for
7 | #' its employees. At the beginning of the year the employees had to choose one of
8 | #' three (or four) different health plan products from this provider to best suit
9 | #' their needs.
10 | #'
11 | #' This dataset was modified from its original source (McNulty, 2022) for the
12 | #' present purposes by adding a fourth choice, sampled randomly from the original three.
13 | #'
14 | #' @usage data("HealthInsurance", package = "nestedLogit")
15 | #'
16 | #' @format A data frame with 1448 rows and 7 columns.
17 | #' \describe{
18 | #' \item{product}{Choice among three products, a factor with levels \code{"A"}, \code{"B"},
19 | #' and \code{"C"}.}
20 | #' \item{product4}{Choice among four products, a factor with levels \code{"A"}, \code{"B"},
21 | #' \code{"C"}, and \code{"D"}.}
22 | #' \item{age}{The age of the individual, in years.}
23 | #' \item{household}{The number of people living with the individual in the
24 | #' same household.}
25 | #' \item{position_level}{Position level in the company at the time the choice was made,
26 | #' where 1 is is the lowest level and 5 is the highest, a numeric vector.}
27 | #' \item{gender}{The gender of the individual, a factor with levels \code{"Female"}
28 | #' and \code{"Male"}.}
29 | #' \item{absent}{The number of days the individual was absent from work in the year
30 | #' prior to the choice,}
31 | #' }
32 | #'
33 | #' @source Originally taken from McNulty, K. (2022).
34 | #' \emph{Handbook of Regression Modeling in People Analytics},
35 | #' \url{https://peopleanalytics-regression-book.org/data/health_insurance.csv}.
36 | #'
37 | #' @seealso \code{\link{nestedLogit}}.
38 | #'
39 | #' @examples
40 | #' lbinary <- logits(AB_CD = dichotomy(c("A", "B"), c("C", "D")),
41 | #' A_B = dichotomy("A", "B"),
42 | #' C_D = dichotomy("C", "D"))
43 | #' as.matrix(lbinary)
44 | #' health.nested <- nestedLogit(product4 ~ age + gender * household + position_level,
45 | #' dichotomies = lbinary, data = HealthInsurance)
46 | #' car::Anova(health.nested)
47 | #' coef(health.nested)
48 | "HealthInsurance"
49 |
--------------------------------------------------------------------------------
/R/as.data.frame.predict.R:
--------------------------------------------------------------------------------
1 |
2 | #' Convert a Predicted Objects to a data.frame
3 | #'
4 | #' These functions provide simple ways to convert the results of \code{\link{predict.nestedLogit}}
5 | #' to a data frame in a consistent format for plotting and other actions.
6 | #'
7 | #' @param x a \code{"predictNestedLogit"} object
8 | #' @param row.names row.names for result (for conformity with generic; not currently used)
9 | #' @param optional logical. If TRUE, setting row names and converting column names
10 | #' (to syntactic names: see \code{\link[base]{make.names}} is optional
11 | #' @param ... other arguments (unused)
12 | #'
13 | #' @return \itemize{
14 | #' \item For \code{predict(\dots, model="nested")} (the default), returns
15 | #' a data frame containing the values of predictors along with the columns
16 | #' \code{response}, \code{p}, \code{se.p}, \code{logit}, \code{se.logit}.
17 | #' \item For \code{predict(\dots, model="dichotomies")}, returns
18 | #' a data frame containing the values of predictors along with the columns
19 | #' \code{response}, \code{logit}, and \code{se.logit}.
20 | #' }
21 | #' @export
22 | #'
23 | #' @examples
24 | #' data("Womenlf", package = "carData")
25 | #' comparisons <- logits(work=dichotomy("not.work", c("parttime", "fulltime")),
26 | #' full=dichotomy("parttime", "fulltime"))
27 | #'
28 | #' wlf.nested <- nestedLogit(partic ~ hincome + children,
29 | #' dichotomies = comparisons,
30 | #' data=Womenlf)
31 | #' # get predicted values for a grid of `hincome` and `children`
32 | #' new <- expand.grid(hincome=seq(0, 45, length=10),
33 | #' children=c("absent", "present"))
34 | #'
35 | #' pred.nested <- predict(wlf.nested, new)
36 | #' plotdata <- as.data.frame(pred.nested)
37 | #' str(plotdata)
38 | #'
39 | #' # Predicted logit values for the dichotomies
40 | #' pred.dichot <- predict(wlf.nested, new, model = "dichotomies")
41 | #' plotlogit <- as.data.frame(pred.dichot)
42 | #' str(plotlogit)
43 |
44 | as.data.frame.predictNestedLogit <- function(x,
45 | row.names = NULL,
46 | optional = FALSE,
47 | ...){
48 | resp.names <- colnames(x$p)
49 |
50 | result <- data.frame(
51 | response = rep(resp.names, nrow(x$p)),
52 | p = as.vector(t(x$p)),
53 | se.p = as.vector(t(x$se.p)),
54 | logit = as.vector(t(x$logit)),
55 | se.logit = as.vector(t(x$se.logit))
56 | )
57 | .data <- x$.data
58 | if (!is.null(.data)) {
59 | idx <- rep(seq_len(nrow(.data)), each = length(resp.names))
60 | result <- cbind(.data[idx, , drop = FALSE], result)
61 | }
62 |
63 | rownames(result) <- NULL
64 | result
65 | }
66 |
67 | #' @importFrom dplyr select bind_cols
68 | #' @importFrom tibble rownames_to_column
69 | #' @importFrom stringr str_remove
70 | #' @export
71 |
72 | as.data.frame.predictDichotomies <- function(x,
73 | row.names = NULL,
74 | optional = FALSE,
75 | ...){
76 | # quiet no visible binding
77 | response <- fit <- se.fit <- residual.scale <- NULL
78 | dichotomies <- attr(x, "dichotomies")
79 | .data <- x$.data
80 |
81 | result <- do.call(rbind, x[dichotomies]) |>
82 | dplyr::select(- residual.scale) |>
83 | tibble::rownames_to_column(var = "response") |>
84 | dplyr::mutate(response = stringr::str_remove(response, ".\\d+")) |>
85 | dplyr::rename(logit = fit,
86 | se.logit = se.fit)
87 |
88 | if(!is.null(.data)) {
89 | nlogits <- length(x[dichotomies])
90 | idx <- rep(seq_len(nrow(.data)), nlogits)
91 | result <- dplyr::bind_cols(.data[idx,], result)
92 | }
93 | result
94 | }
95 |
96 |
97 | # Example of steps
98 | # plotlogit <- do.call(rbind, pred.dichot) |>
99 | # select(- residual.scale) |>
100 | # tibble::rownames_to_column(var = "response") |>
101 | # mutate(response = stringr::str_remove(response, ".\\d+")) |>
102 | # rename(logit = fit,
103 | # se.logit = se.fit)
104 | # idx <- rep(seq_len(nrow(new)), length(pred.dichot))
105 | # plotlogit <- bind_cols(new[idx,], plotlogit)
106 |
--------------------------------------------------------------------------------
/R/broomMethods.R:
--------------------------------------------------------------------------------
1 | #' Broom Related Methods
2 | #'
3 | #' These functions give compact summaries of a \code{"nestedLogit"} object
4 | #' \describe{
5 | #' \item{\code{glance}}{Construct a single row summaries for the dichotomies \code{"nestedLogit"} model.}
6 | #' \item{\code{tidy}}{Summarizes the terms in \code{"nestedLogit"} model.}
7 | #' }
8 | #'
9 | #' @name broomMethods
10 | #' @aliases glance.nestedLogit tidy.nestedLogit
11 | #' @param x an object of class \code{"nestedLogit"}.
12 | #' @param \dots arguments to be passed down.
13 | #' @importFrom broom glance
14 | #' @rdname broomMethods
15 | #' @seealso \code{\link{nestedMethods}}, \code{\link[broom]{glance}}, \code{\link[broom]{tidy}}
16 | #' @exportS3Method broom::glance nestedLogit
17 | #' @return \itemize{
18 | #' \item \code{glance} returns a \code{tibble} containing one row of fit statistics for each dichotomy,
19 | #' labeled \code{response}. See \code{\link[broom]{glance}} for details.
20 | #' \item \code{tidy} returns a \code{tibble} containing coefficient estimates and test statistics for
21 | #' the combinations of \code{response} and \code{term}. See \code{\link[broom]{tidy}} for details.
22 | #' }
23 | #' @examples
24 | #' data("Womenlf", package = "carData")
25 | #' m <- nestedLogit(partic ~ hincome + children,
26 | #' dichotomies = logits(work=dichotomy("not.work",
27 | #' working=c("parttime", "fulltime")),
28 | #' full=dichotomy("parttime", "fulltime")),
29 | #' data=Womenlf)
30 | #'
31 | #' # one-line summaries
32 | #' broom::glance(m)
33 | #' # coefficients and tests
34 | #' broom::tidy(m)
35 | #'
36 | glance.nestedLogit <- function(x, ...){
37 | result <- dplyr::bind_rows(lapply(models(x), broom::glance))
38 | result <- dplyr::bind_cols(response = names(models(x)), result)
39 | result
40 | }
41 |
42 | #' @importFrom broom tidy
43 | #' @rdname broomMethods
44 | #' @exportS3Method broom::tidy nestedLogit
45 | tidy.nestedLogit <- function(x, ...){
46 | result <- dplyr::bind_rows(lapply(models(x), broom::tidy, ...))
47 | response <- rep(names(models(x)), each = nrow(result)/length(models(x)))
48 | result <- dplyr::bind_cols(response = response, result)
49 | result
50 | }
51 |
--------------------------------------------------------------------------------
/R/models.R:
--------------------------------------------------------------------------------
1 | #' Extract Binary Logit Models from a \code{nestedLogit} Object
2 | #'
3 | #' @name models
4 | #' @aliases models models.nestedLogit
5 | #'
6 | #' @description
7 | #' \code{models} is used to extract \code{"glm"} objects representing binary logit
8 | #' models from a \code{"nestedLogit"} object.
9 | #'
10 | #' @param model a \code{"nestedLogit"} model.
11 | #' @param select a numeric or character vector giving the number(s) or names(s)
12 | #' of one or more
13 | #' binary logit models to be extracted from \code{model}; if absent, a list of
14 | #' all of the binary logits models in \code{model} is returned.
15 | #' @param as.list if \code{TRUE} (the default is \code{FALSE}) and one binary logit
16 | #' model is selected, return the \code{"glm"} object in a one-element named list;
17 | #' otherwise a single model is returned directly as a \code{"glm"} object;
18 | #' when more than one binary
19 | #' logit model is selected, the corresponding \code{"glm"} objects are \emph{always}
20 | #' returned as a named list.
21 | #'
22 | #' @return \code{model} returns either a single \code{"glm"} object (see \code{\link{glm}}) or a
23 | #' list of \code{"glm"} objects, each representing a binary logit model.
24 | #'
25 | #' @examples
26 | #' data("Womenlf", package = "carData")
27 | #' comparisons <- logits(work=dichotomy("not.work",
28 | #' working=c("parttime", "fulltime")),
29 | #' full=dichotomy("parttime", "fulltime"))
30 | #' m <- nestedLogit(partic ~ hincome + children,
31 | #' dichotomies = comparisons,
32 | #' data=Womenlf)
33 | #'
34 | #' # extract a binomial logit model
35 | #' models(m, "work")
36 | #' # use that to plot residuals
37 | #' plot(density(residuals(models(m, "work"))))
38 | #' @export
39 | #'
40 | models <- function(model, select, as.list=FALSE){
41 | UseMethod("models")
42 | }
43 |
44 | #' @rdname models
45 | #' @export
46 | models.nestedLogit <- function(model, select, as.list=FALSE){
47 | if (missing(select)) return(model$models)
48 | if (is.numeric(select)){
49 | model.nos <- seq(along=model$models)
50 | which <- !(select %in% model.nos)
51 | } else {
52 | model.names <- names(model$models)
53 | which <- !(select %in% model.names)
54 | }
55 | if (any(which)){
56 | stop("the following model", if (sum(which) > 1) "s are " else " is ",
57 | "not available:\n", paste(select[which], collapse=", "))
58 | }
59 | result <- model$models[select]
60 | if (length(result) > 1 || as.list) return(result) else return(result[[1]])
61 | }
62 |
--------------------------------------------------------------------------------
/_pkgdown.yml:
--------------------------------------------------------------------------------
1 | url: https://friendly.github.io/nestedLogit
2 |
3 | template:
4 | bootstrap: 5
5 | bslib:
6 | base_font: {google: "Roboto"}
7 | heading_font: {google: "Roboto Slab"}
8 | code_font: {google: "JetBrains Mono"}
9 |
10 |
--------------------------------------------------------------------------------
/cran-comments.md:
--------------------------------------------------------------------------------
1 | ## Test environments
2 | * local Windows 10, R version 4.2.3 (2023-03-15 ucrt)
3 | * local MacOS Ventura 13.3.1, R version 4.3.0 (2023-04-21)
4 | * win-builder R Under development (unstable) (2023-06-20 r84585 ucrt)
5 | * Rhub: Ubuntu Linux 20.04.1 LTS, R-release, GCC
6 | * Rhub: Windows Server 2022, R-devel, 64 bit
7 |
8 | ## R CMD check results
9 |
10 | 0 errors | 0 warnings | 0 notes
11 |
12 | ## Reverse dependencies
13 |
14 | > devtools::revdep()
15 | [1] "ggeffects" "insight" "parameters"
16 |
17 | ## revdepcheck results
18 |
19 | We checked 3 reverse dependencies (0 from CRAN + 3 from Bioconductor), comparing R CMD check results across CRAN and dev versions of this package.
20 |
21 | * We saw 0 new problems
22 | * We failed to check 0 packages
23 |
24 |
25 | ## nestedLogit 0.3.2
26 |
27 | This is a modest enhancement to the package, adding effect displays and smoothing some infelicities in the previously released version.
28 |
29 | * new `Effect` method for `"nestedLogit"` objects to create effect displays.
30 | * add Effect example to vignette
31 |
32 | # nestedLogit 0.3.1
33 |
34 | * correct buglet in `as.data.frame` method when `newdata` has one column
35 | * `predict.nestedLogit()` now includes the `newdata` data frame as an additional component (`.data`) in its result. Consequently, the `newdata` argument is no longer required in the `as.data.frame` method.
36 |
37 |
--------------------------------------------------------------------------------
/data/GSS.RData:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/data/GSS.RData
--------------------------------------------------------------------------------
/data/HealthInsurance.RData:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/data/HealthInsurance.RData
--------------------------------------------------------------------------------
/docs/apple-touch-icon-120x120.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/docs/apple-touch-icon-120x120.png
--------------------------------------------------------------------------------
/docs/apple-touch-icon-152x152.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/docs/apple-touch-icon-152x152.png
--------------------------------------------------------------------------------
/docs/apple-touch-icon-180x180.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/docs/apple-touch-icon-180x180.png
--------------------------------------------------------------------------------
/docs/apple-touch-icon-60x60.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/docs/apple-touch-icon-60x60.png
--------------------------------------------------------------------------------
/docs/apple-touch-icon-76x76.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/docs/apple-touch-icon-76x76.png
--------------------------------------------------------------------------------
/docs/apple-touch-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/docs/apple-touch-icon.png
--------------------------------------------------------------------------------
/docs/articles/fig/wlf-alt-plot-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/docs/articles/fig/wlf-alt-plot-1.png
--------------------------------------------------------------------------------
/docs/articles/fig/wlf-effect-plot-1-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/docs/articles/fig/wlf-effect-plot-1-1.png
--------------------------------------------------------------------------------
/docs/articles/fig/wlf-effect-plot-2-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/docs/articles/fig/wlf-effect-plot-2-1.png
--------------------------------------------------------------------------------
/docs/articles/fig/wlf-geomtextpath-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/docs/articles/fig/wlf-geomtextpath-1.png
--------------------------------------------------------------------------------
/docs/articles/fig/wlf-gglogits-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/docs/articles/fig/wlf-gglogits-1.png
--------------------------------------------------------------------------------
/docs/articles/fig/wlf-ggplot-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/docs/articles/fig/wlf-ggplot-1.png
--------------------------------------------------------------------------------
/docs/articles/fig/wlf-ggplot-alt1-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/docs/articles/fig/wlf-ggplot-alt1-1.png
--------------------------------------------------------------------------------
/docs/articles/fig/wlf-ggplot-dichot1-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/docs/articles/fig/wlf-ggplot-dichot1-1.png
--------------------------------------------------------------------------------
/docs/articles/fig/wlf-ggplot-dichot2-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/docs/articles/fig/wlf-ggplot-dichot2-1.png
--------------------------------------------------------------------------------
/docs/articles/fig/wlf-ggplot-logit-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/docs/articles/fig/wlf-ggplot-logit-1.png
--------------------------------------------------------------------------------
/docs/articles/fig/wlf-ggplot-p1-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/docs/articles/fig/wlf-ggplot-p1-1.png
--------------------------------------------------------------------------------
/docs/articles/fig/wlf-ggplot-p2-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/docs/articles/fig/wlf-ggplot-p2-1.png
--------------------------------------------------------------------------------
/docs/articles/fig/wlf-logits-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/docs/articles/fig/wlf-logits-1.png
--------------------------------------------------------------------------------
/docs/articles/fig/wlf-matplot-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/docs/articles/fig/wlf-matplot-1.png
--------------------------------------------------------------------------------
/docs/articles/fig/wlf-plot-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/docs/articles/fig/wlf-plot-1.png
--------------------------------------------------------------------------------
/docs/articles/nested-psychiatric.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/docs/articles/nested-psychiatric.png
--------------------------------------------------------------------------------
/docs/articles/nested.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/docs/articles/nested.jpg
--------------------------------------------------------------------------------
/docs/deps/JetBrains_Mono-0.4.7/font.css:
--------------------------------------------------------------------------------
1 | @font-face {
2 | font-family: 'JetBrains Mono';
3 | font-style: normal;
4 | font-weight: 400;
5 | font-display: swap;
6 | src: url(tDbY2o-flEEny0FZhsfKu5WU4zr3E_BX0PnT8RD8yKxjPg.woff) format('woff');
7 | }
8 |
--------------------------------------------------------------------------------
/docs/deps/JetBrains_Mono-0.4.7/tDbY2o-flEEny0FZhsfKu5WU4zr3E_BX0PnT8RD8yKxjPg.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/docs/deps/JetBrains_Mono-0.4.7/tDbY2o-flEEny0FZhsfKu5WU4zr3E_BX0PnT8RD8yKxjPg.woff
--------------------------------------------------------------------------------
/docs/deps/Roboto-0.4.7/KFOmCnqEu92Fr1Me5g.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/docs/deps/Roboto-0.4.7/KFOmCnqEu92Fr1Me5g.woff
--------------------------------------------------------------------------------
/docs/deps/Roboto-0.4.7/font.css:
--------------------------------------------------------------------------------
1 | @font-face {
2 | font-family: 'Roboto';
3 | font-style: normal;
4 | font-weight: 400;
5 | font-display: swap;
6 | src: url(KFOmCnqEu92Fr1Me5g.woff) format('woff');
7 | }
8 |
--------------------------------------------------------------------------------
/docs/deps/Roboto_Slab-0.4.7/BngbUXZYTXPIvIBgJJSb6s3BzlRRfKOFbvjojISWaw.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/docs/deps/Roboto_Slab-0.4.7/BngbUXZYTXPIvIBgJJSb6s3BzlRRfKOFbvjojISWaw.woff
--------------------------------------------------------------------------------
/docs/deps/Roboto_Slab-0.4.7/font.css:
--------------------------------------------------------------------------------
1 | @font-face {
2 | font-family: 'Roboto Slab';
3 | font-style: normal;
4 | font-weight: 400;
5 | font-display: swap;
6 | src: url(BngbUXZYTXPIvIBgJJSb6s3BzlRRfKOFbvjojISWaw.woff) format('woff');
7 | }
8 |
--------------------------------------------------------------------------------
/docs/deps/data-deps.txt:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/docs/favicon-16x16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/docs/favicon-16x16.png
--------------------------------------------------------------------------------
/docs/favicon-32x32.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/docs/favicon-32x32.png
--------------------------------------------------------------------------------
/docs/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/docs/favicon.ico
--------------------------------------------------------------------------------
/docs/link.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
13 |
--------------------------------------------------------------------------------
/docs/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/docs/logo.png
--------------------------------------------------------------------------------
/docs/pkgdown.js:
--------------------------------------------------------------------------------
1 | /* http://gregfranko.com/blog/jquery-best-practices/ */
2 | (function($) {
3 | $(function() {
4 |
5 | $('nav.navbar').headroom();
6 |
7 | Toc.init({
8 | $nav: $("#toc"),
9 | $scope: $("main h2, main h3, main h4, main h5, main h6")
10 | });
11 |
12 | if ($('#toc').length) {
13 | $('body').scrollspy({
14 | target: '#toc',
15 | offset: $("nav.navbar").outerHeight() + 1
16 | });
17 | }
18 |
19 | // Activate popovers
20 | $('[data-bs-toggle="popover"]').popover({
21 | container: 'body',
22 | html: true,
23 | trigger: 'focus',
24 | placement: "top",
25 | sanitize: false,
26 | });
27 |
28 | $('[data-bs-toggle="tooltip"]').tooltip();
29 |
30 | /* Clipboard --------------------------*/
31 |
32 | function changeTooltipMessage(element, msg) {
33 | var tooltipOriginalTitle=element.getAttribute('data-original-title');
34 | element.setAttribute('data-original-title', msg);
35 | $(element).tooltip('show');
36 | element.setAttribute('data-original-title', tooltipOriginalTitle);
37 | }
38 |
39 | if(ClipboardJS.isSupported()) {
40 | $(document).ready(function() {
41 | var copyButton = "";
42 |
43 | $("div.sourceCode").addClass("hasCopyButton");
44 |
45 | // Insert copy buttons:
46 | $(copyButton).prependTo(".hasCopyButton");
47 |
48 | // Initialize tooltips:
49 | $('.btn-copy-ex').tooltip({container: 'body'});
50 |
51 | // Initialize clipboard:
52 | var clipboard = new ClipboardJS('[data-clipboard-copy]', {
53 | text: function(trigger) {
54 | return trigger.parentNode.textContent.replace(/\n#>[^\n]*/g, "");
55 | }
56 | });
57 |
58 | clipboard.on('success', function(e) {
59 | changeTooltipMessage(e.trigger, 'Copied!');
60 | e.clearSelection();
61 | });
62 |
63 | clipboard.on('error', function() {
64 | changeTooltipMessage(e.trigger,'Press Ctrl+C or Command+C to copy');
65 | });
66 |
67 | });
68 | }
69 |
70 | /* Search marking --------------------------*/
71 | var url = new URL(window.location.href);
72 | var toMark = url.searchParams.get("q");
73 | var mark = new Mark("main#main");
74 | if (toMark) {
75 | mark.mark(toMark, {
76 | accuracy: {
77 | value: "complementary",
78 | limiters: [",", ".", ":", "/"],
79 | }
80 | });
81 | }
82 |
83 | /* Search --------------------------*/
84 | /* Adapted from https://github.com/rstudio/bookdown/blob/2d692ba4b61f1e466c92e78fd712b0ab08c11d31/inst/resources/bs4_book/bs4_book.js#L25 */
85 | // Initialise search index on focus
86 | var fuse;
87 | $("#search-input").focus(async function(e) {
88 | if (fuse) {
89 | return;
90 | }
91 |
92 | $(e.target).addClass("loading");
93 | var response = await fetch($("#search-input").data("search-index"));
94 | var data = await response.json();
95 |
96 | var options = {
97 | keys: ["what", "text", "code"],
98 | ignoreLocation: true,
99 | threshold: 0.1,
100 | includeMatches: true,
101 | includeScore: true,
102 | };
103 | fuse = new Fuse(data, options);
104 |
105 | $(e.target).removeClass("loading");
106 | });
107 |
108 | // Use algolia autocomplete
109 | var options = {
110 | autoselect: true,
111 | debug: true,
112 | hint: false,
113 | minLength: 2,
114 | };
115 | var q;
116 | async function searchFuse(query, callback) {
117 | await fuse;
118 |
119 | var items;
120 | if (!fuse) {
121 | items = [];
122 | } else {
123 | q = query;
124 | var results = fuse.search(query, { limit: 20 });
125 | items = results
126 | .filter((x) => x.score <= 0.75)
127 | .map((x) => x.item);
128 | if (items.length === 0) {
129 | items = [{dir:"Sorry 😿",previous_headings:"",title:"No results found.",what:"No results found.",path:window.location.href}];
130 | }
131 | }
132 | callback(items);
133 | }
134 | $("#search-input").autocomplete(options, [
135 | {
136 | name: "content",
137 | source: searchFuse,
138 | templates: {
139 | suggestion: (s) => {
140 | if (s.title == s.what) {
141 | return `${s.dir} >
${s.title}
`;
142 | } else if (s.previous_headings == "") {
143 | return `${s.dir} > ${s.title}
> ${s.what}`;
144 | } else {
145 | return `${s.dir} > ${s.title}
> ${s.previous_headings} > ${s.what}`;
146 | }
147 | },
148 | },
149 | },
150 | ]).on('autocomplete:selected', function(event, s) {
151 | window.location.href = s.path + "?q=" + q + "#" + s.id;
152 | });
153 | });
154 | })(window.jQuery || window.$)
155 |
156 |
157 |
--------------------------------------------------------------------------------
/docs/pkgdown.yml:
--------------------------------------------------------------------------------
1 | pandoc: 3.1.2
2 | pkgdown: 2.0.7
3 | pkgdown_sha: ~
4 | articles:
5 | nestedLogit: nestedLogit.html
6 | plotting-ggplot: plotting-ggplot.html
7 | standard-errors: standard-errors.html
8 | last_built: 2023-08-05T21:08Z
9 | urls:
10 | reference: https://friendly.github.io/nestedLogit/reference
11 | article: https://friendly.github.io/nestedLogit/articles
12 |
13 |
--------------------------------------------------------------------------------
/docs/reference/Effect.nestedLogit-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/docs/reference/Effect.nestedLogit-1.png
--------------------------------------------------------------------------------
/docs/reference/Effect.nestedLogit-2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/docs/reference/Effect.nestedLogit-2.png
--------------------------------------------------------------------------------
/docs/reference/Effect.nestedLogit-3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/docs/reference/Effect.nestedLogit-3.png
--------------------------------------------------------------------------------
/docs/reference/Effect.nestedLogit-4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/docs/reference/Effect.nestedLogit-4.png
--------------------------------------------------------------------------------
/docs/reference/Rplot001.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/docs/reference/Rplot001.png
--------------------------------------------------------------------------------
/docs/reference/Rplot002.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/docs/reference/Rplot002.png
--------------------------------------------------------------------------------
/docs/reference/Rplot003.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/docs/reference/Rplot003.png
--------------------------------------------------------------------------------
/docs/reference/Rplot004.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/docs/reference/Rplot004.png
--------------------------------------------------------------------------------
/docs/reference/figures/README-wlf-plot-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/docs/reference/figures/README-wlf-plot-1.png
--------------------------------------------------------------------------------
/docs/reference/figures/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/docs/reference/figures/logo.png
--------------------------------------------------------------------------------
/docs/reference/models-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/docs/reference/models-1.png
--------------------------------------------------------------------------------
/docs/reference/nestedLogit-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/docs/reference/nestedLogit-1.png
--------------------------------------------------------------------------------
/docs/reference/plot.nestedLogit-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/docs/reference/plot.nestedLogit-1.png
--------------------------------------------------------------------------------
/docs/reference/plot.nestedLogit-2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/docs/reference/plot.nestedLogit-2.png
--------------------------------------------------------------------------------
/docs/sitemap.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | https://friendly.github.io/nestedLogit/404.html
5 |
6 |
7 | https://friendly.github.io/nestedLogit/articles/index.html
8 |
9 |
10 | https://friendly.github.io/nestedLogit/articles/nestedLogit.html
11 |
12 |
13 | https://friendly.github.io/nestedLogit/articles/nestedLogits.html
14 |
15 |
16 | https://friendly.github.io/nestedLogit/articles/partials/methods-2.html
17 |
18 |
19 | https://friendly.github.io/nestedLogit/articles/partials/methods.html
20 |
21 |
22 | https://friendly.github.io/nestedLogit/articles/plotting-ggplot.html
23 |
24 |
25 | https://friendly.github.io/nestedLogit/articles/plotting.html
26 |
27 |
28 | https://friendly.github.io/nestedLogit/articles/standard-errors.html
29 |
30 |
31 | https://friendly.github.io/nestedLogit/authors.html
32 |
33 |
34 | https://friendly.github.io/nestedLogit/index.html
35 |
36 |
37 | https://friendly.github.io/nestedLogit/news/index.html
38 |
39 |
40 | https://friendly.github.io/nestedLogit/reference/as.data.frame.predictNestedLogit.html
41 |
42 |
43 | https://friendly.github.io/nestedLogit/reference/broomMethods.html
44 |
45 |
46 | https://friendly.github.io/nestedLogit/reference/Effect.nestedLogit.html
47 |
48 |
49 | https://friendly.github.io/nestedLogit/reference/GSS.html
50 |
51 |
52 | https://friendly.github.io/nestedLogit/reference/HealthInsurance.html
53 |
54 |
55 | https://friendly.github.io/nestedLogit/reference/index.html
56 |
57 |
58 | https://friendly.github.io/nestedLogit/reference/models.html
59 |
60 |
61 | https://friendly.github.io/nestedLogit/reference/nestedHypotheses.html
62 |
63 |
64 | https://friendly.github.io/nestedLogit/reference/nestedLogit.html
65 |
66 |
67 | https://friendly.github.io/nestedLogit/reference/nestedMethods.html
68 |
69 |
70 | https://friendly.github.io/nestedLogit/reference/plot.nestedLogit.html
71 |
72 |
73 |
--------------------------------------------------------------------------------
/examples/00Index:
--------------------------------------------------------------------------------
1 | BlauDuncan-example Blau-Duncan-- Education of fathers and sons
2 | GSS-example GSS example-- parent-child education
3 | HealthInsurance-example HealthInsurance example
4 | HealthInsurance-plot Health Insurance plots
5 | nested-methods-examples test nested-methods
6 | wlf-nested-example Womenlf nested examples
7 | wlf-nested-plot Womenlf nested plots
8 | wlf-nested-test Womenlf nested tests
9 |
--------------------------------------------------------------------------------
/examples/BlauDuncan-example.R:
--------------------------------------------------------------------------------
1 | #' ---
2 | #' title: Blau-Duncan- Education of fathers and sons
3 | #' ---
4 |
5 | BlauDuncan <- read.table("https://www.john-fox.ca/AppliedRegression/BlauDuncan.txt",
6 | header=TRUE, stringsAsFactors=TRUE)
7 |
8 |
9 | library(nestedLogit)
10 |
11 | #' ## Recode education and education.father
12 | BlauDuncan$educ <- factor(car::recode(BlauDuncan$education,
13 | " 0:3='gradeschool.or.less'; 4='some.highschool'; 5='highschool';
14 | 6='some.college'; 7:8='college.or.more' "),
15 | levels=c('gradeschool.or.less', 'some.highschool',
16 | 'highschool', 'some.college', 'college.or.more'))
17 |
18 | BlauDuncan$educ.father <- factor(car::recode(BlauDuncan$education.father,
19 | " 0:3='gradeschool.or.less'; 4='some.highschool'; 5='highschool';
20 | 6='some.college'; 7:8='college.or.more' "),
21 | levels=c('gradeschool.or.less', 'some.highschool',
22 | 'highschool', 'some.college', 'college.or.more'))
23 |
24 | #' ## Fit the nested logit model
25 | m.BD <- nestedLogit(educ ~ educ.father + ses.father + race,
26 | continuationLogits(c('gradeschool.or.less', 'some.highschool',
27 | 'highschool', 'some.college', 'college.or.more')),
28 | data=BlauDuncan)
29 |
30 | m.BD
31 | summary(m.BD)
32 | car::Anova(m.BD)
33 |
34 | coef(m.BD)
35 |
36 | new <- expand.grid(educ.father=c('gradeschool.or.less', 'some.highschool',
37 | 'highschool', 'some.college', 'college.or.more'),
38 | ses.father=mean(BlauDuncan$ses.father, na.rm=TRUE),
39 | race=c("white", "negro", "other"))
40 |
41 | pred.BD <- predict(m.BD, new)
42 |
43 | plotdata <- cbind(new, pred.BD)
44 |
45 | op <- par(mfrow=c(3, 1), mar=c(4, 4, 5, 1)+.1)
46 | cols <- car::carPalette()
47 | for ( rc in c("white", "negro", "other") ) {
48 | data <- subset(plotdata, race==rc)
49 | with(data, {
50 | plot( c(1, 5), c(0, 0.5),
51 | type="n",
52 | axes=FALSE,
53 | xlab="Father's Education",
54 | ylab='Fitted Probability',
55 | main = paste("Race:", rc),
56 | cex.lab = 1.1,
57 | cex.main = 1.25)
58 | axis(2)
59 | axis(1, at=1:5, labels=c('gradeschool.or.less', 'some.highschool',
60 | 'highschool', 'some.college', 'college.or.more'))
61 | lines(1:5, gradeschool.or.less, lwd=3, lty=1, col=cols[1],
62 | pch=1, cex=1.5, type="b")
63 | lines(1:5, some.highschool, lwd=3, lty=2, col=cols[2],
64 | pch=2, cex=1.5, type="b")
65 | lines(1:5, highschool, lwd=3, lty=3, col=cols[3],
66 | pch=3, cex=1.5, type="b")
67 | lines(1:5, some.college, lwd=3, lty=4, col=cols[4],
68 | pch=4, cex=1.5, type="b")
69 | lines(1:5, college.or.more, lwd=3, lty=5, col=cols[5],
70 | pch=5, cex=1.5, type="b")
71 | })
72 |
73 | if (rc == "white") {
74 | legend(4, 0.7, lty=1:5, pch=1:5, lwd=3, pt.cex=1.5, col=cols, bty = "n",
75 | legend=c('gradeschool.or.less', 'some.highschool',
76 | 'highschool', 'some.college', 'college.or.more'),
77 | title="Education",
78 | xpd=TRUE)
79 | }
80 | }
81 | par(op)
82 |
83 |
--------------------------------------------------------------------------------
/examples/Effect.nestedLogit-examples.R:
--------------------------------------------------------------------------------
1 |
2 | library(effects)
3 | library(nestedLogit)
4 | source("experimental/Effect.nestedLogit.R")
5 |
6 | example("nestedLogit")
7 |
8 | eff <- Effect("hincome", m)
9 | eff
10 | summary(eff)
11 | plot(eff)
12 | plot(eff, axes=list(y=list(style="stacked")))
13 |
14 | lbinary <- logits(AB_CD = dichotomy(c("A", "B"), c("C", "D")),
15 | A_B = dichotomy("A", "B"),
16 | C_D = dichotomy("C", "D"))
17 | health.nested <- nestedLogit(product4 ~ age + gender * household + position_level,
18 | dichotomies = lbinary, data = HealthInsurance)
19 | eff.h <- Effect(c("gender", "household"), health.nested)
20 | eff.h
21 | plot(eff.h)
22 | plot(eff.h, axes=list(y=list(style="stacked")))
23 |
24 | # tests of correctness
25 |
26 | eff.1 <- Effect("children", m)
27 | new <- eff.1$x
28 | new$hincome <- mean(Womenlf$hincome)
29 | pred.1 <- predict(m, newdata=new)
30 | all.equal(eff.1$prob, as.matrix(pred.1$p), check.attributes=FALSE)
31 | all.equal(eff.1$se.prob, as.matrix(pred.1$se.p), check.attributes=FALSE)
32 |
33 | Womenlf$kids <- with(Womenlf, ifelse(children == "present", 1, 0))
34 | mm <- update(m, . ~ . - children + kids, data=Womenlf)
35 | eff.2 <- Effect("hincome", m)
36 | new <- eff.2$x
37 | new$kids <- mean(Womenlf$kids)
38 | pred.2 <- predict(mm, newdata=new)
39 | all.equal(eff.2$prob, as.matrix(pred.2$p), check.attributes=FALSE)
40 | all.equal(eff.2$se.prob, as.matrix(pred.2$se.p), check.attributes=FALSE)
41 |
42 | eff.3 <- Effect("hincome", m,
43 | fixed.predictors=list(given.values=c(childrenpresent=0.5)))
44 | new <- eff.3$x
45 | new$kids <- c(kids=0.5)
46 | pred.3 <- predict(mm, newdata=new)
47 | all.equal(eff.3$prob, as.matrix(pred.3$p), check.attributes=FALSE)
48 | all.equal(eff.3$se.prob, as.matrix(pred.3$se.p), check.attributes=FALSE)
49 |
50 | new <- eff.h$x
51 | new$age <- with(HealthInsurance, mean(age))
52 | new$position_level <- with(HealthInsurance, mean(position_level))
53 | pred.h <- predict(health.nested, newdata=new)
54 | all.equal(eff.h$prob, as.matrix(pred.h$p), check.attributes=FALSE)
55 | all.equal(eff.h$se.prob, as.matrix(pred.h$se.p), check.attributes=FALSE)
56 | all.equal(eff.h$logit, as.matrix(pred.h$logit), check.attributes=FALSE)
57 | all.equal(eff.h$se.logit, as.matrix(pred.h$se.logit), check.attributes=FALSE)
58 |
59 | # tests with missing data
60 |
61 | H <- HealthInsurance
62 | H[2, 2] <- H[3, 3] <- H[4, 4] <- H[5, 5] <- H[6, 6] <- NA
63 | h.n <- update(health.nested, data=H)
64 | eff.h <- Effect(c("gender", "household"), h.n)
65 | eff.h
66 | plot(eff.h)
67 | plot(eff.h, axes=list(y=list(style="stacked")))
68 | new <- eff.h$x
69 | H <- na.omit(H[, 2:6])
70 | new$age <- with(H, mean(age))
71 | new$position_level <- with(H, mean(position_level))
72 | pred.h <- predict(h.n, newdata=new)
73 | all.equal(eff.h$prob, as.matrix(pred.h$p), check.attributes=FALSE)
74 | all.equal(eff.h$se.prob, as.matrix(pred.h$se.p), check.attributes=FALSE)
75 | all.equal(eff.h$logit, as.matrix(pred.h$logit), check.attributes=FALSE)
76 | all.equal(eff.h$se.logit, as.matrix(pred.h$se.logit), check.attributes=FALSE)
77 |
78 | # check whether other Effect() args work
79 |
80 | Effect("hincome", m, xlevels=10)
81 | Effect("hincome", m, xlevels=list(hincome=seq(5, 45, by=5)))
82 |
83 | plot(Effect("hincome", m))
84 | plot(Effect("hincome", m, confidence.level=0.50))
85 |
--------------------------------------------------------------------------------
/examples/GSS-example.R:
--------------------------------------------------------------------------------
1 | #' ---
2 | #' title: GSS example-- parent-child education
3 | #' ---
4 |
5 | library(nestedLogit)
6 |
7 | #' Check crosstab of degree by parentdeg
8 | round(100*with(GSS, prop.table(table(degree, parentdeg), 2)))
9 |
10 | m1 <- nestedLogit(degree ~ parentdeg*year,
11 | continuationLogits(c("l.t.highschool", "highschool",
12 | "college", "graduate")),
13 | data=GSS)
14 | car::Anova(m1)
15 |
16 | m2 <- nestedLogit(degree ~ parentdeg + year,
17 | continuationLogits(c("l.t.highschool", "highschool",
18 | "college", "graduate")),
19 | data=GSS)
20 |
21 | summary(m2)
22 |
23 | new <- expand.grid(parentdeg=c("l.t.highschool", "highschool",
24 | "college", "graduate"),
25 | year=1972:2016)
26 | pred.GSS <- predict(m2, new)
27 | plotdata <- cbind(new, pred.GSS)
28 |
29 | cols <- car::carPalette()
30 | degs <- c("l.t.highschool", "highschool",
31 | "college", "graduate")
32 | deg <- c("< high school", "high school", "college", "graduate")
33 | op <- par(mfrow=c(2, 2), mar=c(4,4,3,1)+.1)
34 | for (i in 1:4) {
35 | data <- subset(plotdata, parentdeg == degs[i])
36 | with(data, {
37 | plot( c(1972, 2016), c(0, 1),
38 | type="n",
39 | xlab="Year",
40 | ylab='Fitted Probability',
41 | main = paste("Parents' Education:", deg[i]),
42 | cex.lab = 1.1)
43 | for (j in 1:4){
44 | lines(year, data[, degs[j]], lwd=3, lty=j, col=cols[j])
45 | }
46 | })
47 | if (i == 1) {
48 | legend(1972, 1, lty=1:5, lwd=3, col=cols, bty = "n",
49 | legend=deg,
50 | xpd=TRUE)
51 | }
52 | }
53 | par(op)
54 |
55 | # check that predicted probabilities are correct
56 |
57 | p.m2.1 <- predict(m2$models[[1]], newdata=new, type="response")
58 | p.m2.2 <- predict(m2$models[[2]], newdata=new, type="response")
59 | p.m2.3 <- predict(m2$models[[3]], newdata=new, type="response")
60 |
61 | all.equal(1 - p.m2.1, pred.GSS[, "l.t.highschool"])
62 | all.equal(p.m2.1*(1 - p.m2.2), pred.GSS[, "highschool"])
63 | all.equal(p.m2.1*p.m2.2*(1 - p.m2.3), pred.GSS[, "college"])
64 | all.equal(p.m2.1*p.m2.2*p.m2.3, pred.GSS[, "graduate"])
65 |
66 |
--------------------------------------------------------------------------------
/examples/HealthInsurance-example.R:
--------------------------------------------------------------------------------
1 | #' ---
2 | #' title: HealthInsurance example
3 | #' ---
4 |
5 | # test different dichotomies for 4 level response
6 |
7 | library(ggplot2)
8 | library(directlabels)
9 |
10 |
11 | #' ## define logits as successive binary splits of A, B, C, D
12 | lbinary <- logits(AB_CD = dichotomy(c("A", "B"), c("C", "D")),
13 | A_B = dichotomy("A", "B"),
14 | C_D = dichotomy("C", "D"))
15 |
16 | as.matrix(lbinary)
17 |
18 | health.nested <- nestedLogit(product4 ~ age + gender * household + position_level,
19 | dichotomies = lbinary, data = HealthInsurance)
20 | car::Anova(health.nested)
21 |
22 | #' ## predict and plot
23 | #'
24 | new <- expand.grid(age=seq(20, 70, by = 5),
25 | gender = c("Female", "Male"),
26 | household = mean(HealthInsurance$household),
27 | position_level = mean(HealthInsurance$position_level)
28 | )
29 |
30 | fit <-data.frame(new,
31 | predict(health.nested, newdata = new))
32 |
33 | plotdat <- fit |>
34 | tidyr::gather(key="Level", value="Probability", A:D)
35 |
36 | gg <- ggplot(plotdat, aes(x = age, y = Probability, colour= Level)) +
37 | geom_line(linewidth = 1.5) +
38 | facet_grid(~ gender, labeller= label_both)
39 |
40 | direct.label(gg, list("top.bumptwice", dl.trans(y = y + 0.2)))
41 |
42 |
43 |
44 | #' ## check fitted probabilities
45 |
46 | pred <- predict(health.nested, newdata = new)
47 |
48 | pred.m.1 <- predict(health.nested$models[[1]], newdata=new, type="response")
49 | pred.m.2 <- predict(health.nested$models[[2]], newdata=new, type="response")
50 | pred.m.3 <- predict(health.nested$models[[3]], newdata=new, type="response")
51 |
52 | pred.A <- (1 - pred.m.1)*(1 - pred.m.2)
53 | all.equal(pred.A, pred[, "A"])
54 | pred.B <- (1 - pred.m.1)*pred.m.2
55 | all.equal(pred.B, pred[, "B"])
56 | pred.C <- pred.m.1*(1 - pred.m.3)
57 | all.equal(pred.C, pred[, "C"])
58 | pred.D <- pred.m.1*pred.m.3
59 | all.equal(pred.D, pred[, "D"])
60 |
61 |
--------------------------------------------------------------------------------
/examples/HealthInsurance-plot-se.R:
--------------------------------------------------------------------------------
1 | #' ---
2 | #' title: Health Insurance plots with std errors
3 | #' ---
4 |
5 | library(nestedLogit)
6 | library(ggplot2)
7 | library(geomtextpath)
8 |
9 | #source("./experimental/predict-with-se.R")
10 | #source("./experimental/plot.nested--with-conf-limits.R")
11 | #source("./experimental/as.data.frame.predict.R")
12 |
13 | # define logits as successive binary splits of A, B, C, D
14 | lbinary <- logits(AB_CD = dichotomy(c("A", "B"), c("C", "D")),
15 | A_B = dichotomy("A", "B"),
16 | C_D = dichotomy("C", "D"))
17 |
18 | health.mod <- nestedLogit(product4 ~ age + gender * household + position_level,
19 | dichotomies = lbinary, data = HealthInsurance)
20 |
21 | # predict data for effects of age, gender, averaged over household and position_level
22 | new <- expand.grid(age=seq(20, 70, by = 10),
23 | gender = c("Female", "Male"),
24 | household = mean(HealthInsurance$household),
25 | position_level = mean(HealthInsurance$position_level)
26 | )
27 |
28 | #' ## package plot method
29 | op <- par(mfcol=c(1, 2), mar=c(4, 4, 3, 1) + 0.1)
30 | plot(health.mod, "age", list(gender="Female"),
31 | xlab="Age", legend.location="top",
32 | main = "gender: Female")
33 | plot(health.mod, "age", list(gender="Male"),
34 | xlab="Age", legend = FALSE,
35 | main = "gender: Male")
36 | par(op)
37 |
38 | #' ## Using ggplot
39 |
40 | # make a data.frame in long format
41 | health.pred <- predict(health.mod, new)
42 | plotdata <- as.data.frame(health.pred)
43 |
44 | # plot probabilities
45 | plotdata |>
46 | ggplot(aes(x = age, y = p, color = response)) +
47 | geom_line(linewidth = 1) +
48 | geom_point(size = 1.5, shape = 16, color = "black") +
49 | scale_color_discrete() +
50 | labs(x="Age", y= "Fitted Probability") +
51 | facet_wrap(~ gender, labeller = label_both) +
52 | theme_bw(base_size = 14) +
53 | geom_ribbon(aes(ymin = p - 1.96 * se.p,
54 | ymax = p + 1.96 * se.p,
55 | fill = response), alpha = 0.3) +
56 | geom_textline(aes(label = response), hjust = 0.0, vjust=-0.5, size=5) +
57 | theme(legend.position = "none")
58 |
59 | # plot logits
60 | plotdata |>
61 | ggplot(aes(x = age, y = logit, color = response)) +
62 | geom_line(linewidth = 1) +
63 | geom_point(size = 1.5, shape = 16, color = "black") +
64 | scale_color_discrete() +
65 | labs(x="Age", y= "Fitted Log Odds") +
66 | facet_wrap(~ gender, labeller = label_both) +
67 | theme_bw(base_size = 14) +
68 | geom_ribbon(aes(ymin = logit - 2 * se.logit,
69 | ymax = logit + 2 * se.logit,
70 | fill = response), alpha = 0.3) +
71 | geom_textline(aes(label = response), hjust = 0.0, vjust=-0.5, size=5) +
72 | theme(legend.position = "none")
73 |
74 |
--------------------------------------------------------------------------------
/examples/HealthInsurance-plot.R:
--------------------------------------------------------------------------------
1 | #' ---
2 | #' title: Health Insurance plots
3 | #' ---
4 |
5 | # test different dichotomies for 4 level response
6 |
7 | library(nestedLogit)
8 | library(ggplot2)
9 | library(directlabels)
10 | library(nnet)
11 |
12 | #' ## Binary splits
13 | # define logits as successive binary splits of A, B, C, D
14 | lbinary <- logits(AB_CD = dichotomy(c("A", "B"), c("C", "D")),
15 | A_B = dichotomy("A", "B"),
16 | C_D = dichotomy("C", "D"))
17 |
18 | as.matrix(lbinary)
19 |
20 | health.binary <- nestedLogit(product4 ~ age + gender * household + position_level,
21 | dichotomies = lbinary, data = HealthInsurance)
22 | car::Anova(health.binary)
23 |
24 | new <- expand.grid(age=seq(20, 70, by = 5),
25 | gender = c("Female", "Male"),
26 | household = mean(HealthInsurance$household),
27 | position_level = mean(HealthInsurance$position_level)
28 | )
29 |
30 | fit.binary <-data.frame(new,
31 | predict(health.binary, newdata = new))
32 |
33 | plotdat <- fit.binary |>
34 | tidyr::gather(key="Level", value="Probability", A:D)
35 |
36 | gg <- ggplot(plotdat, aes(x = age, y = Probability, colour= Level)) +
37 | geom_line(linewidth = 1.5) +
38 | facet_grid(~ gender, labeller= label_both) +
39 | ggtitle("Nested model: {{A B} {C D}}, {A B}, {C D}")
40 |
41 | direct.label(gg, list("top.bumptwice", dl.trans(y = y + 0.2)))
42 |
43 | #' ## Continuation logits
44 |
45 | health.contin <- nestedLogit(product4 ~ age + gender * household + position_level,
46 | dichotomies = continuationLogits(4), data = HealthInsurance)
47 | car::Anova(health.contin)
48 |
49 | fit.contin <-data.frame(new,
50 | predict(health.binary, newdata = new))
51 | plotdat <- fit.contin |>
52 | tidyr::gather(key="Level", value="Probability", A:D)
53 |
54 | gg <- ggplot(plotdat, aes(x = age, y = Probability, colour= Level)) +
55 | geom_line(linewidth = 1.5) +
56 | facet_grid(~ gender, labeller= label_both) +
57 | ggtitle("Continuation logits")
58 |
59 | direct.label(gg, list("top.bumptwice", dl.trans(y = y + 0.2)))
60 |
61 | #' ## Compare predictions
62 | #'
63 | diff <- predict(health.binary, newdata = new) - predict(health.contin, newdata = new)
64 | max(diff)
65 | summary(diff)
66 |
67 | #' ## Compare with multinomial model
68 | health.multi <- multinom(product4 ~ age + gender * household + position_level,
69 | data = HealthInsurance)
70 |
71 | car::Anova(health.multi)
72 |
73 | fit.multi <-data.frame(new,
74 | predict(health.multi, newdata=new, type='probs'))
75 |
76 | plotdat <- fit.multi |>
77 | tidyr::gather(key="Level", value="Probability", A:D)
78 |
79 | gg <- ggplot(plotdat, aes(x = age, y = Probability, colour= Level)) +
80 | geom_line(linewidth = 1.5) +
81 | facet_grid(~ gender, labeller= label_both) +
82 | ggtitle("Multinomial model")
83 |
84 | direct.label(gg, list("top.bumptwice", dl.trans(y = y + 0.2)))
85 |
86 | #' ## Compare predicted values
87 |
88 | diff <- predict(health.binary, newdata = new) - predict(health.multi, newdata = new, type = "probs")
89 | max(diff)
90 | summary(diff)
91 |
92 | # get predicted 'class' from multinom
93 |
94 | pred <- predict(health.multi, type = "class")
95 | table(HealthInsurance$product4, pred)
96 |
97 |
--------------------------------------------------------------------------------
/examples/check_dichotomies.R:
--------------------------------------------------------------------------------
1 | #' Check validity of dichotomies as nested lists
2 | #'
3 | #'
4 | #' @param x
5 | #' @param levels
6 | #'
7 | #' @author Achim Zeileis
8 | #' @return
9 | #' @export
10 | #'
11 | #' @examples
12 | check_dichotomies <- function(x, levels = NULL) {
13 | if(!is.null(levels)) {
14 | xvec <- unlist(x)
15 | if(anyDuplicated(xvec) > 0L || length(setdiff(xvec, levels)) > 0L || length(setdiff(levels, xvec)) > 0L) {
16 | stop("dichotomies must contain all levels exactly once")
17 | }
18 | }
19 | if(!is.list(x) || length(x) != 2L) stop("dichotomies must be (recursive) lists of two elements")
20 | xlist <- sapply(x, is.list)
21 | if(any(!xlist)) {
22 | ok <- sapply(which(!xlist), function(i) is.character(x[[i]]) && length(x[[i]]) == 1L)
23 | if(any(!ok)) stop("terminal elements of dichotomies must be character strings of length 1")
24 | }
25 | ok <- if(any(xlist)) {
26 | all(sapply(x[xlist], check_dichotomies))
27 | } else {
28 | TRUE
29 | }
30 | return(ok)
31 | }
32 |
33 | if(FALSE) {
34 |
35 | ## levels
36 | lev <- c("a", "b", "c", "d")
37 |
38 | ## ok
39 | d1 <- list("a", list("b", list("c", "d")))
40 | d2 <- list(list(list("a", "c"), "d"), "b")
41 | d3 <- list(list("a", "d"), list("b", "c"))
42 | check_dichotomies(d1, levels = lev)
43 | check_dichotomies(d2, levels = lev)
44 | check_dichotomies(d3, levels = lev)
45 |
46 | ## not ok
47 | x1 <- list("a", list("b", list("c", "e")))
48 | x2 <- list("a", list("b", list("c", list("d", "d"))))
49 | x3 <- list("a", list("b", c("c", "d")))
50 | x4 <- list("a", list("b", "c", "d"))
51 | check_dichotomies(x1, levels = lev)
52 | check_dichotomies(x2, levels = lev)
53 | check_dichotomies(x3, levels = lev)
54 | check_dichotomies(x4, levels = lev)
55 |
56 | lev <- c("plane", "train", "bus", "car")
57 | travel <- list(
58 | air = "plane",
59 | ground = list(
60 | public = list("train", "bus"),
61 | private = "car"
62 | )
63 | )
64 |
65 | check_dichotomies(travel, lev)
66 |
67 | unlist(travel, names)
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/examples/createDichotomies-test.R:
--------------------------------------------------------------------------------
1 | # check createDichotomies
2 |
3 | library(nestedLogit)
4 |
5 | d1 <- list("a", list("b", list("c", "d")))
6 | d2 <- list(list(list("a", "c"), "d"), "b")
7 | d3 <- list(list("a", "d"), list("b", "c"))
8 |
9 | nestedLogit:::createDichotomies(d1)
10 | nestedLogit:::createDichotomies(d2)
11 | nestedLogit:::createDichotomies(d3)
12 |
13 | x1 <- list("a", list("b", list("c", "e"))) # actually OK (w/o giving levels)
14 | x2 <- list("a", list("b", list("c", list("d", "d"))))
15 | x3 <- list("a", list("b", c("c", "d")))
16 | x4 <- list("a", list("b", "c", "d"))
17 |
18 | nestedLogit:::createDichotomies(x1)
19 | nestedLogit:::createDichotomies(x2)
20 | nestedLogit:::createDichotomies(x3)
21 | nestedLogit:::createDichotomies(x4)
22 |
23 | (di1 <- nestedLogit:::createDichotomies(d1))
24 | names(di1)
25 | names(di1) <- c("d1", "d2", "d3")
26 | di1
27 |
28 | dd1 <- list("a", BCD=list("b", CD=list("c", "d")))
29 | nestedLogit:::createDichotomies(dd1)
30 |
31 | dd3 <- list(private=list("a", "d"), public=list("b", "c"))
32 | nestedLogit:::createDichotomies(dd3)
33 |
34 |
35 | nestedLogit:::createDichotomies(travel <- list(
36 | air = "plane",
37 | ground = list(
38 | public = list("train", "bus"),
39 | private = "car"
40 | )))
41 |
42 | labor <- list(
43 | work = "not.work",
44 | full = list("parttime", "fulltime"))
45 |
46 | nestedLogit:::createDichotomies(labor)
47 |
48 |
--------------------------------------------------------------------------------
/examples/gators.R:
--------------------------------------------------------------------------------
1 | #' ---
2 | #' title: Food choice of alligators
3 | #' ---
4 |
5 | # from: https://data.library.virginia.edu/getting-started-with-multinomial-logit-models/
6 |
7 | library(nestedLogit)
8 | library(car)
9 | library(nnet)
10 | library(ggeffects)
11 | library(ggplot2)
12 |
13 | gators <- read.csv('https://static.lib.virginia.edu/statlab/materials/data/table_8-1.csv')
14 | gators$food <- factor(gators$food,
15 | levels = c("O", "F", "I"),
16 | labels = c("Other", "Fish", "Invertebrates"))
17 |
18 | gator.multi <- multinom(food ~ length, data = gators,
19 | Hess = TRUE, trace = FALSE)
20 |
21 | summary(gator.multi, Wald.ratios = TRUE)
22 | confint(gator.multi)
23 |
24 | Anova(gator.multi)
25 |
26 | pred <- predict(gator.multi, type = "probs")
27 |
28 |
29 | eff <- ggeffect(gator.multi, terms = "length[1:4,by=0.5]")
30 | ggplot(eff) +
31 | aes(x = x, y = predicted, fill = response.level, color = response.level) +
32 | geom_line() +
33 | geom_ribbon(aes(ymin = conf.low, ymax = conf.high), alpha = 1/3) +
34 | labs(x = 'Length of Alligator', y = 'Predicted Probability') +
35 | ylim(c(0, 1))
36 |
37 |
38 | #' ## use nested logits
39 |
40 | dichot <- logits(d1=dichotomy("Other", c("Fish", "Invertebrates")),
41 | d2=dichotomy("Fish", "Invertebrates"))
42 |
43 | gator.nested <- nestedLogit(food ~ length,
44 | dichotomies = dichot,
45 | data = gators)
46 |
47 | # use the plot method
48 | plot(gator.nested, x.var = "length")
49 |
50 | new <- data.frame(length = seq(1, 4, by = 0.25))
51 | pred <- predict(gator.nested, newdata = new)
52 | plotdat <- as.data.frame(pred)
53 |
54 | # this doesn't work:
55 | # > eff <- ggeffect(gator.nested, terms = "length[1:4,by=0.5]")
56 | # Can't compute marginal effects, 'effects::Effect()' returned an error.
57 | #
58 | # Reason: object 'prior.weights' not found
59 | # You may try 'ggpredict()' or 'ggemmeans()'.
60 |
61 | eff <- ggeffect(gator.nested, terms = "length[1:4,by=0.5]")
62 |
63 |
64 | matplot(plotdat[, "length"], plotdat[, 2:4],
65 | type ="b",
66 | xlab = "Length",
67 | ylab = "Probability")
68 |
--------------------------------------------------------------------------------
/examples/ggeffects-test.R:
--------------------------------------------------------------------------------
1 | # test ggeffects
2 |
3 | install.packages("ggeffects", repos = "https://strengejacke.r-universe.dev")
4 | install.packages("insight", repos = "https://easystats.r-universe.dev")
5 | library(ggeffects)
6 | library(insight)
7 | packageVersion("ggeffects")
8 | # tested using latgest version, 1.2.2.12
9 |
10 | library(nestedLogit)
11 |
12 | data("Womenlf", package = "carData")
13 | m <- nestedLogit(partic ~ hincome + children,
14 | logits(
15 | work = dichotomy("not.work", c("parttime", "fulltime")),
16 | full = dichotomy("parttime", "fulltime")
17 | ),
18 | data = Womenlf
19 | )
20 |
21 | ggpredict(m, c("hincome[all]", "children")) |> plot()
22 |
23 |
24 | # Data were 'prettified'. Consider using `terms="hincome [all]"` to get smooth plots.
25 | # Error: At least one term specified in `terms` is no valid model term.
26 |
27 |
28 |
29 | wlf.ggeff <- ggeffect(m, terms = c("hincome[5:40, by=5]", "children"))
30 | plot(wlf.ggeff, facet=TRUE)
31 |
32 | # why does this produce only one plot??
33 |
34 | ggeffects::ggeffect(m, terms = c("hincome[10:40, by=10]"))
35 |
36 | effects::Effect("hincome", m, xlevels=list(hincome = seq(10,40,10)))
37 |
38 | library(nestedLogit)
39 | library(ggeffects)
40 | library(effects)
41 | ggpredict(wlf.nested, c("hincome", "children")) |> plot() # OK
42 | ggeffect(wlf.nested, "hincome") |> plot() # bugged!
43 |
44 | Effect("hincome", wlf.nested) |> plot() # OK
45 | #ggeffect(wlf.multinom, "hincome") |> plot() # OK
46 |
47 |
--------------------------------------------------------------------------------
/examples/nested-methods-examples.R:
--------------------------------------------------------------------------------
1 | #' ---
2 | #' title: test nested-methods
3 | #' ---
4 |
5 | library(nestedLogit)
6 | data(Womenlf, package = "carData")
7 |
8 | m1 <- nestedLogit(partic ~ hincome,
9 | logits(work=dichotomy("not.work", c("parttime", "fulltime")),
10 | full=dichotomy("parttime", "fulltime")),
11 | data=Womenlf)
12 |
13 | m2 <- nestedLogit(partic ~ hincome + children,
14 | logits(work=dichotomy("not.work", c("parttime", "fulltime")),
15 | full=dichotomy("parttime", "fulltime")),
16 | data=Womenlf)
17 |
18 | #' ## Test `anova()` methods
19 | anova(m1)
20 | anova(m2)
21 | anova(m1, m2)
22 |
23 | #' ## Test `update()` methods
24 | update(m1, partic ~ hincome + children)
25 | update(m1,. ~ . + children)
26 |
27 | summary(update(m2, dichotomies=logits(full=dichotomy(c("not.work", "parttime"), "fulltime"),
28 | part=dichotomy("not.work", "parttime"))))
29 |
30 | Ontario <- Womenlf[Womenlf$region == "Ontario", ]
31 | update(m1, data=Ontario)
32 |
33 | m2.ont <- update(m2, subset = "region == 'Ontario'", contrasts=list(children="contr.sum"))
34 | m2.ont
35 | summary(m2.ont)
36 |
--------------------------------------------------------------------------------
/examples/parameters-test.R:
--------------------------------------------------------------------------------
1 | #' ---
2 | #' title: Test parameters package
3 | #' ---
4 | #'
5 | library(nestedLogit)
6 | library(parameters)
7 | library(performance)
8 | data(Womenlf, package="carData")
9 | comparisons <- logits(work=dichotomy("not.work", c("parttime", "fulltime")),
10 | full=dichotomy("parttime", "fulltime"))
11 | wlf.nested <- nestedLogit(partic ~ hincome + children,
12 | dichotomies = comparisons,
13 | data=Womenlf)
14 |
15 | (parm <- parameters(wlf.nested))
16 |
17 | parameters(wlf.nested, exponentiate = TRUE)
18 |
19 | # see::plot(parm) -- doesn't do anything useful
20 | # check <- performance::check_normality(wlf.nested)
21 | # Checking normality of residuals is only appropriate for linear models.
22 |
--------------------------------------------------------------------------------
/examples/predict-test.R:
--------------------------------------------------------------------------------
1 | # test with ggeffects and other easystats pkgs
2 |
3 | library(nestedLogit)
4 |
5 | # get dev version
6 | #install.packages("ggeffects", repos = "https://strengejacke.r-universe.dev")
7 | #remotes::install_github("strengejacke/ggeffects")
8 | library(ggeffects)
9 |
10 | data("Womenlf", package = "carData")
11 | m <- nestedLogit(partic ~ hincome + children,
12 | logits(
13 | work = dichotomy("not.work", c("parttime", "fulltime")),
14 | full = dichotomy("parttime", "fulltime")
15 | ),
16 | data = Womenlf
17 | )
18 | new <- expand.grid(
19 | hincome = c(20, 30, 40),
20 | children = c("absent", "present")
21 | )
22 |
23 | # this doesn't work
24 | #cbind(new, predict(m, newdata = new))
25 |
26 | pred <- predict(m, newdata = new)
27 | as.data.frame(pred, newdata=new)
28 |
29 |
30 | ggpredict(m, c("hincome [30, 40]", "children"))
31 |
--------------------------------------------------------------------------------
/examples/predict-with-se-example-2.R:
--------------------------------------------------------------------------------
1 | library(nestedLogit)
2 | source("./experimental/predict-with-se.R")
3 | source("./experimental/plot.nested--with-conf-limits.R")
4 |
5 | data(Womenlf, package="carData")
6 |
7 | comparisons <- logits(work=dichotomy("not.work", c("parttime", "fulltime")),
8 | full=dichotomy("parttime", "fulltime"))
9 |
10 | wlf.nested <- nestedLogit(partic ~ hincome + children,
11 | dichotomies = comparisons,
12 | data=Womenlf)
13 | # get predicted values for a grid
14 | new <- expand.grid(hincome=seq(0, 45, length=4),
15 | children=c("absent", "present"))
16 |
17 | pred.nested <- predict(wlf.nested, new)
18 | pred.nested
19 |
20 | confint(pred.nested)
21 | confint(pred.nested, parm="logit")
22 | confint(pred.nested, conf.limits.logit=FALSE) # note some limits < 0 and > 1
23 |
24 | plot(wlf.nested, "hincome", list(children="absent"),
25 | xlab="Husband's Income", legend.location="top")
26 |
27 | plot(wlf.nested, "hincome", list(children="absent"),
28 | xlab="Husband's Income", legend.location="top", conf.alpha=0.1)
29 |
30 | plot(wlf.nested, "hincome", list(children="absent"),
31 | xlab="Husband's Income", legend.location="top", conf.level=0.5)
32 |
33 | plot(wlf.nested, "children", list(hincome=round(mean(Womenlf$hincome))),
34 | legend.location="top")
35 |
36 | plot(wlf.nested, "children", list(hincome=round(mean(Womenlf$hincome))),
37 | legend.location="top", conf.level=0.5)
38 |
39 | plot(wlf.nested, "hincome", list(children="absent"),
40 | xlab="Husband's Income", legend.location="top", conf.level=NULL)
41 |
42 | plot(wlf.nested, "children", list(hincome=round(mean(Womenlf$hincome))),
43 | legend.location="top", conf.level=NULL)
44 |
45 | pred.dichotomies <- predict(wlf.nested, model="dichotomies", newdata=new)
46 | pred.dichotomies
47 | str(pred.dichotomies)
48 |
49 | pred.dichotomies <- predict(wlf.nested, model="dichotomies")
50 | head(pred.dichotomies)
51 | tail(pred.dichotomies)
52 | str(pred.dichotomies)
53 |
54 | # compare to multinomial logit model
55 |
56 | library(nnet)
57 | library(effects)
58 |
59 | m <- multinom(partic ~ hincome + children, data=Womenlf)
60 | plot(Effect(c("hincome", "children"), m))
61 |
62 | comparisons <- logits(full=dichotomy(c("not.work", "parttime"), "fulltime"),
63 | part=dichotomy("not.work", "parttime"))
64 |
65 | n <- nestedLogit(partic ~ hincome + children,
66 | dichotomies = comparisons,
67 | data=Womenlf)
68 |
69 | plot(n, "hincome", list(children="absent"),
70 | xlab="Husband's Income", legend.location="top")
71 |
72 | library(nnet)
73 | library(effects)
74 |
75 | m <- multinom(partic ~ hincome + children, data=Womenlf)
76 | plot(Effect(c("hincome", "children"), m))
77 |
78 | comparisons <- logits(full=dichotomy(c("not.work", "parttime"), "fulltime"),
79 | part=dichotomy("not.work", "parttime"))
80 |
81 | n <- nestedLogit(partic ~ hincome + children,
82 | dichotomies = comparisons,
83 | data=Womenlf)
84 |
85 | plot(n, "hincome", list(children="absent"),
86 | xlab="Husband's Income", legend.location="top")
87 |
88 | library(nnet)
89 | library(effects)
90 |
91 | m <- multinom(partic ~ hincome + children, data=Womenlf)
92 | plot(Effect(c("hincome", "children"), m))
93 |
94 | comparisons <- logits(full=dichotomy(c("not.work", "parttime"), "fulltime"),
95 | part=dichotomy("not.work", "parttime"))
96 |
97 | n <- nestedLogit(partic ~ hincome + children,
98 | dichotomies = comparisons,
99 | data=Womenlf)
100 |
101 | plot(n, "hincome", list(children="absent"),
102 | xlab="Husband's Income", legend.location="top")
103 |
104 | library(nnet)
105 | library(effects)
106 |
107 | m <- multinom(partic ~ hincome + children, data=Womenlf)
108 | plot(Effect(c("hincome", "children"), m))
109 |
110 | comparisons <- logits(full=dichotomy(c("not.work", "parttime"), "fulltime"),
111 | part=dichotomy("not.work", "parttime"))
112 |
113 | n <- nestedLogit(partic ~ hincome + children,
114 | dichotomies = comparisons,
115 | data=Womenlf)
116 |
117 | plot(n, "hincome", list(children="absent"),
118 | xlab="Husband's Income", legend.location="top")
119 |
120 | head(predict(m, type="probs")[, c("not.work", "parttime", "fulltime")])
121 | head(predict(n)$p)
122 | diag(cor(predict(m, type="probs")[, c("not.work", "parttime", "fulltime")], predict(n)$p))
123 | apply(abs(predict(m, type="probs")[, c("not.work", "parttime", "fulltime")] - predict(n)$p), 2, mean)
124 |
--------------------------------------------------------------------------------
/examples/predict-with-se-example.R:
--------------------------------------------------------------------------------
1 | library(nestedLogit)
2 | library(dplyr, warn.conflicts = FALSE)
3 | library(tidyr)
4 | library(ggplot2)
5 | library(geomtextpath)
6 | source("./experimental/predict-with-se.R")
7 |
8 | data(Womenlf, package="carData")
9 |
10 | comparisons <- logits(work=dichotomy("not.work", c("parttime", "fulltime")),
11 | full=dichotomy("parttime", "fulltime"))
12 |
13 | wlf.nested <- nestedLogit(partic ~ hincome + children,
14 | dichotomies = comparisons,
15 | data=Womenlf)
16 | # get predicted values for a grid
17 | new <- expand.grid(hincome=seq(0, 45, length=4),
18 | children=c("absent", "present"))
19 |
20 | pred.nested <- predict(wlf.nested, new)
21 | names(pred.nested)
22 |
23 | rowSums(pred.nested$p)
24 |
25 |
26 | pred.dichotomies <- predict(wlf.nested, new, model = "dichotomies")
27 |
28 | # print method doesn't do anything useful
29 | pred.dichotomies
30 |
31 | sapply(pred.dichotomies, cbind)
32 |
33 | #' ## Transform predicted values to long suitable for plotting
34 |
35 | # matrices don't work well with tidy processing; these should be data.frames
36 | pred.nested.df <- lapply(pred.nested, as.data.frame)
37 |
38 | # add predictors to each data set
39 | pred.nested.df <-lapply(pred.nested.df, cbind, new)
40 |
41 |
42 | # make a dataset for plotting
43 |
44 | prob <- pred.nested.df$p |> relocate(hincome, children)
45 |
46 | se.prob <- pred.nested.df$se.p |> relocate(hincome, children)
47 | resp.names <- colnames(pred.nested.df$p)
48 |
49 | p_long <- prob |>
50 | tidyr::pivot_longer(cols = not.work:fulltime,
51 | names_to = "response",
52 | values_to = "prob")
53 |
54 | se_long <- se.prob |>
55 | tidyr::pivot_longer(cols = not.work:fulltime,
56 | names_to = "response",
57 | values_to = "se.prob")
58 |
59 | plotprob <- cbind(p_long, se.prob = se_long$se.prob)
60 |
61 | ggplot(plotprob,
62 | aes(x=hincome, y=prob, color=response)) +
63 | geom_line(linewidth = 2) +
64 | geom_point(size = 1.5, shape = 16, color = "black") +
65 | scale_color_discrete() +
66 | labs(x="Husband's Income", y= "Probability") +
67 | facet_wrap(~ children, labeller = label_both) +
68 | theme_bw(base_size = 14) +
69 | geom_ribbon(aes(ymin=prob - se.prob,
70 | ymax=prob + se.prob,
71 | fill = response), alpha = 0.3) +
72 | geom_textline(aes(label = response), hjust = -0.01, vjust=-0.5, size=5) +
73 | theme(legend.position = "none")
74 |
75 | # --------------------------------------------
76 | # do the same for logit
77 |
78 | logit <- pred.nested.df$logit |> relocate(hincome, children)
79 |
80 | se.logit <- pred.nested.df$se.logit |> relocate(hincome, children)
81 | resp.names <- colnames(pred.nested.df$p)
82 |
83 | p_long <- logit |>
84 | tidyr::pivot_longer(cols = not.work:fulltime,
85 | names_to = "response",
86 | values_to = "logit")
87 |
88 | se_long <- se.logit |>
89 | tidyr::pivot_longer(cols = not.work:fulltime,
90 | names_to = "response",
91 | values_to = "se.logit")
92 |
93 | plotlogit <- cbind(p_long, se.logit = se_long$se.logit)
94 |
95 | ggplot(plotlogit,
96 | aes(x=hincome, y=logit, color=response)) +
97 | geom_line(linewidth = 2) +
98 | geom_point(size = 1.5, shape = 16, color = "black") +
99 | scale_color_discrete() +
100 | labs(x="Husband's Income", y= "Log Odds") +
101 | facet_wrap(~ children, labeller = label_both) +
102 | theme_bw(base_size = 14) +
103 | geom_ribbon(aes(ymin=logit - se.logit,
104 | ymax=logit + se.logit,
105 | fill = response), alpha = 0.3) +
106 | geom_textline(aes(label = response), hjust = -0.01, vjust=-0.5, size=5) +
107 | theme(legend.position = "none")
108 |
109 |
--------------------------------------------------------------------------------
/examples/predict-with-se-logit.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/examples/predict-with-se-logit.png
--------------------------------------------------------------------------------
/examples/predict-with-se-plot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/examples/predict-with-se-plot.png
--------------------------------------------------------------------------------
/examples/predict.nested-test.R:
--------------------------------------------------------------------------------
1 | #' ---
2 | #' title: nested predict methods
3 | #' ---
4 |
5 | data(Womenlf, package = "carData")
6 |
7 | #' ## Fit the model
8 | #' Use `logits()` and `dichotomy()` to specify the comparisons of interest
9 | comparisons <- logits(work=dichotomy("not.work", c("parttime", "fulltime")),
10 | full=dichotomy("parttime", "fulltime"))
11 |
12 | wlf.nested <- nestedLogit(partic ~ hincome + children,
13 | dichotomies = comparisons,
14 | data=Womenlf)
15 |
16 |
17 | #' ## Get predicted probabilities
18 | new <- expand.grid(hincome=seq(0, 45, length=10),
19 | children=c("absent", "present"))
20 |
21 | pred.nested <- predict(wlf.nested, newdata=new, model = "nested")
22 |
23 | head(pred.nested)
24 |
25 | pred.logits <- predict(wlf.nested, newdata=new, model = "dichotomies")
26 |
27 | # print method not useful
28 | pred.logits
29 |
30 | # show predicted values
31 | pred.logits$work
32 | pred.logits$full
33 |
34 | # what predict should give, when newdata is specified
35 | preds <- sapply(wlf.nested$models, predict, newdata=new)
36 | cbind(new, preds)
37 |
38 | #' ## predictions for observations (no newdata)
39 | #'
40 |
41 | obs.nested <- predict(wlf.nested, model = "nested")
42 |
43 | head(obs.nested)
44 |
45 | obs.logits <- predict(wlf.nested, model = "dichotomies")
46 |
47 | # print method not useful
48 | obs.logits
49 |
50 | # show predicted values
51 | str(obs.logits$work)
52 | str(obs.logits$full)
53 |
54 | # combine them into a data structure
55 | nms <- names(obs.logits)
56 | for (i in seq_along(obs.logits)) {
57 | obs.logits[[i]] <- cbind(response = nms[[i]], obs.logits[[i]])
58 | }
59 |
60 |
--------------------------------------------------------------------------------
/examples/wlf-ggplot.R:
--------------------------------------------------------------------------------
1 | #' ---
2 | #' title: Test ggplot2 methods for Womenlf data
3 | #' ---
4 | #'
5 | #' This example explores different ways of plotting the results for nested dichotomies using ggplot2.
6 | #' The `predict()` method for `nestedLogit` objects generates predicted probabilities
7 | #' of the response categories, their logits and corresponding standard errors.
8 | #'
9 | #' **Methods**: the following plotting methods are illustrated
10 | #'
11 | #' * ggplot
12 | #' * ggplot + geomtextpath
13 | #' * plotting the logit transformation of the probabilities
14 | #' * plotting the predicted results for the separate binary logit models that comprise the full model.
15 | #' * doing the same, for an alternative model for the nested dichotomies.
16 |
17 | #' This uses the new as.data.frame.predictDichotomies method
18 | #source("R/as.data.frame.predict.R")
19 | library(ggplot2)
20 | library(geomtextpath)
21 |
22 | data(Womenlf, package="carData")
23 |
24 | comparisons <- logits(work=dichotomy("not.work", c("parttime", "fulltime")),
25 | full=dichotomy("parttime", "fulltime"))
26 |
27 | wlf.nested <- nestedLogit(partic ~ hincome + children,
28 | dichotomies = comparisons,
29 | data=Womenlf)
30 |
31 | # get predicted values for a grid
32 | new <- expand.grid(hincome=seq(0, 45, length=4),
33 | children=c("absent", "present"))
34 |
35 | pred.nested <- predict(wlf.nested, new)
36 | plotdata <- as.data.frame(pred.nested)
37 |
38 | # set a consistent theme for all plots here
39 | theme_set(theme_bw(base_size = 14))
40 |
41 | ggplot(plotdata,
42 | aes(x=hincome, y=p, color=response)) +
43 | geom_line(linewidth = 2) +
44 | geom_point(size = 1.5, shape = 16, color = "black") +
45 | labs(x="Husband's Income", y= "Probability") +
46 | facet_wrap(~ children, labeller = label_both) +
47 | geom_ribbon(aes(ymin=p - se.p,
48 | ymax=p + se.p,
49 | fill = response), alpha = 0.3) +
50 | geom_textline(aes(label = response),
51 | hjust = -0.01, vjust=-0.5, size=5) +
52 | theme(legend.position = "none")
53 |
54 | # Plot the corresponding logits
55 | ggplot(plotdata,
56 | aes(x=hincome, y=logit, color=response)) +
57 | geom_line(linewidth = 2) +
58 | geom_point(size = 1.5, shape = 16, color = "black") +
59 | labs(x="Husband's Income", y= "Log Odds") +
60 | facet_wrap(~ children, labeller = label_both) +
61 | geom_ribbon(aes(ymin=logit - se.logit,
62 | ymax=logit + se.logit,
63 | fill = response), alpha = 0.3) +
64 | geom_textline(aes(label = response),
65 | hjust = -0.01, vjust=-0.5, size=5) +
66 | theme(legend.position = "none")
67 |
68 |
69 | # Predicted logit values for the dichotomies
70 |
71 | pred.dichot <- predict(wlf.nested, newdata = new,
72 | model = "dichotomies")
73 | str(pred.dichot)
74 | #pred.dichot
75 |
76 |
77 | plotlogit <- as.data.frame(pred.dichot)
78 |
79 |
80 | ggplot(plotlogit,
81 | aes(x=hincome, y=logit, color=response)) +
82 | geom_line(linewidth = 2) +
83 | geom_point(size = 1.5, shape = 16, color = "black") +
84 | labs(x="Husband's Income", y= "Log Odds") +
85 | facet_wrap(~ children, labeller = label_both) +
86 | geom_ribbon(aes(ymin=logit - se.logit,
87 | ymax=logit + se.logit,
88 | fill = response), alpha = 0.3) +
89 | geom_textline(aes(label = response),
90 | hjust = -0.01, vjust=-0.5, size=5) +
91 | theme(legend.position = "none")
92 |
93 | # plot the other way -- by dichotomy
94 | ggplot(plotlogit,
95 | aes(x=hincome, y=logit, color=children)) +
96 | geom_line(linewidth = 2) +
97 | geom_point(size = 1.5, shape = 16, color = "black") +
98 | labs(x="Husband's Income", y= "Log Odds") +
99 | facet_wrap(~ response, labeller = label_both) +
100 | geom_ribbon(aes(ymin=logit - se.logit,
101 | ymax=logit + se.logit,
102 | fill = children), alpha = 0.3) +
103 | geom_textline(aes(label = children),
104 | hjust = -0.01, vjust=-0.5, size=5) +
105 | theme(legend.position = "none")
106 |
107 | #' ## Do this for the alternative model
108 | #'
109 | wlf.nested.alt <- nestedLogit(partic ~ hincome + children,
110 | logits(full=dichotomy(nonfulltime=c("not.work", "parttime"), "fulltime"),
111 | part=dichotomy("not.work", "parttime")),
112 | data=Womenlf)
113 |
114 | pred.dichot.alt <- predict(wlf.nested.alt, newdata = new,
115 | model = "dichotomies")
116 | str(pred.dichot.alt)
117 |
118 | plotlogit.alt <- as.data.frame(pred.dichot.alt)
119 |
120 | ggplot(plotlogit.alt,
121 | aes(x=hincome, y=logit, color=response)) +
122 | geom_line(linewidth = 2) +
123 | geom_point(size = 1.5, shape = 16, color = "black") +
124 | labs(x="Husband's Income", y= "Log Odds") +
125 | facet_wrap(~ children, labeller = label_both) +
126 | geom_ribbon(aes(ymin=logit - se.logit,
127 | ymax=logit + se.logit,
128 | fill = response), alpha = 0.3) +
129 | geom_textline(aes(label = response),
130 | hjust = -0.01, vjust=-0.5, size=5) +
131 | theme(legend.position = "none")
132 |
133 | # plot the other way -- by dichotomy
134 | ggplot(plotlogit.alt,
135 | aes(x=hincome, y=logit, color=children)) +
136 | geom_line(linewidth = 2) +
137 | geom_point(size = 1.5, shape = 16, color = "black") +
138 | labs(x="Husband's Income", y= "Log Odds") +
139 | facet_wrap(~ response, labeller = label_both) +
140 | geom_ribbon(aes(ymin=logit - se.logit,
141 | ymax=logit + se.logit,
142 | fill = children), alpha = 0.3) +
143 | geom_textline(aes(label = children),
144 | hjust = -0.01, vjust=-0.5, size=5) +
145 | theme(legend.position = "none")
146 |
--------------------------------------------------------------------------------
/examples/wlf-nested-example.R:
--------------------------------------------------------------------------------
1 | #' ---
2 | #' title: Womenlf nested examples, largely for checking that things work
3 | #' ---
4 |
5 | #' This file generates errors, warnings, but errors are allowed here
6 | #'
7 |
8 |
9 | library(car)
10 | data(Womenlf, package = "carData")
11 |
12 | logits(work=dichotomy("not.work", c("parttime", "fulltime")),
13 | full=dichotomy("parttime", "fulltime"))
14 |
15 | as.matrix(logits(work=dichotomy("not.work", c("parttime", "fulltime")),
16 | full=dichotomy("parttime", "fulltime")))
17 |
18 | #' ## not properly nested:
19 | #'
20 | #+ error=TRUE
21 | logits(work=dichotomy("not.work", c("parttime", "fulltime")),
22 | full=dichotomy("not.work", "fulltime"))
23 |
24 | # OK
25 | logits(one=dichotomy(c("A", "B"), c("C", "D")),
26 | two=dichotomy("A", "B"),
27 | three=dichotomy("C", "D"))
28 |
29 | #' ## duplicate dichotomy
30 | #+ error=TRUE
31 | logits(one=dichotomy(c("A", "B"), c("C", "D")),
32 | two=dichotomy("A", "B"),
33 | three=dichotomy("A", "B"))
34 |
35 | #' ## incomplete
36 | #+ error=TRUE
37 | logits(one=dichotomy(c("A", "B"), c("C", "D")),
38 | two=dichotomy("A", "B"))
39 |
40 | # Arthritis treatment
41 | logits(better = dichotomy("None", c("Some", "Marked")),
42 | v.better = dichotomy("Some", "Marked"))
43 |
44 |
45 | m <- nestedLogit(partic ~ hincome + children,
46 | logits(work=dichotomy("not.work", c("parttime", "fulltime")),
47 | full=dichotomy("parttime", "fulltime")),
48 | data=Womenlf)
49 | m
50 | summary(m)
51 | Anova(m)
52 |
53 | m1 <- nestedLogit(partic ~ hincome + children,
54 | logits(work=dichotomy("not.work", c("parttime", "fulltime")),
55 | full=dichotomy("parttime", "fulltime")),
56 | contrasts=list(children=contr.sum),
57 | subset = 'region == "Ontario"',
58 | data=Womenlf)
59 | m1
60 |
61 | m2 <- nestedLogit(partic ~ log(hincome)*children,
62 | logits(work=dichotomy("not.work", c("parttime", "fulltime")),
63 | full=dichotomy("parttime", "fulltime")),
64 | data=Womenlf)
65 | m2
66 | summary(m2)
67 | Anova(m2)
68 |
69 | (new <- expand.grid(hincome=seq(1, 45, length=10), children=c("absent", "present")))
70 |
71 | (p <- predict(m2, newdata=new))
72 | rowSums(p)
73 | p2 <- predict(m2)
74 | all(abs(rowSums(p2) - 1) < .Machine$double.eps)
75 |
76 | plotdata <- cbind(new, p)
77 |
78 | # par(mfrow=c(1, 2))
79 | # plot(c(1, 45), 0:1, type="n", xlab="Husband's Income", ylab="Probability",
80 | # main="Children Absent")
81 | # with(plotdata, lines(spline(hincome[1:10], fulltime[1:10]), col="blue", lwd=2))
82 | # with(plotdata, lines(spline(hincome[1:10], parttime[1:10]), col="magenta", lwd=2))
83 | # with(plotdata, lines(spline(hincome[1:10], not.work[1:10]), col="darkcyan", lwd=2))
84 | # legend("topright", inset=.02, lwd=2, col=c("blue", "magenta", "darkcyan"),
85 | # legend=c("Full Time", "Part Time", "Not Working"))
86 | #
87 | # plot(c(1, 45), 0:1, type="n", xlab="Husband's Income", ylab="Probability",
88 | # main="Children Present")
89 | # with(plotdata, lines(spline(hincome[11:20], fulltime[11:20]), col="blue", lwd=2))
90 | # with(plotdata, lines(spline(hincome[11:20], parttime[11:20]), col="magenta", lwd=2))
91 | # with(plotdata, lines(spline(hincome[11:20], not.work[11:20]), col="darkcyan", lwd=2))
92 |
93 | continuationLogits(3)
94 | continuationLogits(c("low", "medium", "high", "very.high"))
95 | continuationLogits(c("gradeschool", "some highschool", "highschool grad",
96 | "some univ", "univ grad" ),
97 | names=c("some.highschool.or.more", "highschool.grad.or.more",
98 | "some.univ.or.more", "univ.grad"))
99 |
100 |
101 | #' ## check fitted probabilities
102 |
103 | p.m2.1 <- predict(m2$models[[1]], newdata=new, type="response")
104 | p.m2.2 <- predict(m2$models[[2]], newdata=new, type="response")
105 | pred.not.work <- 1 - p.m2.1
106 | all.equal(pred.not.work, p[, "not.work"])
107 | pred.parttime <- p.m2.1*(1 - p.m2.2 )
108 | all.equal(pred.parttime, p[, "parttime"])
109 | pred.fulltime <- p.m2.1*p.m2.2
110 | all.equal(pred.fulltime, p[, "fulltime"])
111 |
112 |
113 | # -----
114 | # alternative specifications
115 |
116 | library(nestedLogit)
117 | library(nnet)
118 | data(Womenlf, package="carData")
119 |
120 | m1 <- nestedLogit(partic ~ hincome + children,
121 | logits(work=dichotomy("not.work", working=c("parttime", "fulltime")),
122 | full=dichotomy("parttime", "fulltime")),
123 | data=Womenlf)
124 | summary(m1)
125 |
126 | m2 <- nestedLogit(partic ~ hincome + children,
127 | logits(full=dichotomy(nonfulltime=c("not.work", "parttime"), "fulltime"),
128 | part=dichotomy("not.work", "parttime")),
129 | data=Womenlf)
130 | summary(m2)
131 |
132 | m3 <- multinom(partic ~ hincome + children, data=Womenlf)
133 | summary(m3)
134 |
135 | par(mfcol=c(1, 2), mar=c(4, 4, 3, 1) + 0.1)
136 |
137 | plot(m1, "hincome", list(children="absent"),
138 | xlab="Husband's Income", legend=FALSE)
139 | plot(m1, "hincome", list(children="present"),
140 | xlab="Husband's Income")
141 |
142 | plot(m2, "hincome", list(children="absent"),
143 | xlab="Husband's Income", legend=FALSE)
144 | plot(m2, "hincome", list(children="present"),
145 | xlab="Husband's Income")
146 |
147 | new <- expand.grid(hincome=seq(0, 45, length=10),
148 | children=c("absent", "present"))
149 | new <- cbind(new, predict(m3, new, type='probs'))
150 | cols = palette()[2:4]
151 | for ( kids in c("absent", "present") ) {
152 | data <- subset(new, children == kids)
153 | matplot(data[, "hincome"], data[, c("not.work", "parttime", "fulltime")],
154 | type = "l", lwd=3, lty = 1:3, col = cols,
155 | xlab="Husband's Income",
156 | ylab='Fitted Probability',
157 | main = paste("Children", kids),
158 | cex.lab = 1.1)
159 | if (kids=="absent") {
160 | legend("topright", lty=1:3, lwd=3, col=cols, bty = "n",
161 | legend=c("not.work", "parttime", "fulltime"))
162 | }
163 | }
164 |
165 |
166 | fit1 <- predict(m1)
167 | fit2 <- predict(m2)
168 | fit3 <- predict(m3, type="probs")[, c("not.work", "parttime", "fulltime")]
169 | diag(cor(fit1, fit2))
170 | diag(cor(fit1, fit3))
171 | diag(cor(fit2, fit3))
172 |
173 | logLik(m1)
174 | logLik(m2)
175 | logLik(m3)
176 |
--------------------------------------------------------------------------------
/examples/wlf-nested-test.R:
--------------------------------------------------------------------------------
1 | #' ---
2 | #' title: test nested dichotomies
3 | #' ---
4 |
5 | library(nestedLogit)
6 | library(dplyr)
7 | data(Womenlf, package = "carData")
8 |
9 | #' ## Fit nested dichotomies 'by hand'
10 |
11 | Womenlf <- Womenlf |>
12 | mutate(partic = ordered(partic, levels = c("not.work", "parttime", "fulltime"))) |>
13 | mutate(work = ifelse(partic=="not.work", 0, 1)) |>
14 | mutate(full = case_when(
15 | work & partic == "fulltime" ~ 1,
16 | work & partic == "parttime" ~ 0)
17 | )
18 |
19 | wlf.work <- glm(work ~ hincome + children, family=binomial, data=Womenlf)
20 | wlf.full <- glm(full ~ hincome + children, family=binomial, data=Womenlf)
21 |
22 | #' ## Use nestedLogit()
23 |
24 | wlf.nested <- nestedLogit(partic ~ hincome + children,
25 | logits(work=dichotomy("not.work", c("parttime", "fulltime")),
26 | full=dichotomy("parttime", "fulltime")),
27 | data=Womenlf)
28 |
29 | #' ## Compare coefficients
30 | #'
31 | c.hand <- rbind(work = coef(wlf.work),
32 | full = coef(wlf.full))
33 |
34 | c.nest <- t(coef(wlf.nested))
35 |
36 | all.equal(c.hand, c.nest)
37 |
38 | #' ## Test predict()
39 | #'
40 | new <- expand.grid(hincome=seq(0, 45, length=10),
41 | children=c("absent", "present"))
42 |
43 | #' ## by hand
44 |
45 | #' predictions for the two submodels
46 | p.work <- predict(wlf.work, new, type='response')
47 | p.fulltime <- predict(wlf.full, new, type='response')
48 |
49 | #' calculate unconditional probs for the three response categories
50 |
51 | pred.hand <- data.frame(
52 | not.work = 1 - p.work,
53 | parttime = p.work * (1 - p.fulltime),
54 | fulltime = p.work * p.fulltime
55 | )
56 |
57 | #' ## `predict.nested()`
58 | pred.nested <- predict(wlf.nested, new)
59 |
60 | #' ## Compare predictions
61 | #'
62 |
63 | all.equal(pred.hand, as.data.frame(pred.nested),
64 | check.attributes = FALSE)
65 |
66 |
67 |
68 |
--------------------------------------------------------------------------------
/experimental/augment.nested-test.R:
--------------------------------------------------------------------------------
1 | #' ---
2 | #' title: test augment methods
3 | #' ---
4 | #'
5 |
6 | library(nestedLogit)
7 | library(dplyr)
8 | library(broom)
9 | library(ggplot2)
10 | data(Womenlf, package = "carData")
11 |
12 | wlf.nested <- nestedLogit(partic ~ hincome + children,
13 | logits(work=dichotomy("not.work", c("parttime", "fulltime")),
14 | full=dichotomy("parttime", "fulltime")),
15 | data=Womenlf)
16 |
17 | # what does broom return?
18 | broom::augment(wlf.nested$models[[1]]) |> head()
19 | broom::augment(wlf.nested$models[[1]], se_fit = TRUE) |> head()
20 |
21 | broom::augment(wlf.nested$models[[1]], type.predict = "response") |> head()
22 | broom::augment(wlf.nested$models[[1]], type.predict = "response", se_fit = TRUE) |> head()
23 |
24 | predict(wlf.nested) |> head()
25 |
26 |
27 | #' try getting augment directly on each submodel
28 | wlf.augmented <- lapply(wlf.nested$models, broom::augment)
29 | names(wlf.augmented)
30 |
31 | # try our function
32 | wlf.aug <- augment.nested(wlf.nested)
33 |
34 | names(wlf.aug)
35 | # why don't we get the other variables computed by broom::augment.glm?
36 | names(wlf.augmented[[1]])
37 |
38 | wlf.aug.probs <- augment(wlf.nested, type.predict = "probs")
39 |
40 | # try using new data
41 | new <- expand.grid(hincome = seq(0, 40, by = 5),
42 | children = c("absent", "present"))
43 |
44 | wlf.augmented.new <- lapply(wlf.nested$models, broom::augment, se_fit=TRUE, newdata=new)
45 | names(wlf.augmented.new[[1]])
46 |
47 | wlf.aug.new <- augment(wlf.nested, newdata = new)
48 |
49 |
50 | #' Make the plot
51 | wlf.aug <- wlf.aug |>
52 | mutate(response = ordered(response, levels=c("work", "full")))
53 |
54 | gg <- ggplot(wlf.aug,
55 | aes(x=hincome, y=.fitted, color=children)) +
56 | geom_line(linewidth = 3) +
57 | geom_point(size = 1.5, shape = 16, color = "black") +
58 | scale_color_discrete() +
59 | labs(x="Husband's Income", y= "Log Odds") +
60 | facet_wrap(~ response, labeller = label_both) +
61 | theme_bw(base_size = 14) +
62 | theme(legend.position = c(.35, .85))
63 |
64 | #' add error bars
65 | gg + geom_errorbar(aes(ymin=.fitted-.se.fit, ymax=.fitted+.se.fit),
66 | colour="black", width=.1)
67 |
68 | #' better: use a ribbon
69 | gg + geom_ribbon(aes(ymin=.fitted-.se.fit,
70 | ymax=.fitted+.se.fit,
71 | fill = children), alpha = 0.4)
72 |
73 | #' label the lines directly
74 | library(geomtextpath)
75 | gg +
76 | geom_ribbon(aes(ymin=.fitted-.se.fit,
77 | ymax=.fitted+.se.fit,
78 | fill = children), alpha = 0.4) +
79 | geom_textline(aes(label = children), vjust=-0.5, size=6) +
80 | theme(legend.position = "none")
81 |
82 |
83 |
--------------------------------------------------------------------------------
/experimental/augment.nested.R:
--------------------------------------------------------------------------------
1 | #' Augment data with information from a nested object
2 | #'
3 | #' Augment accepts a model object and a dataset and adds information about each observation in the dataset,
4 | #' typically to assist in preparing plots of the model. The general scheme is to append columns to the
5 | #' data representing predicted values and other quantities (residuals, standard errors, ...) where available.
6 | #'
7 | #' A complication for nested dichotomies models is that there are at least two types of predicted values of
8 | #' interest: the fitted \emph{logits} for the \eqn{m-1} dichotomies and the fitted \emph{probabilities} of the \eqn{m}
9 | #' response categories.
10 | #'
11 | #' @param x an object of class \code{"nestedLogit"} produced by \code{\link{nestedLogit}}.
12 | #' @param data the data set used to fit the model. If not supplied, this is extracted from the model object.
13 | #' @param newdata a prediction data set containing values of all predictors used in the model
14 | #' @param type.predict a character string, either \code{"link"} to calculate predicted values on the logit scale
15 | #' for each of the dichotomies, or \code{"probs"} to calculate fitted probabilities
16 | #' @param se_fit Logical. For predicted logits, whether to return the standard errors.
17 | #' @param to_long Logical. For predicted probabilities, whether to convert these to long format.
18 | #' @param ... Other parameters passed to predict methods
19 | #'
20 | #' @return Returns a \code{"tibble"} containing the values of the response variable, predictors and estimated
21 | #' values from the model.
22 | #' For \code{type.predict = "link"}, the dichotomies in the model are given as \code{response} and
23 | #' the predicted log odds is given as \code{.fitted}, with standard error \code{.se.fit}. The number
24 | #' of observations is the sum of those not coded \code{NA} across all dichotomies.
25 | #' For \code{type.predict = "probs"}, when \code{to_long=FALSE}, predicted probabilities appear as
26 | #' code{m} columns corresponding to the levels of the response.
27 | #' @importFrom generics augment
28 | #' @importFrom broom augment.glm
29 | #' @importFrom dplyr bind_rows bind_cols
30 | #' @importFrom tidyr pivot_longer
31 | #' @export
32 | #'
33 | #' @examples
34 | augment.nested <- function(x,
35 | data = NULL,
36 | newdata = NULL,
37 | type.predict = c("link", "probs"),
38 | se_fit = TRUE, # it is FALSE in augment.glm()
39 | to_long = TRUE,
40 | ...)
41 | {
42 | if (is.null(data))
43 | data <- model.frame(models(x)[[1L]])
44 | if (missing(newdata))
45 | newdata <- models(x)[[1L]]$data
46 |
47 | type.predict <- match.arg(type.predict)
48 |
49 | if (type.predict == "link") {
50 |
51 | nms <- names(models(x))
52 | result <- lapply(models(x), broom::augment,
53 | data=data,
54 | newdata=newdata,
55 | type.predict = type.predict,
56 | se_fit = se_fit,
57 | ... )
58 |
59 | cls <- class(result[[1L]])
60 | for (i in seq_along(models(x))) {
61 | result[[i]] <- cbind(response = nms[i], result[[i]])
62 | }
63 | result <- dplyr::bind_rows(result) |>
64 | select(-starts_with("..")) # remove ..y
65 | class(result) <- cls
66 | }
67 |
68 | else { #type.predict = "probs", as in multinom()
69 | result <- predict(x, newdata = newdata, ...)
70 | resp.names <- colnames(result)
71 | result <- dplyr::bind_cols(newdata, result) |>
72 | as_tibble()
73 | # if("..y" %in% colnames(result)) result <- select(result, -c("..y"))
74 |
75 | if(isTRUE(to_long)) {
76 | result <- result |>
77 | tidyr::pivot_longer(cols = all_of({{resp.names}}),
78 | names_to = "response.level",
79 | values_to = "prob")
80 | }
81 | }
82 |
83 | result
84 |
85 | }
86 |
87 |
88 |
89 |
--------------------------------------------------------------------------------
/experimental/models.R:
--------------------------------------------------------------------------------
1 | #' Extract glm() objects from a nestedLogit object
2 | #'
3 | #' \code{models} is used to extract \code{"glm"} objects representing binary logit
4 | #' models from a \code{"nestedLogit"} object.
5 | #'
6 | #' @export
7 | models <- function(model, select, as.list=FALSE){
8 | UseMethod("models")
9 | }
10 |
11 | #' @export
12 | models.nestedLogit <- function(model, select, as.list=FALSE){
13 | if (missing(select)) return(model$models)
14 | if (is.numeric(select)){
15 | model.nos <- seq(along=model$models)
16 | which <- !(select %in% model.nos)
17 | } else {
18 | model.names <- names(model$models)
19 | which <- !(select %in% model.names)
20 | }
21 | if (any(which)){
22 | stop("the following model", if (sum(which) > 1) "s are " else " is ",
23 | "not available:\n", paste(select[which], collapse=", "))
24 | }
25 | result <- model$models[select]
26 | if (length(result) > 1 || as.list) return(result) else return(result[[1]])
27 | }
28 |
29 | #' @param model a \code{"nestedLogit"} model.
30 | #' @param select a numeric or character vector giving the number(s) or names(s)
31 | #' of one or more
32 | #' binary logit models to be extracted from \code{model}; if absent, a list of
33 | #' all of the binary logits models in \code{model} is returned.
34 | #' @param as.list if \code{TRUE} (the default is \code{FALSE}) and one binary logit
35 | #' model is selected, return the \code{"glm"} object in a one-element named list;
36 | #' otherwise a single model is returned directly as a \code{"glm"} object;
37 | #' when more than one binary
38 | #' logit model is selected, the corresponding \code{"glm"} objects are \emph{always}
39 | #' returned as a named list.
40 |
41 | if (FALSE){
42 | library(nestedLogit)
43 | library(car)
44 | # example("nestedLogit")
45 |
46 | m <- nestedLogit(partic ~ hincome + children,
47 | dichotomies = logits(work=dichotomy("not.work", working=c("parttime", "fulltime")),
48 | full=dichotomy("parttime", "fulltime")),
49 | data=Womenlf)
50 |
51 | models(m)
52 | models(m, 2:1)
53 | models(m, 1)
54 | models(m, 1, as.list=TRUE)
55 | models(m, c("work", "full"))
56 | models(m, "full")
57 |
58 | models(m, "foo") # error
59 | models(m, 3:4) # error
60 |
61 | # plot one model -- gives the 'regression quartet for a glm()
62 | op <- par(mfrow = c(2,2))
63 | plot(models(m, 1))
64 | par(op)
65 | }
66 |
--------------------------------------------------------------------------------
/experimental/pkgdown-reference.yml.txt:
--------------------------------------------------------------------------------
1 | reference:
2 |
3 | - title: Fitting
4 | desc: Specifying and fitting nestedLogit models
5 | contents:
6 | - nestedLogit
7 | - dichotomy
8 | - logits
9 | - continuationLogits
10 |
11 | - title: Methods
12 | desc: Standard model methods
13 | contents:
14 | - coef
15 | - summary
16 | - update
17 | - vcov
18 | - predict
19 | - glance
20 | - tidy
21 | - plot
22 | - models
23 |
24 | - title: Hypothesis-testing
25 | desc: Testing hypotheses for nestedLogit models
26 | contents:
27 | - anova
28 | - Anova
29 | - linearHypothesis
30 | - logLike
31 |
32 |
33 | - title: Data
34 | desc: Some small data sets used in examples
35 | contents:
36 | - GSS
37 | - HealthInsurance
38 |
39 |
--------------------------------------------------------------------------------
/experimental/response-variances.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/experimental/response-variances.pdf
--------------------------------------------------------------------------------
/experimental/test-SEs.R:
--------------------------------------------------------------------------------
1 | # this will eventually became a package test
2 |
3 | library(nestedLogit)
4 | source("./experimental/predict-with-se.R")
5 | source("./experimental/plot.nested--with-conf-limits.R")
6 |
7 | data(Womenlf, package="carData")
8 |
9 | comparisons <- logits(work=dichotomy("not.work", c("parttime", "fulltime")),
10 | full=dichotomy("parttime", "fulltime"))
11 |
12 | wlf.nested <- nestedLogit(partic ~ hincome + children,
13 | dichotomies = comparisons,
14 | data=Womenlf)
15 | new <- expand.grid(hincome=seq(0, 45, length=4),
16 | children=c("absent", "present"))
17 |
18 | pred.nested <- predict(wlf.nested, new)
19 |
20 | m1 <- models(wlf.nested, "work")
21 | m2 <- models(wlf.nested, "full")
22 |
23 | pr1 <- predict(m1, newdata=new, type="response", se.fit=TRUE)
24 | p1 <- pr1$fit
25 | v1 <- (pr1$se.fit)^2
26 |
27 | pr2 <- predict(m2, newdata=new, type="response", se.fit=TRUE)
28 | p2 <- pr2$fit
29 | v2 <- (pr2$se.fit)^2
30 |
31 | p.nw <- 1 - p1
32 | p.pt <- p1*(1 - p2)
33 | p.ft <- p1*p2
34 | p.nw + p.pt + p.ft
35 |
36 | # check that category probabilities are computed correctly
37 | all.equal(cbind(p.nw, p.pt, p.ft), as.matrix(pred.nested$p),
38 | check.attributes=FALSE)
39 |
40 | se.p.nw <- sqrt(v1)
41 | se.p.pt <- sqrt((1 - p2)^2*v1 + p1^2*v2)
42 | se.p.ft <- sqrt(p2^2*v1 + p1^2*v2)
43 |
44 | # check that SEs of category probabilities are comouted correctly
45 | all.equal(cbind(se.p.nw, se.p.pt, se.p.ft), as.matrix(pred.nested$se.p),
46 | check.attributes=FALSE)
47 |
48 | ## ---- continuation logits exammple
49 |
50 | m.gss <- nestedLogit(degree ~ parentdeg + year,
51 | continuationLogits(c("l.t.highschool", "highschool",
52 | "college", "graduate")),
53 | data=GSS)
54 |
55 | new <- expand.grid(parentdeg=c("l.t.highschool", "highschool",
56 | "college", "graduate"),
57 | year=seq(1972, 2016, length=5))
58 | pred.gss <- predict(m.gss, new)
59 |
60 | GSS$y1 <- with(GSS, ifelse(degree == "l.t.highschool", 0, 1))
61 | GSS$y2 <- with(GSS, ifelse(y1 == 0, NA,
62 | ifelse(degree == "highschool", 0, 1)))
63 | GSS$y3 <- with(GSS, ifelse(degree == "college", 0,
64 | ifelse(degree == "graduate", 1, NA)))
65 | xtabs(~ degree + y1, data=GSS)
66 | xtabs(~ degree + y2, data=GSS)
67 | xtabs(~ degree + y3, data=GSS)
68 |
69 | m1 <- glm(y1 ~ parentdeg + year, data=GSS, family=binomial)
70 | m2 <- glm(y2 ~ parentdeg + year, data=GSS, family=binomial)
71 | m3 <- glm(y3 ~ parentdeg + year, data=GSS, family=binomial)
72 |
73 | pr1 <- predict(m1, newdata=new, type="response", se.fit=TRUE)
74 | p1 <- pr1$fit
75 | v1 <- (pr1$se.fit)^2
76 |
77 | pr2 <- predict(m2, newdata=new, type="response", se.fit=TRUE)
78 | p2 <- pr2$fit
79 | v2 <- (pr2$se.fit)^2
80 |
81 | pr3 <- predict(m3, newdata=new, type="response", se.fit=TRUE)
82 | p3 <- pr3$fit
83 | v3 <- (pr3$se.fit)^2
84 |
85 | p.a <- 1 - p1
86 | p.b <- p1*(1 - p2)
87 | p.c <- p1*p2*(1 - p3)
88 | p.d <- p1*p2*p3
89 |
90 | all.equal(cbind(p.a, p.b, p.c, p.d), as.matrix(pred.gss$p),
91 | check.attributes=FALSE)
92 |
93 | se.p.a <- sqrt(v1)
94 | se.p.b <- sqrt((1 - p2)^2*v1 + p1^2*v2)
95 | se.p.c <- sqrt((p2*(1 - p3))^2*v1 + (p1*(1 - p3))^2*v2 + (p1*p2)^2*v3)
96 | se.p.d <- sqrt((p2*p3)^2*v1 + (p1*p3)^2*v2 + (p1*p2)^2*v3)
97 |
98 | all.equal(cbind(se.p.a, se.p.b, se.p.c, se.p.d), as.matrix(pred.gss$se.p),
99 | check.attributes=FALSE)
100 |
101 |
102 | # ------------- health-insurance example --------
103 |
104 | lbinary <- logits(AB_CD = dichotomy(c("A", "B"), c("C", "D")),
105 | A_B = dichotomy("A", "B"),
106 | C_D = dichotomy("C", "D"))
107 |
108 | health.nested <- nestedLogit(product4 ~ age + gender * household + position_level,
109 | dichotomies = lbinary, data = HealthInsurance)
110 |
111 | HealthInsurance$y1 <- with(HealthInsurance, ifelse(product4 %in% c("A", "B"),0, 1))
112 | HealthInsurance$y2 <- with(HealthInsurance, ifelse(product4 == "A", 0,
113 | ifelse(product4 == "B", 1, NA)))
114 | HealthInsurance$y3 <- with(HealthInsurance, ifelse(product4 == "C", 0,
115 | ifelse(product4 == "D", 1, NA)))
116 | xtabs(~ product4 + y1, data=HealthInsurance)
117 | xtabs(~ product4 + y2, data=HealthInsurance)
118 | xtabs(~ product4 + y3, data=HealthInsurance)
119 |
120 | m1 <- glm(y1 ~ age + gender * household + position_level,
121 | data=HealthInsurance, family=binomial)
122 | m2 <- glm(y2 ~ age + gender * household + position_level,
123 | data=HealthInsurance, family=binomial)
124 | m3 <- glm(y3 ~ age + gender * household + position_level,
125 | data=HealthInsurance, family=binomial)
126 |
127 | new <- expand.grid(age=seq(20, 70, length=3),
128 | gender = c("Female", "Male"),
129 | household = mean(HealthInsurance$household),
130 | position_level = mean(HealthInsurance$position_level)
131 | )
132 |
133 | pr1 <- predict(m1, newdata=new, type="response", se.fit=TRUE)
134 | p1 <- pr1$fit
135 | v1 <- (pr1$se.fit)^2
136 |
137 | pr2 <- predict(m2, newdata=new, type="response", se.fit=TRUE)
138 | p2 <- pr2$fit
139 | v2 <- (pr2$se.fit)^2
140 |
141 | pr3 <- predict(m3, newdata=new, type="response", se.fit=TRUE)
142 | p3 <- pr3$fit
143 | v3 <- (pr3$se.fit)^2
144 |
145 | pred.health <- predict(health.nested, newdata=new)
146 |
147 | p.a <- (1 - p1)*(1 - p2)
148 | p.b <- (1 - p1)*p2
149 | p.c <- p1*(1 - p3)
150 | p.d <- p1*p3
151 |
152 | all.equal(cbind(p.a, p.b, p.c, p.d), as.matrix(pred.health$p),
153 | check.attributes=FALSE)
154 |
155 | se.p.a <- sqrt((1 - p2)^2*v1 + (1 - p1)^2*v2)
156 | se.p.b <- sqrt(p2^2*v1 + (1 - p1)^2*v2)
157 | se.p.c <- sqrt((1 - p3)^2*v1 + p1^2*v3)
158 | se.p.d <- sqrt(p3^2*v1 + p1^2*v3)
159 |
160 | all.equal(cbind(se.p.a, se.p.b, se.p.c, se.p.d), as.matrix(pred.health$se.p),
161 | check.attributes=FALSE)
162 |
--------------------------------------------------------------------------------
/inst/WORDLIST:
--------------------------------------------------------------------------------
1 | Analytics
2 | anova
3 | Anova
4 | aspx
5 | boldsymbol
6 | carData
7 | cdots
8 | continuationLogits
9 | CRC
10 | dichotomize
11 | df
12 | doi
13 | Fienberg
14 | frac
15 | fulltime
16 | ggplot
17 | ggeffects
18 | gradeschool
19 | GSS
20 | https
21 | ij
22 | im
23 | jk
24 | ldots
25 | Lifecycle
26 | McNulty
27 | newdata
28 | NORC
29 | norc
30 | nnet
31 | Weisberg
32 | highschool
33 | hincome
34 | linearHypothesis
35 | mathbf
36 | mathcal
37 | nd
38 | ne
39 | operatorname
40 | partic
41 | parttime
42 | polytomy
43 | predictNestedLogit
44 | recoding
45 | repo
46 | summarising
47 | tibbles
48 | th
49 | vec
50 | widehat
51 | womens
52 | Womenlf
53 | www
54 | Monette
55 | subseteq
56 | buglet
57 | customizable
58 |
--------------------------------------------------------------------------------
/man/Effect.nestedLogit.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/Effect.nestedLogit.R
3 | \name{Effect.nestedLogit}
4 | \alias{Effect.nestedLogit}
5 | \title{Effect Displays for Nested Logit Models}
6 | \usage{
7 | \method{Effect}{nestedLogit}(
8 | focal.predictors,
9 | mod,
10 | confidence.level = 0.95,
11 | fixed.predictors = NULL,
12 | ...
13 | )
14 | }
15 | \arguments{
16 | \item{focal.predictors}{a character vector of the names of one or more of
17 | the predictors in the model, for which the effect display should be computed.}
18 |
19 | \item{mod}{a \code{"nestedLogit"} model object.}
20 |
21 | \item{confidence.level}{for point-wise confidence bands around the effects
22 | (the default is \code{0.95}).}
23 |
24 | \item{fixed.predictors}{controls the values at which other predictors are fixed;
25 | see \code{\link[effects]{Effect}} for details; if \code{NULL} (the default),
26 | numeric predictors are set to their means, factors to their distribution in the data.}
27 |
28 | \item{...}{optional arguments to be passed to the \code{\link[effects]{Effect}} method for
29 | binary logit models (fit by the \code{\link{glm}} function).}
30 | }
31 | \value{
32 | an object of class \code{"effpoly"} (see \code{\link[effects]{Effect}}).
33 | }
34 | \description{
35 | Computes effects (in the sense of the \pkg{effects} package---see, in
36 | particular, \code{\link[effects]{Effect}})---for \code{"nestedLogit"} models, which then
37 | can be used with other functions in the \pkg{effects} package, for example,
38 | \code{\link[effects]{predictorEffects}} and to produce effect plots.
39 | }
40 | \examples{
41 | data("Womenlf", package = "carData")
42 | comparisons <- logits(work=dichotomy("not.work",
43 | working=c("parttime", "fulltime")),
44 | full=dichotomy("parttime", "fulltime"))
45 | m <- nestedLogit(partic ~ hincome + children,
46 | dichotomies = comparisons,
47 | data=Womenlf)
48 | peff.women <- effects::predictorEffects(m)
49 | plot(peff.women)
50 | plot(peff.women, axes=list(y=list(style="stacked")))
51 | summary(peff.women)
52 |
53 | dichots <- logits(AB_CD = dichotomy(c("A", "B"), c("C", "D")),
54 | A_B = dichotomy("A", "B"),
55 | C_D = dichotomy("C", "D"))
56 | m.health <- nestedLogit(product4 ~ age + gender*household + position_level,
57 | dichotomies = dichots, data = HealthInsurance)
58 | eff.gen.hh <- effects::Effect(c("gender", "household"), m.health,
59 | xlevels=list(household=0:7))
60 | eff.gen.hh
61 | plot(eff.gen.hh, axes=list(x=list(rug=FALSE)))
62 | plot(eff.gen.hh, axes=list(x=list(rug=FALSE),
63 | y=list(style="stacked")))
64 | }
65 | \references{
66 | John Fox and Sanford Weisberg (2019). \emph{An R Companion to Applied Regression},
67 | 3rd Edition. Sage, Thousand Oaks, CA.
68 |
69 | John Fox, Sanford Weisberg (2018). Visualizing Fit and Lack of Fit in Complex
70 | Regression Models with Predictor Effect Plots and Partial Residuals.
71 | \emph{Journal of Statistical Software}, 87(9), 1-27.
72 | }
73 | \seealso{
74 | \code{\link[effects]{Effect}}, \code{\link[effects]{plot.effpoly}},
75 | \code{\link[effects]{predictorEffects}}
76 | }
77 | \author{
78 | John Fox
79 | }
80 | \keyword{regression}
81 |
--------------------------------------------------------------------------------
/man/GSS.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/GSS.R
3 | \docType{data}
4 | \name{GSS}
5 | \alias{GSS}
6 | \title{Data From the U.S. General Social Survey 1972-2016}
7 | \format{
8 | A data frame with 44091 rows and 3 columns.
9 | \describe{
10 | \item{parentdeg}{A factor representing parents' attained level of education
11 | (highest "degree" obtained), recording
12 | the higher of mother's and father's education, with levels \code{"l.t.highschool"},
13 | \code{"highschool"}, \code{"college"}, and \code{"graduate"}.}
14 | \item{degree}{The respondent's level of education, a factor with the same levels
15 | as \code{parentdeg}.}
16 | \item{year}{The year of the survey, between \code{1972} and
17 | \code{2016}.}
18 | }
19 | }
20 | \source{
21 | General Social Survey, NORC, The University of Chicago
22 | https://www.norc.org/Research/Projects/Pages/general-social-survey.aspx.
23 | }
24 | \usage{
25 | data("GSS", package = "nestedLogit")
26 | }
27 | \description{
28 | This data set is drawn from the U.S. General Social Survey (GSS) for years
29 | between 1972 and 2016.
30 | }
31 | \examples{
32 | round(100*with(GSS, prop.table(table(degree, parentdeg), 2)))
33 | m.GSS <- nestedLogit(degree ~ parentdeg*year,
34 | continuationLogits(c("l.t.highschool", "highschool",
35 | "college", "graduate")),
36 | data=GSS)
37 | car::Anova(m.GSS)
38 | summary(m.GSS)
39 | }
40 | \seealso{
41 | \code{\link{nestedLogit}}.
42 | }
43 | \keyword{datasets}
44 |
--------------------------------------------------------------------------------
/man/HealthInsurance.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/HealthInsurance.R
3 | \docType{data}
4 | \name{HealthInsurance}
5 | \alias{HealthInsurance}
6 | \title{Choice of Health Insurance Product}
7 | \format{
8 | A data frame with 1448 rows and 7 columns.
9 | \describe{
10 | \item{product}{Choice among three products, a factor with levels \code{"A"}, \code{"B"},
11 | and \code{"C"}.}
12 | \item{product4}{Choice among four products, a factor with levels \code{"A"}, \code{"B"},
13 | \code{"C"}, and \code{"D"}.}
14 | \item{age}{The age of the individual, in years.}
15 | \item{household}{The number of people living with the individual in the
16 | same household.}
17 | \item{position_level}{Position level in the company at the time the choice was made,
18 | where 1 is is the lowest level and 5 is the highest, a numeric vector.}
19 | \item{gender}{The gender of the individual, a factor with levels \code{"Female"}
20 | and \code{"Male"}.}
21 | \item{absent}{The number of days the individual was absent from work in the year
22 | prior to the choice,}
23 | }
24 | }
25 | \source{
26 | Originally taken from McNulty, K. (2022).
27 | \emph{Handbook of Regression Modeling in People Analytics},
28 | \url{https://peopleanalytics-regression-book.org/data/health_insurance.csv}.
29 | }
30 | \usage{
31 | data("HealthInsurance", package = "nestedLogit")
32 | }
33 | \description{
34 | A company recently introduced a new health insurance provider for
35 | its employees. At the beginning of the year the employees had to choose one of
36 | three (or four) different health plan products from this provider to best suit
37 | their needs.
38 |
39 | This dataset was modified from its original source (McNulty, 2022) for the
40 | present purposes by adding a fourth choice, sampled randomly from the original three.
41 | }
42 | \examples{
43 | lbinary <- logits(AB_CD = dichotomy(c("A", "B"), c("C", "D")),
44 | A_B = dichotomy("A", "B"),
45 | C_D = dichotomy("C", "D"))
46 | as.matrix(lbinary)
47 | health.nested <- nestedLogit(product4 ~ age + gender * household + position_level,
48 | dichotomies = lbinary, data = HealthInsurance)
49 | car::Anova(health.nested)
50 | coef(health.nested)
51 | }
52 | \seealso{
53 | \code{\link{nestedLogit}}.
54 | }
55 | \keyword{datasets}
56 |
--------------------------------------------------------------------------------
/man/as.data.frame.predictNestedLogit.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/as.data.frame.predict.R
3 | \name{as.data.frame.predictNestedLogit}
4 | \alias{as.data.frame.predictNestedLogit}
5 | \title{Convert a Predicted Objects to a data.frame}
6 | \usage{
7 | \method{as.data.frame}{predictNestedLogit}(x, row.names = NULL, optional = FALSE, ...)
8 | }
9 | \arguments{
10 | \item{x}{a \code{"predictNestedLogit"} object}
11 |
12 | \item{row.names}{row.names for result (for conformity with generic; not currently used)}
13 |
14 | \item{optional}{logical. If TRUE, setting row names and converting column names
15 | (to syntactic names: see \code{\link[base]{make.names}} is optional}
16 |
17 | \item{...}{other arguments (unused)}
18 | }
19 | \value{
20 | \itemize{
21 | \item For \code{predict(\dots, model="nested")} (the default), returns
22 | a data frame containing the values of predictors along with the columns
23 | \code{response}, \code{p}, \code{se.p}, \code{logit}, \code{se.logit}.
24 | \item For \code{predict(\dots, model="dichotomies")}, returns
25 | a data frame containing the values of predictors along with the columns
26 | \code{response}, \code{logit}, and \code{se.logit}.
27 | }
28 | }
29 | \description{
30 | These functions provide simple ways to convert the results of \code{\link{predict.nestedLogit}}
31 | to a data frame in a consistent format for plotting and other actions.
32 | }
33 | \examples{
34 | data("Womenlf", package = "carData")
35 | comparisons <- logits(work=dichotomy("not.work", c("parttime", "fulltime")),
36 | full=dichotomy("parttime", "fulltime"))
37 |
38 | wlf.nested <- nestedLogit(partic ~ hincome + children,
39 | dichotomies = comparisons,
40 | data=Womenlf)
41 | # get predicted values for a grid of `hincome` and `children`
42 | new <- expand.grid(hincome=seq(0, 45, length=10),
43 | children=c("absent", "present"))
44 |
45 | pred.nested <- predict(wlf.nested, new)
46 | plotdata <- as.data.frame(pred.nested)
47 | str(plotdata)
48 |
49 | # Predicted logit values for the dichotomies
50 | pred.dichot <- predict(wlf.nested, new, model = "dichotomies")
51 | plotlogit <- as.data.frame(pred.dichot)
52 | str(plotlogit)
53 | }
54 |
--------------------------------------------------------------------------------
/man/broomMethods.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/broomMethods.R
3 | \name{broomMethods}
4 | \alias{broomMethods}
5 | \alias{glance.nestedLogit}
6 | \alias{tidy.nestedLogit}
7 | \title{Broom Related Methods}
8 | \usage{
9 | \method{glance}{nestedLogit}(x, ...)
10 |
11 | \method{tidy}{nestedLogit}(x, ...)
12 | }
13 | \arguments{
14 | \item{x}{an object of class \code{"nestedLogit"}.}
15 |
16 | \item{\dots}{arguments to be passed down.}
17 | }
18 | \value{
19 | \itemize{
20 | \item \code{glance} returns a \code{tibble} containing one row of fit statistics for each dichotomy,
21 | labeled \code{response}. See \code{\link[broom]{glance}} for details.
22 | \item \code{tidy} returns a \code{tibble} containing coefficient estimates and test statistics for
23 | the combinations of \code{response} and \code{term}. See \code{\link[broom]{tidy}} for details.
24 | }
25 | }
26 | \description{
27 | These functions give compact summaries of a \code{"nestedLogit"} object
28 | \describe{
29 | \item{\code{glance}}{Construct a single row summaries for the dichotomies \code{"nestedLogit"} model.}
30 | \item{\code{tidy}}{Summarizes the terms in \code{"nestedLogit"} model.}
31 | }
32 | }
33 | \examples{
34 | data("Womenlf", package = "carData")
35 | m <- nestedLogit(partic ~ hincome + children,
36 | dichotomies = logits(work=dichotomy("not.work",
37 | working=c("parttime", "fulltime")),
38 | full=dichotomy("parttime", "fulltime")),
39 | data=Womenlf)
40 |
41 | # one-line summaries
42 | broom::glance(m)
43 | # coefficients and tests
44 | broom::tidy(m)
45 |
46 | }
47 | \seealso{
48 | \code{\link{nestedMethods}}, \code{\link[broom]{glance}}, \code{\link[broom]{tidy}}
49 | }
50 |
--------------------------------------------------------------------------------
/man/figures/README-wlf-plot-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/man/figures/README-wlf-plot-1.png
--------------------------------------------------------------------------------
/man/figures/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/man/figures/logo.png
--------------------------------------------------------------------------------
/man/models.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/models.R
3 | \name{models}
4 | \alias{models}
5 | \alias{models.nestedLogit}
6 | \title{Extract Binary Logit Models from a \code{nestedLogit} Object}
7 | \usage{
8 | models(model, select, as.list = FALSE)
9 |
10 | \method{models}{nestedLogit}(model, select, as.list = FALSE)
11 | }
12 | \arguments{
13 | \item{model}{a \code{"nestedLogit"} model.}
14 |
15 | \item{select}{a numeric or character vector giving the number(s) or names(s)
16 | of one or more
17 | binary logit models to be extracted from \code{model}; if absent, a list of
18 | all of the binary logits models in \code{model} is returned.}
19 |
20 | \item{as.list}{if \code{TRUE} (the default is \code{FALSE}) and one binary logit
21 | model is selected, return the \code{"glm"} object in a one-element named list;
22 | otherwise a single model is returned directly as a \code{"glm"} object;
23 | when more than one binary
24 | logit model is selected, the corresponding \code{"glm"} objects are \emph{always}
25 | returned as a named list.}
26 | }
27 | \value{
28 | \code{model} returns either a single \code{"glm"} object (see \code{\link{glm}}) or a
29 | list of \code{"glm"} objects, each representing a binary logit model.
30 | }
31 | \description{
32 | \code{models} is used to extract \code{"glm"} objects representing binary logit
33 | models from a \code{"nestedLogit"} object.
34 | }
35 | \examples{
36 | data("Womenlf", package = "carData")
37 | comparisons <- logits(work=dichotomy("not.work",
38 | working=c("parttime", "fulltime")),
39 | full=dichotomy("parttime", "fulltime"))
40 | m <- nestedLogit(partic ~ hincome + children,
41 | dichotomies = comparisons,
42 | data=Womenlf)
43 |
44 | # extract a binomial logit model
45 | models(m, "work")
46 | # use that to plot residuals
47 | plot(density(residuals(models(m, "work"))))
48 | }
49 |
--------------------------------------------------------------------------------
/man/nestedHypotheses.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/nestedHypotheses.R
3 | \name{nestedHypotheses}
4 | \alias{nestedHypotheses}
5 | \alias{Anova.nestedLogit}
6 | \alias{print.Anova.nestedLogit}
7 | \alias{anova.nestedLogit}
8 | \alias{print.anova.nestedLogit}
9 | \alias{logLik.nestedLogit}
10 | \alias{linearHypothesis.nestedLogit}
11 | \title{Hypothesis-Testing and Related Methods for \code{"nestedLogit"} Objects}
12 | \usage{
13 | \method{Anova}{nestedLogit}(mod, ...)
14 |
15 | \method{print}{Anova.nestedLogit}(x, ...)
16 |
17 | \method{linearHypothesis}{nestedLogit}(model, ...)
18 |
19 | \method{anova}{nestedLogit}(object, object2, ...)
20 |
21 | \method{print}{anova.nestedLogit}(x, ...)
22 |
23 | \method{logLik}{nestedLogit}(object, ...)
24 | }
25 | \arguments{
26 | \item{\dots}{arguments to be passed down. In the case of \code{linearHypothesis},
27 | the second argument is typically the \code{hypothesis.matrix}. See the
28 | Details section of \code{\link[car]{linearHypothesis}}. In the case of \code{anova},
29 | additional sequential \code{"nestedLogit"} models.}
30 |
31 | \item{x, object, object2, mod, model}{in most cases, an object of class \code{"nestedLogit"}.}
32 | }
33 | \value{
34 | \itemize{
35 | \item The \code{Anova} and \code{anova} methods return objects
36 | of class \code{"Anova.nestedLogit"} and \code{"anova.nestedLogit"}, respectively,
37 | each of which contains a list of \code{"anova"} objects (see \code{\link{anova}})
38 | and is usually printed.
39 | \item The \code{linearHypothesis} method is called for its side effect, printing
40 | the result of linear hypothesis tests, and invisibly returns \code{NULL}.
41 | \item The \code{logLik} method returns an object of class \code{"logLik"} (see \code{\link{logLik}}).
42 | }
43 | }
44 | \description{
45 | Various methods for testing hypotheses about nested logit models.
46 | \describe{
47 | \item{\code{Anova}}{Calculates type-II or type-III analysis-of-variance tables for \code{"nestedLogit"} objects;
48 | see \code{\link[car]{Anova}} in the \pkg{car} package.}
49 | \item{\code{anova}}{Computes sequential analysis of variance (or deviance) tables for one or more fitted
50 | \code{"nestedLogit"} objects; see \code{\link{anova}}.}
51 | \item{\code{linearHypothesis}}{Computes Wald tests for linear hypotheses;
52 | see \code{\link[car]{linearHypothesis}} in the \pkg{car} package.}
53 | \item{\code{logLik}}{Returns the log-likelihood and degrees of freedom for the nested-dichotomies model.
54 | (and through it \code{\link{AIC}} and \code{\link{BIC}} model-comparison statistics).}
55 | }
56 | }
57 | \examples{
58 | # define continuation dichotomies for level of education
59 | cont.dichots <- continuationLogits(c("l.t.highschool",
60 | "highschool",
61 | "college",
62 | "graduate"))
63 | # fit a nested model for the GSS data examining education degree in relation to parent & year
64 | m <- nestedLogit(degree ~ parentdeg + year,
65 | cont.dichots,
66 | data=GSS)
67 |
68 | # Anova and anova tests
69 | car::Anova(m) # type-II (partial) tests
70 |
71 | anova(update(m, . ~ . - year), m) # model comparison
72 |
73 | # Wald test
74 | car::linearHypothesis(m, c("parentdeghighschool", "parentdegcollege",
75 | "parentdeggraduate"))
76 |
77 | # log-liklihood, AIC, and BIC
78 | logLik(m)
79 | AIC(m)
80 | BIC(m)
81 | }
82 | \seealso{
83 | \code{\link[car]{Anova}}, \code{\link{anova}},
84 | \code{\link[car]{linearHypothesis}}, \code{\link{logLik}}, \code{\link{AIC}},
85 | \code{\link{BIC}}
86 | }
87 | \author{
88 | John Fox
89 | }
90 | \keyword{regression}
91 |
--------------------------------------------------------------------------------
/man/partials/methods.Rmd:
--------------------------------------------------------------------------------
1 | As befits a model-fitting function, the package defines a nearly complete set of methods for `"nestedLogit"` objects:
2 |
3 | * `print()` and `summary()` print the results for each of the submodels.
4 | * `update()` re-fits the model, allowing changes to the model `formula`, `data`, `subset`, and `contrasts` arguments.
5 | * `coef()` returns the coefficients for the predictors in each dichotomy.
6 | * `vcov()` returns the variance-covariance matrix of the coefficients
7 | * `predict()` computes predicted probabilities for the response categories, either for the cases in the data, which is equivalent to `fitted()`, or for arbitrary combinations of the predictors; the latter is useful for producing plots to aid interpretation.
8 | * `confint()` calculates confidence intervals for the predicted probabilities or predicted logits.
9 | * `as.data.frame()` method for predicted probabilities and logits converts these to long format for use with `ggplot2`.
10 | * `glance()` and `tidy()` are extensions of `broom::glance.glm()` and `broom::tidy.glm()` to obtain compact summaries of a `"nestedLogit"` model object.
11 | * `plot()` provides basic plots of the predicted probabilities over a range of values of the predictor variables.
12 | * `models()` is an extractor function for the binary logit models in the `"nestedLogit"` object
13 | * `Effect()` calculates marginal effects collapsed over some variable(s) for the purpose of making effect plots.
14 |
15 | These functions are supplemented by various methods for testing hypotheses about and comparing nested-logit models:
16 |
17 | * `anova()` provides analysis-of-deviance Type I (sequential) tests for each dichotomy and for the combined model. When given a sequence of model objects, `anova()` tests the models against one another in the order specified.
18 | * `Anova()` uses `car::Anova()` to provide analysis-of-deviance Type II or III (partial) tests for each dichotomy and for the combined model.
19 | * `linearHypothesis()` uses `car::linearHypothesis()` to compute Wald tests for hypotheses about coefficients or their linear combinations.
20 | * `logLik()` returns the log-likelihood and degrees of freedom for the nested-dichotomies logit model.
21 | * Through `logLik()`, the `AIC()` and `BIC()` functions compute the Akaike and Bayesian information criteria model-comparison statistics.
22 |
--------------------------------------------------------------------------------
/man/plot.nestedLogit.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/plot.nested-ci.R
3 | \name{plot.nestedLogit}
4 | \alias{plot.nestedLogit}
5 | \title{Plotting Nested Logit Models}
6 | \usage{
7 | \method{plot}{nestedLogit}(
8 | x,
9 | x.var,
10 | others,
11 | n.x.values = 100L,
12 | xlab = x.var,
13 | ylab = "Fitted Probability",
14 | main,
15 | cex.main = 1,
16 | digits.main = getOption("digits") - 2L,
17 | font.main = 1L,
18 | pch = 1L:length(response.levels),
19 | lwd = 3,
20 | lty = 1L:length(response.levels),
21 | col = palette()[1L:length(response.levels)],
22 | legend = TRUE,
23 | legend.inset = 0.01,
24 | legend.location = "topleft",
25 | legend.bty = "n",
26 | conf.level = 0.95,
27 | conf.alpha = 0.3,
28 | ...
29 | )
30 | }
31 | \arguments{
32 | \item{x}{an object of \code{"nestedLogit"} produced by \code{\link{nestedLogit}}.}
33 |
34 | \item{x.var}{quoted name of the variable to appear on the x-axis; if omitted, the first
35 | predictor in the model is used.}
36 |
37 | \item{others}{a named list of values for the other variables in the model,
38 | that is, other than \code{x.var}; if any other predictor is omitted, it is set
39 | to an arbitrary value---the mean for a numeric predictor or the first level or
40 | value of a factor, character, or logical predictor; only one value may be
41 | specified for each variable in \code{others}.}
42 |
43 | \item{n.x.values}{the number of evenly spaced values of \code{x.var} at which
44 | to evaluate fitted probabilities to be plotted (default \code{100}).}
45 |
46 | \item{xlab}{label for the x-axis (defaults to the value of \code{x.var}).}
47 |
48 | \item{ylab}{label for the y-axis (defaults to \code{"Fitted Probability"}).}
49 |
50 | \item{main}{main title for the graph (if missing, constructed from the variables and
51 | values in \code{others}).}
52 |
53 | \item{cex.main}{size of main title (see \code{\link{par}}).}
54 |
55 | \item{digits.main}{number of digits to retain when rounding values for the main title.}
56 |
57 | \item{font.main}{font for main title (see \code{\link{par}}).}
58 |
59 | \item{pch}{plotting characters (see \code{\link{par}}).}
60 |
61 | \item{lwd}{line width (see \code{\link{par}}).}
62 |
63 | \item{lty}{line types (see \code{\link{par}}).}
64 |
65 | \item{col}{line colors (see \code{\link{par}}).}
66 |
67 | \item{legend}{if \code{TRUE} (the default), add a legend for the
68 | response levels to the graph.}
69 |
70 | \item{legend.inset}{default \code{0.01} (see \code{\link{legend}}).}
71 |
72 | \item{legend.location}{position of the legend (default \code{"topleft"},
73 | see \code{\link{legend}}).}
74 |
75 | \item{legend.bty}{the type of box to be drawn around the legend. The allowed values are "o" (the default) and "n".}
76 |
77 | \item{conf.level}{the level for pointwise confidence envelopes around the predicted response probabilities;
78 | the default is \code{.0.95}. If \code{NULL}, the confidence envelopes are suppressed.}
79 |
80 | \item{conf.alpha}{the opacity of the confidence envelopes; the default is \code{0.3}.}
81 |
82 | \item{\dots}{arguments to be passed to \code{\link{matplot}}.}
83 | }
84 | \value{
85 | NULL Used for its side-effect of producing a plot
86 | }
87 | \description{
88 | A \code{\link{plot}} method for \code{"nestedLogit"} objects produced by the
89 | \code{\link{nestedLogit}} function. Fitted probabilities under the model are plotted
90 | for each level of the polytomous response variable, with one of the explanatory variables
91 | on the horizontal axis and other explanatory variables fixed to particular values.
92 | By default, a 95\% pointwise confidence envelope is added to the plot.
93 | }
94 | \examples{
95 | data("Womenlf", package = "carData")
96 | m <- nestedLogit(partic ~ hincome + children,
97 | logits(work=dichotomy("not.work", c("parttime", "fulltime")),
98 | full=dichotomy("parttime", "fulltime")),
99 | data=Womenlf)
100 | plot(m, legend.location="top")
101 | op <- par(mfcol=c(1, 2), mar=c(4, 4, 3, 1) + 0.1)
102 | plot(m, "hincome", list(children="absent"),
103 | xlab="Husband's Income", legend=FALSE)
104 | plot(m, "hincome", list(children="present"),
105 | xlab="Husband's Income")
106 | par(op)
107 |
108 | }
109 | \seealso{
110 | \code{\link{nestedLogit}}, \code{\link[graphics]{matplot}}
111 | }
112 | \author{
113 | John Fox \email{jfox@mcmaster.ca}
114 | }
115 |
--------------------------------------------------------------------------------
/old/predict-nested.R:
--------------------------------------------------------------------------------
1 | # old predict.nestedLogit
2 |
3 | #' @rdname nestedMethods
4 | #' @importFrom stats predict
5 | #' @export
6 | predict.nestedLogit <- function(object, newdata, model=c("nested", "dichotomies"), ...) {
7 | model <- match.arg(model)
8 | if (model == "nested"){
9 | if (missing(newdata))
10 | newdata <- models(object, 1)$data
11 | ndichot <- length(models(object))
12 | if (ndichot < 2L)
13 | stop("there are fewer than 2 nested dichotomies")
14 | fitted <- vector(ndichot, mode = "list")
15 | for (i in seq_along(models(object))) {
16 | p <- predict(models(object, i), newdata = newdata, type = "response")
17 | p <- cbind(1 - p, p)
18 | attr(p, "columns") <- models(object, i)$dichotomy
19 | fitted[[i]] <- p
20 | }
21 | response.levels <-
22 | unique(unlist(lapply(fitted, function(x)
23 | attr(x, "columns"))))
24 | p <- matrix(1, nrow(newdata), length(response.levels))
25 | colnames(p) <- response.levels
26 | for (level in response.levels) {
27 | for (i in seq_along(models(object))) {
28 | which <- sapply(models(object, i)$dichotomy, function(x)
29 | level %in% x)
30 | if (!any(which))
31 | next
32 | p[, level] <- p[, level] * fitted[[i]][, which]
33 | }
34 | }
35 | rownames(p) <- rownames(newdata)
36 | return(p)
37 | } else {
38 | result <- lapply(models(object), predict, newdata=newdata, ...)
39 | attr(result, "model") <- deparse(substitute(object))
40 | class(result) <- "predictDichotomies"
41 | return(result)
42 | }
43 | }
44 |
45 | #' @rdname nestedMethods
46 | #' @export
47 | print.predictDichotomies <- function(x, ...){
48 | cat("\n predictions for binary logit models from nested logit model:",
49 | attr(x, "model"))
50 | cat("\n for responses:", paste(names(x), sep=", "))
51 | cat(paste0("\n access via $", names(x)[1], " etc."))
52 | }
53 |
--------------------------------------------------------------------------------
/pkgdown/favicon/apple-touch-icon-120x120.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/pkgdown/favicon/apple-touch-icon-120x120.png
--------------------------------------------------------------------------------
/pkgdown/favicon/apple-touch-icon-152x152.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/pkgdown/favicon/apple-touch-icon-152x152.png
--------------------------------------------------------------------------------
/pkgdown/favicon/apple-touch-icon-180x180.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/pkgdown/favicon/apple-touch-icon-180x180.png
--------------------------------------------------------------------------------
/pkgdown/favicon/apple-touch-icon-60x60.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/pkgdown/favicon/apple-touch-icon-60x60.png
--------------------------------------------------------------------------------
/pkgdown/favicon/apple-touch-icon-76x76.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/pkgdown/favicon/apple-touch-icon-76x76.png
--------------------------------------------------------------------------------
/pkgdown/favicon/apple-touch-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/pkgdown/favicon/apple-touch-icon.png
--------------------------------------------------------------------------------
/pkgdown/favicon/favicon-16x16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/pkgdown/favicon/favicon-16x16.png
--------------------------------------------------------------------------------
/pkgdown/favicon/favicon-32x32.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/pkgdown/favicon/favicon-32x32.png
--------------------------------------------------------------------------------
/pkgdown/favicon/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/pkgdown/favicon/favicon.ico
--------------------------------------------------------------------------------
/revdep/README.md:
--------------------------------------------------------------------------------
1 | # Platform
2 |
3 | |field |value |
4 | |:--------|:-------------------------------------------|
5 | |version |R version 4.2.3 (2023-03-15 ucrt) |
6 | |os |Windows 10 x64 (build 19044) |
7 | |system |x86_64, mingw32 |
8 | |ui |RStudio |
9 | |language |(EN) |
10 | |collate |English_Canada.utf8 |
11 | |ctype |English_Canada.utf8 |
12 | |tz |America/New_York |
13 | |date |2023-06-21 |
14 | |rstudio |2023.03.0+386 Cherry Blossom (desktop) |
15 | |pandoc |3.1.2 @ C:/PROGRA~1/Pandoc/ (via rmarkdown) |
16 |
17 | # Dependencies
18 |
19 | |package |old |new |Δ |
20 | |:-----------|:-----|:-----|:--|
21 | |nestedLogit |0.3.0 |0.3.2 |* |
22 |
23 | # Revdeps
24 |
25 | ## Failed to check (3)
26 |
27 | |package |version |error |warning |note |
28 | |:----------|:-------|:-----|:-------|:----|
29 | |ggeffects |? | | | |
30 | |insight |? | | | |
31 | |parameters |? | | | |
32 |
33 |
--------------------------------------------------------------------------------
/revdep/checks/libraries.csv:
--------------------------------------------------------------------------------
1 | package,old,new,delta
2 | nestedLogit,0.3.0,0.3.2,*
3 |
--------------------------------------------------------------------------------
/revdep/cran.md:
--------------------------------------------------------------------------------
1 | ## revdepcheck results
2 |
3 | We checked 3 reverse dependencies (0 from CRAN + 3 from Bioconductor), comparing R CMD check results across CRAN and dev versions of this package.
4 |
5 | * We saw 0 new problems
6 | * We failed to check 0 packages
7 |
8 |
--------------------------------------------------------------------------------
/revdep/data.sqlite:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/revdep/data.sqlite
--------------------------------------------------------------------------------
/revdep/library/nestedLogit/new/nestedLogit/DESCRIPTION:
--------------------------------------------------------------------------------
1 | Package: nestedLogit
2 | Title: Nested Dichotomy Logistic Regression Models
3 | Version: 0.3.2
4 | Date: 2023-06-06
5 | Authors@R: c(
6 | person("John", "Fox", , "jfox@mcmaster.ca", role = "aut",
7 | comment = c(ORCID = "0000-0002-1196-8012")),
8 | person("Michael", "Friendly", , "friendly@yorku.ca", role = c("aut", "cre"),
9 | comment = c(ORCID = "0000-0002-3237-0941")),
10 | person("Achim", "Zeileis", , "Achim.Zeileis@uibk.ac.at", role = "ctb",
11 | comment = c(ORCID = "0000-0003-0918-3766"))
12 | )
13 | Description: Provides functions for specifying and fitting nested
14 | dichotomy logistic regression models for a multi-category response and
15 | methods for summarising and plotting those models. Nested dichotomies are
16 | statistically independent, and hence provide an additive decomposition
17 | of tests for the overall 'polytomous' response. When the dichotomies
18 | make sense substantively, this method can be a simpler alternative to
19 | the standard 'multinomial' logistic model which compares response
20 | categories to a reference level. See: J. Fox (2016), "Applied
21 | Regression Analysis and Generalized Linear Models", 3rd Ed., ISBN
22 | 1452205663.
23 | License: GPL (>=2)
24 | URL: https://github.com/friendly/nestedLogit
25 | BugReports: https://github.com/friendly/nestedLogit/issues
26 | Depends: R (>= 3.5.0)
27 | Imports: broom, car, dplyr, effects, graphics, grDevices, stats,
28 | stringr, tibble
29 | Suggests: carData, geomtextpath, ggplot2, here, lobstr, knitr, nnet,
30 | rmarkdown, spelling, testthat, tidyr
31 | VignetteBuilder: knitr, rmarkdown
32 | Encoding: UTF-8
33 | Language: en-US
34 | LazyData: TRUE
35 | Roxygen: list(markdown = TRUE)
36 | RoxygenNote: 7.2.3
37 | RemoteType: local
38 | RemoteUrl: C:\Dropbox\R\projects\nestedLogit
39 | NeedsCompilation: no
40 | Packaged: 2023-06-21 09:49:30 UTC; friendly
41 | Author: John Fox [aut] (),
42 | Michael Friendly [aut, cre] (),
43 | Achim Zeileis [ctb] ()
44 | Maintainer: Michael Friendly
45 | Built: R 4.2.3; ; 2023-06-21 09:49:33 UTC; windows
46 |
--------------------------------------------------------------------------------
/revdep/library/nestedLogit/new/nestedLogit/INDEX:
--------------------------------------------------------------------------------
1 | Effect.nestedLogit Effect Displays for Nested Logit Models
2 | GSS Data From the U.S. General Social Survey
3 | 1972-2016
4 | HealthInsurance Choice of Health Insurance Product
5 | as.data.frame.predictNestedLogit
6 | Convert a Predicted Objects to a data.frame
7 | broomMethods Broom Related Methods
8 | models Extract Binary Logit Models from a
9 | 'nestedLogit' Object
10 | nestedHypotheses Hypothesis-Testing and Related Methods for
11 | '"nestedLogit"' Objects
12 | nestedLogit Binary Logit Models for Nested Dichotomies
13 | nestedMethods Methods for '"nestedLogit"' and Related Objects
14 | plot.nestedLogit Plotting Nested Logit Models
15 |
--------------------------------------------------------------------------------
/revdep/library/nestedLogit/new/nestedLogit/Meta/Rd.rds:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/revdep/library/nestedLogit/new/nestedLogit/Meta/Rd.rds
--------------------------------------------------------------------------------
/revdep/library/nestedLogit/new/nestedLogit/Meta/data.rds:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/revdep/library/nestedLogit/new/nestedLogit/Meta/data.rds
--------------------------------------------------------------------------------
/revdep/library/nestedLogit/new/nestedLogit/Meta/features.rds:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/revdep/library/nestedLogit/new/nestedLogit/Meta/features.rds
--------------------------------------------------------------------------------
/revdep/library/nestedLogit/new/nestedLogit/Meta/hsearch.rds:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/revdep/library/nestedLogit/new/nestedLogit/Meta/hsearch.rds
--------------------------------------------------------------------------------
/revdep/library/nestedLogit/new/nestedLogit/Meta/links.rds:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/revdep/library/nestedLogit/new/nestedLogit/Meta/links.rds
--------------------------------------------------------------------------------
/revdep/library/nestedLogit/new/nestedLogit/Meta/nsInfo.rds:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/revdep/library/nestedLogit/new/nestedLogit/Meta/nsInfo.rds
--------------------------------------------------------------------------------
/revdep/library/nestedLogit/new/nestedLogit/Meta/package.rds:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/revdep/library/nestedLogit/new/nestedLogit/Meta/package.rds
--------------------------------------------------------------------------------
/revdep/library/nestedLogit/new/nestedLogit/NAMESPACE:
--------------------------------------------------------------------------------
1 | # Generated by roxygen2: do not edit by hand
2 |
3 | S3method(Anova,nestedLogit)
4 | S3method(anova,nestedLogit)
5 | S3method(as.character,dichotomies)
6 | S3method(as.data.frame,predictDichotomies)
7 | S3method(as.data.frame,predictNestedLogit)
8 | S3method(as.dichotomies,matrix)
9 | S3method(as.matrix,continuationDichotomies)
10 | S3method(as.matrix,dichotomies)
11 | S3method(broom::glance,nestedLogit)
12 | S3method(broom::tidy,nestedLogit)
13 | S3method(car::Anova,nestedLogit)
14 | S3method(car::linearHypothesis,nestedLogit)
15 | S3method(coef,nestedLogit)
16 | S3method(confint,predictNestedLogit)
17 | S3method(effects::Effect,nestedLogit)
18 | S3method(fitted,nestedLogit)
19 | S3method(linearHypothesis,nestedLogit)
20 | S3method(logLik,nestedLogit)
21 | S3method(models,nestedLogit)
22 | S3method(plot,nestedLogit)
23 | S3method(predict,nestedLogit)
24 | S3method(print,Anova.nestedLogit)
25 | S3method(print,anova.nestedLogit)
26 | S3method(print,dichotomies)
27 | S3method(print,nestedLogit)
28 | S3method(print,predictDichotomies)
29 | S3method(print,predictNestedLogit)
30 | S3method(print,summary.nestedLogit)
31 | S3method(stats::logLik,nestedLogit)
32 | S3method(summary,nestedLogit)
33 | S3method(update,nestedLogit)
34 | S3method(vcov,nestedLogit)
35 | export(as.dichotomies)
36 | export(continuationLogits)
37 | export(dichotomy)
38 | export(logits)
39 | export(models)
40 | export(nestedLogit)
41 | importFrom(broom,glance)
42 | importFrom(broom,tidy)
43 | importFrom(car,Anova)
44 | importFrom(car,linearHypothesis)
45 | importFrom(dplyr,bind_cols)
46 | importFrom(dplyr,select)
47 | importFrom(effects,Effect)
48 | importFrom(grDevices,adjustcolor)
49 | importFrom(grDevices,palette)
50 | importFrom(graphics,arrows)
51 | importFrom(graphics,axis)
52 | importFrom(graphics,box)
53 | importFrom(graphics,matplot)
54 | importFrom(graphics,polygon)
55 | importFrom(graphics,title)
56 | importFrom(stats,anova)
57 | importFrom(stats,binomial)
58 | importFrom(stats,coef)
59 | importFrom(stats,confint)
60 | importFrom(stats,fitted)
61 | importFrom(stats,formula)
62 | importFrom(stats,glm)
63 | importFrom(stats,model.frame)
64 | importFrom(stats,model.matrix)
65 | importFrom(stats,model.response)
66 | importFrom(stats,na.omit)
67 | importFrom(stats,pchisq)
68 | importFrom(stats,predict)
69 | importFrom(stats,qnorm)
70 | importFrom(stats,update)
71 | importFrom(stringr,str_remove)
72 | importFrom(tibble,rownames_to_column)
73 |
--------------------------------------------------------------------------------
/revdep/library/nestedLogit/new/nestedLogit/NEWS.md:
--------------------------------------------------------------------------------
1 | # nestedLogit 0.3.2
2 |
3 | * new `Effect` method for `"nestedLogit"` objects to create effect displays.
4 | * add Effect example to vignette
5 |
6 |
7 | # nestedLogit 0.3.1
8 |
9 | * correct buglet in `as.data.frame` method when `newdata` has one column
10 | * `predict.nestedLogit()` now includes the `newdata` data frame as an additional component (`.data`) in its result. Consequently, the `newdata` argument is no longer required in the `as.data.frame` method.
11 |
12 | # nestedLogit 0.3.0
13 |
14 | This is a major enhancement to the package, adding computations of standard errors and confidence intervals to predicted probabilities and logits.
15 |
16 | ## Enhancements
17 | * The `predict()` method now computes standard errors for probabilities and logits using the delta method. These can be obtained for either the response probabilities (and equivalent logits) or for the predicted log odds of the individual dichotomies.
18 | * A `confint()` method for the result of `predict()` generates the corresponding confidence intervals.
19 | * `as.data.frame()` methods for predicted values, either for the nested logit model or for the separate dichotomies converts these to a data frame in long format, handy for using `ggplot()`.
20 | * Added a `confint()` method for predicted probabilities and logits
21 | * The `plot()` method for `"nestedLogit"` objects now plots confidence intervals for predicted probabilities.
22 | * A new vignette, "standard-errors", describes the mathematics behind the standard error calculations.
23 | * An old vignette on plotting methods was completely re-written using the new `predict()` methods and focusing exclusively on `ggplot2().
24 |
25 | ## Other
26 | * Added an example of `lobstr::tree()` to print nested lists
27 | * Now use `fig.show="hold"` to keep `par(op)` with the code.
28 |
29 | # nestedLogit 0.2.1
30 |
31 | * Reset all `par()` and `options()` calls so as to not alter user's workspace.
32 | * now document all return values.
33 | * added a reference to DESCRIPTION. It is a book, so no doi:, url, etc.
34 | * fixed one URL that win-builder (spuriously) complains about.
35 |
36 |
37 | # nestedLogit 0.2.0
38 |
39 | * Now allow dichotomies to be specified by a nested (recursive) of binary splits of the categories [suggestion of Achim Zeileis]
40 | * The model object is now of class "nestedLogit" for uniformity.
41 | * A basic `plot()` method now operational
42 | * Added a `linearHypothesis()` method to give Wald tests for hypotheses about coefficients or their linear combinations.
43 | * Expanded vignette to illustrate some other methods.
44 | * Added a `models()` generic and method to extract separate models from the `"nestedLogit"` object
45 | * Added a `logLike()` method, and through it, gets `AIC()` and `BIC()`
46 | * Reorganized documentation to separate nested hypothesis methods.
47 |
48 | # nestedLogit 0.1.0
49 |
50 | * Initial version
51 | * Added a `NEWS.md` file to track changes to the package.
52 |
53 |
--------------------------------------------------------------------------------
/revdep/library/nestedLogit/new/nestedLogit/R/nestedLogit:
--------------------------------------------------------------------------------
1 | # File share/R/nspackloader.R
2 | # Part of the R package, https://www.R-project.org
3 | #
4 | # Copyright (C) 1995-2012 The R Core Team
5 | #
6 | # This program is free software; you can redistribute it and/or modify
7 | # it under the terms of the GNU General Public License as published by
8 | # the Free Software Foundation; either version 2 of the License, or
9 | # (at your option) any later version.
10 | #
11 | # This program is distributed in the hope that it will be useful,
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | # GNU General Public License for more details.
15 | #
16 | # A copy of the GNU General Public License is available at
17 | # https://www.r-project.org/Licenses/
18 |
19 | local({
20 | info <- loadingNamespaceInfo()
21 | pkg <- info$pkgname
22 | ns <- .getNamespace(as.name(pkg))
23 | if (is.null(ns))
24 | stop("cannot find namespace environment for ", pkg, domain = NA);
25 | dbbase <- file.path(info$libname, pkg, "R", pkg)
26 | lazyLoad(dbbase, ns, filter = function(n) n != ".__NAMESPACE__.")
27 | })
28 |
--------------------------------------------------------------------------------
/revdep/library/nestedLogit/new/nestedLogit/R/nestedLogit.rdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/revdep/library/nestedLogit/new/nestedLogit/R/nestedLogit.rdb
--------------------------------------------------------------------------------
/revdep/library/nestedLogit/new/nestedLogit/R/nestedLogit.rdx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/revdep/library/nestedLogit/new/nestedLogit/R/nestedLogit.rdx
--------------------------------------------------------------------------------
/revdep/library/nestedLogit/new/nestedLogit/WORDLIST:
--------------------------------------------------------------------------------
1 | Analytics
2 | anova
3 | Anova
4 | aspx
5 | boldsymbol
6 | carData
7 | cdots
8 | continuationLogits
9 | CRC
10 | dichotomize
11 | df
12 | doi
13 | Fienberg
14 | frac
15 | fulltime
16 | ggplot
17 | gradeschool
18 | GSS
19 | https
20 | ij
21 | im
22 | jk
23 | ldots
24 | Lifecycle
25 | McNulty
26 | newdata
27 | NORC
28 | norc
29 | nnet
30 | Weisberg
31 | highschool
32 | hincome
33 | linearHypothesis
34 | mathbf
35 | mathcal
36 | nd
37 | ne
38 | operatorname
39 | partic
40 | parttime
41 | polytomy
42 | predictNestedLogit
43 | recoding
44 | repo
45 | summarising
46 | tibbles
47 | th
48 | vec
49 | widehat
50 | womens
51 | Womenlf
52 | www
53 | Monette
54 | subseteq
55 | buglet
56 | customizable
57 |
--------------------------------------------------------------------------------
/revdep/library/nestedLogit/new/nestedLogit/data/Rdata.rdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/revdep/library/nestedLogit/new/nestedLogit/data/Rdata.rdb
--------------------------------------------------------------------------------
/revdep/library/nestedLogit/new/nestedLogit/data/Rdata.rds:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/revdep/library/nestedLogit/new/nestedLogit/data/Rdata.rds
--------------------------------------------------------------------------------
/revdep/library/nestedLogit/new/nestedLogit/data/Rdata.rdx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/revdep/library/nestedLogit/new/nestedLogit/data/Rdata.rdx
--------------------------------------------------------------------------------
/revdep/library/nestedLogit/new/nestedLogit/help/AnIndex:
--------------------------------------------------------------------------------
1 | Anova.nestedLogit nestedHypotheses
2 | anova.nestedLogit nestedHypotheses
3 | as.character.dichotomies nestedMethods
4 | as.data.frame.predictNestedLogit as.data.frame.predictNestedLogit
5 | as.dichotomies nestedMethods
6 | as.dichotomies.matrix nestedMethods
7 | as.matrix.continuationDichotomies nestedMethods
8 | as.matrix.dichotomies nestedMethods
9 | broomMethods broomMethods
10 | coef.nestedLogit nestedMethods
11 | confint.predictNestedLogit nestedMethods
12 | continuationLogits nestedLogit
13 | dichotomy nestedLogit
14 | Effect.nestedLogit Effect.nestedLogit
15 | fitted.nestedLogit nestedMethods
16 | glance.nestedLogit broomMethods
17 | GSS GSS
18 | HealthInsurance HealthInsurance
19 | linearHypothesis.nestedLogit nestedHypotheses
20 | logits nestedLogit
21 | logLik.nestedLogit nestedHypotheses
22 | models models
23 | models.nestedLogit models
24 | nestedHypotheses nestedHypotheses
25 | nestedLogit nestedLogit
26 | nestedMethods nestedMethods
27 | plot.nestedLogit plot.nestedLogit
28 | predict.nestedLogit nestedMethods
29 | print.Anova.nestedLogit nestedHypotheses
30 | print.anova.nestedLogit nestedHypotheses
31 | print.dichotomies nestedMethods
32 | print.nestedLogit nestedMethods
33 | print.predictDichotomies nestedMethods
34 | print.predictNestedLogit nestedMethods
35 | print.summary.nestedLogit nestedMethods
36 | summary.nestedLogit nestedMethods
37 | tidy.nestedLogit broomMethods
38 | update.nestedLogit nestedMethods
39 | vcov.nestedLogit nestedMethods
40 |
--------------------------------------------------------------------------------
/revdep/library/nestedLogit/new/nestedLogit/help/aliases.rds:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/revdep/library/nestedLogit/new/nestedLogit/help/aliases.rds
--------------------------------------------------------------------------------
/revdep/library/nestedLogit/new/nestedLogit/help/figures/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/revdep/library/nestedLogit/new/nestedLogit/help/figures/logo.png
--------------------------------------------------------------------------------
/revdep/library/nestedLogit/new/nestedLogit/help/nestedLogit.rdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/revdep/library/nestedLogit/new/nestedLogit/help/nestedLogit.rdb
--------------------------------------------------------------------------------
/revdep/library/nestedLogit/new/nestedLogit/help/nestedLogit.rdx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/revdep/library/nestedLogit/new/nestedLogit/help/nestedLogit.rdx
--------------------------------------------------------------------------------
/revdep/library/nestedLogit/new/nestedLogit/help/paths.rds:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/revdep/library/nestedLogit/new/nestedLogit/help/paths.rds
--------------------------------------------------------------------------------
/revdep/library/nestedLogit/new/nestedLogit/html/R.css:
--------------------------------------------------------------------------------
1 | @media screen {
2 | .container {
3 | padding-right: 10px;
4 | padding-left: 10px;
5 | margin-right: auto;
6 | margin-left: auto;
7 | max-width: 900px;
8 | }
9 | }
10 |
11 | .rimage img { /* from knitr - for examples and demos */
12 | width: 96%;
13 | margin-left: 2%;
14 | }
15 |
16 | .katex { font-size: 1.1em; }
17 |
18 | code {
19 | color: inherit;
20 | background: inherit;
21 | }
22 |
23 | body {
24 | line-height: 1.4;
25 | background: white;
26 | color: black;
27 | }
28 |
29 | a:link {
30 | background: white;
31 | color: blue;
32 | }
33 |
34 | a:visited {
35 | background: white;
36 | color: rgb(50%, 0%, 50%);
37 | }
38 |
39 | h1 {
40 | background: white;
41 | color: rgb(55%, 55%, 55%);
42 | font-family: monospace;
43 | font-size: 1.4em; /* x-large; */
44 | text-align: center;
45 | }
46 |
47 | h2 {
48 | background: white;
49 | color: rgb(40%, 40%, 40%);
50 | font-family: monospace;
51 | font-size: 1.2em; /* large; */
52 | text-align: center;
53 | }
54 |
55 | h3 {
56 | background: white;
57 | color: rgb(40%, 40%, 40%);
58 | font-family: monospace;
59 | font-size: 1.2em; /* large; */
60 | }
61 |
62 | h4 {
63 | background: white;
64 | color: rgb(40%, 40%, 40%);
65 | font-family: monospace;
66 | font-style: italic;
67 | font-size: 1.2em; /* large; */
68 | }
69 |
70 | h5 {
71 | background: white;
72 | color: rgb(40%, 40%, 40%);
73 | font-family: monospace;
74 | }
75 |
76 | h6 {
77 | background: white;
78 | color: rgb(40%, 40%, 40%);
79 | font-family: monospace;
80 | font-style: italic;
81 | }
82 |
83 | img.toplogo {
84 | width: 4em;
85 | vertical-align: middle;
86 | }
87 |
88 | img.arrow {
89 | width: 30px;
90 | height: 30px;
91 | border: 0;
92 | }
93 |
94 | span.acronym {
95 | font-size: small;
96 | }
97 |
98 | span.env {
99 | font-family: monospace;
100 | }
101 |
102 | span.file {
103 | font-family: monospace;
104 | }
105 |
106 | span.option{
107 | font-family: monospace;
108 | }
109 |
110 | span.pkg {
111 | font-weight: bold;
112 | }
113 |
114 | span.samp{
115 | font-family: monospace;
116 | }
117 |
118 | div.vignettes a:hover {
119 | background: rgb(85%, 85%, 85%);
120 | }
121 |
--------------------------------------------------------------------------------
/revdep/library/nestedLogit/old/nestedLogit/DESCRIPTION:
--------------------------------------------------------------------------------
1 | Package: nestedLogit
2 | Title: Nested Dichotomy Logistic Regression Models
3 | Version: 0.3.0
4 | Date: 2023-05-30
5 | Authors@R: c(
6 | person("John", "Fox", , "jfox@mcmaster.ca", role = "aut",
7 | comment = c(ORCID = "0000-0002-1196-8012")),
8 | person("Michael", "Friendly", , "friendly@yorku.ca", role = c("aut", "cre"),
9 | comment = c(ORCID = "0000-0002-3237-0941")),
10 | person("Achim", "Zeileis", , "Achim.Zeileis@uibk.ac.at", role = "ctb",
11 | comment = c(ORCID = "0000-0003-0918-3766"))
12 | )
13 | Description: Provides functions for specifying and fitting nested
14 | dichotomy logistic regression models for a multi-category response and
15 | methods for summarising and plotting those models. Nested dichotomies are
16 | statistically independent, and hence provide an additive decomposition
17 | of tests for the overall 'polytomous' response. When the dichotomies
18 | make sense substantively, this method can be a simpler alternative to
19 | the standard 'multinomial' logistic model which compares response
20 | categories to a reference level. See: J. Fox (2016), "Applied
21 | Regression Analysis and Generalized Linear Models", 3rd Ed., ISBN
22 | 1452205663.
23 | License: GPL (>= 2)
24 | URL: https://github.com/friendly/nestedLogit
25 | BugReports: https://github.com/friendly/nestedLogit/issues
26 | Depends: R (>= 3.5.0)
27 | Imports: broom, car, dplyr, graphics, grDevices, stats, stringr, tibble
28 | Suggests: carData, geomtextpath, ggplot2, here, lobstr, knitr, nnet,
29 | rmarkdown, spelling, testthat, tidyr
30 | VignetteBuilder: knitr, rmarkdown
31 | Encoding: UTF-8
32 | Language: en-US
33 | LazyData: TRUE
34 | RoxygenNote: 7.2.3
35 | NeedsCompilation: no
36 | Packaged: 2023-05-30 16:09:16 UTC; friendly
37 | Author: John Fox [aut] (),
38 | Michael Friendly [aut, cre] (),
39 | Achim Zeileis [ctb] ()
40 | Maintainer: Michael Friendly
41 | Repository: CRAN
42 | Date/Publication: 2023-05-30 17:10:02 UTC
43 | Built: R 4.2.3; ; 2023-06-19 03:58:43 UTC; windows
44 |
--------------------------------------------------------------------------------
/revdep/library/nestedLogit/old/nestedLogit/INDEX:
--------------------------------------------------------------------------------
1 | GSS Data From the U.S. General Social Survey
2 | 1972-2016
3 | HealthInsurance Choice of Health Insurance Product
4 | as.data.frame.predictNestedLogit
5 | Convert a Predicted Objects to a data.frame
6 | broomMethods Broom Related Methods
7 | models Extract Binary Logit Models from a
8 | 'nestedLogit' Object
9 | nestedHypotheses Hypothesis-Testing and Related Methods for
10 | '"nestedLogit"' Objects
11 | nestedLogit Binary Logit Models for Nested Dichotomies
12 | nestedMethods Methods for '"nestedLogit"' and Related Objects
13 | plot.nestedLogit Plotting Nested Logit Models
14 |
--------------------------------------------------------------------------------
/revdep/library/nestedLogit/old/nestedLogit/MD5:
--------------------------------------------------------------------------------
1 | f680fee671de9632e1af0ea267601ebf *DESCRIPTION
2 | 0986faa76a05bc4917d607ed07040e8a *INDEX
3 | 1156fe432cc0ac4b46a29cdd07febfc7 *Meta/Rd.rds
4 | 96e0d77ba829c414fbae069d5678cb1c *Meta/data.rds
5 | 9f7a4637f056aa0787fb29bc9c21a1ff *Meta/features.rds
6 | 999e2a603877b31f57cb1d1c830546d5 *Meta/hsearch.rds
7 | 31fa0fc8fe17b51e81c34e4d30a003b5 *Meta/links.rds
8 | 6f60486a9646e92c43a427cc77032d2d *Meta/nsInfo.rds
9 | 698a326da015af919c46575a86623a12 *Meta/package.rds
10 | 197ffa7d7a269441350c923a1d161216 *Meta/vignette.rds
11 | e98ac30763583889049c253b30290983 *NAMESPACE
12 | 706898d1ff0a110e76e9898b210d863f *NEWS.md
13 | d6c68f1fe41ced6e98a766a3757313da *R/nestedLogit
14 | 925bd05400814cf9f88cee4d0a531b23 *R/nestedLogit.rdb
15 | ef9245ead9587f54b1edf8d89ddf08ad *R/nestedLogit.rdx
16 | dbc27817b8b6f749502bd7e6f23be167 *WORDLIST
17 | 769dad40d31da9f035e59e9e6de43801 *data/Rdata.rdb
18 | aab1d6c22846d26b8048b8eeceff82ba *data/Rdata.rds
19 | 6922527654f5eca7fc1b4a41d6a512fd *data/Rdata.rdx
20 | abf747e86d1b7d96a91deb51512d3114 *doc/index.html
21 | 5629d971f1f4695c35b50351ee9dd91a *doc/nestedLogit.R
22 | 65396721ef75cfba43116f8d529a27be *doc/nestedLogit.Rmd
23 | b354d6ca5554c79ab40399785d44a017 *doc/nestedLogit.html
24 | 9c307be68a3d05a7aa28fb89ee7ccf43 *doc/plotting-ggplot.R
25 | 085020700a631e2510f009087462e91f *doc/plotting-ggplot.Rmd
26 | 12440d7e87c3dc5a34fa227197a7fa54 *doc/plotting-ggplot.html
27 | 6b25afd22801b94c90148032d4436faa *doc/standard-errors.Rmd
28 | 94ad883fa4ecad28aff59bcd3700abb1 *doc/standard-errors.html
29 | 34e4dd6a847e64b4c1a69c71529415aa *help/AnIndex
30 | 1f88bbe5ed8acbdd9bcde226e377dfc2 *help/aliases.rds
31 | b930e58c9bb32622390c8b0d5847743c *help/figures/logo.png
32 | fb4304ba6b7a5e8a26b8827f89a42825 *help/nestedLogit.rdb
33 | 3deac79827924675d35a9d14b841e6d0 *help/nestedLogit.rdx
34 | d610a82e37523873068148f3f6b9d434 *help/paths.rds
35 | eae4d7949c1e133eed5ee51846c5b5b0 *html/00Index.html
36 | 3845aef6126cf18c45937f292f23508c *html/R.css
37 |
--------------------------------------------------------------------------------
/revdep/library/nestedLogit/old/nestedLogit/Meta/Rd.rds:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/revdep/library/nestedLogit/old/nestedLogit/Meta/Rd.rds
--------------------------------------------------------------------------------
/revdep/library/nestedLogit/old/nestedLogit/Meta/data.rds:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/revdep/library/nestedLogit/old/nestedLogit/Meta/data.rds
--------------------------------------------------------------------------------
/revdep/library/nestedLogit/old/nestedLogit/Meta/features.rds:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/revdep/library/nestedLogit/old/nestedLogit/Meta/features.rds
--------------------------------------------------------------------------------
/revdep/library/nestedLogit/old/nestedLogit/Meta/hsearch.rds:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/revdep/library/nestedLogit/old/nestedLogit/Meta/hsearch.rds
--------------------------------------------------------------------------------
/revdep/library/nestedLogit/old/nestedLogit/Meta/links.rds:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/revdep/library/nestedLogit/old/nestedLogit/Meta/links.rds
--------------------------------------------------------------------------------
/revdep/library/nestedLogit/old/nestedLogit/Meta/nsInfo.rds:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/revdep/library/nestedLogit/old/nestedLogit/Meta/nsInfo.rds
--------------------------------------------------------------------------------
/revdep/library/nestedLogit/old/nestedLogit/Meta/package.rds:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/revdep/library/nestedLogit/old/nestedLogit/Meta/package.rds
--------------------------------------------------------------------------------
/revdep/library/nestedLogit/old/nestedLogit/Meta/vignette.rds:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/revdep/library/nestedLogit/old/nestedLogit/Meta/vignette.rds
--------------------------------------------------------------------------------
/revdep/library/nestedLogit/old/nestedLogit/NAMESPACE:
--------------------------------------------------------------------------------
1 | # Generated by roxygen2: do not edit by hand
2 |
3 | S3method(Anova,nestedLogit)
4 | S3method(anova,nestedLogit)
5 | S3method(as.character,dichotomies)
6 | S3method(as.data.frame,predictDichotomies)
7 | S3method(as.data.frame,predictNestedLogit)
8 | S3method(as.dichotomies,matrix)
9 | S3method(as.matrix,continuationDichotomies)
10 | S3method(as.matrix,dichotomies)
11 | S3method(broom::glance,nestedLogit)
12 | S3method(broom::tidy,nestedLogit)
13 | S3method(car::Anova,nestedLogit)
14 | S3method(car::linearHypothesis,nestedLogit)
15 | S3method(coef,nestedLogit)
16 | S3method(confint,predictNestedLogit)
17 | S3method(fitted,nestedLogit)
18 | S3method(linearHypothesis,nestedLogit)
19 | S3method(logLik,nestedLogit)
20 | S3method(models,nestedLogit)
21 | S3method(plot,nestedLogit)
22 | S3method(predict,nestedLogit)
23 | S3method(print,Anova.nestedLogit)
24 | S3method(print,anova.nestedLogit)
25 | S3method(print,dichotomies)
26 | S3method(print,nestedLogit)
27 | S3method(print,predictDichotomies)
28 | S3method(print,predictNestedLogit)
29 | S3method(print,summary.nestedLogit)
30 | S3method(stats::logLik,nestedLogit)
31 | S3method(summary,nestedLogit)
32 | S3method(update,nestedLogit)
33 | S3method(vcov,nestedLogit)
34 | export(as.dichotomies)
35 | export(continuationLogits)
36 | export(dichotomy)
37 | export(logits)
38 | export(models)
39 | export(nestedLogit)
40 | importFrom(broom,glance)
41 | importFrom(broom,tidy)
42 | importFrom(car,Anova)
43 | importFrom(car,linearHypothesis)
44 | importFrom(dplyr,bind_cols)
45 | importFrom(dplyr,select)
46 | importFrom(grDevices,adjustcolor)
47 | importFrom(grDevices,palette)
48 | importFrom(graphics,arrows)
49 | importFrom(graphics,axis)
50 | importFrom(graphics,box)
51 | importFrom(graphics,matplot)
52 | importFrom(graphics,polygon)
53 | importFrom(graphics,title)
54 | importFrom(stats,anova)
55 | importFrom(stats,binomial)
56 | importFrom(stats,coef)
57 | importFrom(stats,confint)
58 | importFrom(stats,fitted)
59 | importFrom(stats,formula)
60 | importFrom(stats,glm)
61 | importFrom(stats,model.frame)
62 | importFrom(stats,model.response)
63 | importFrom(stats,na.omit)
64 | importFrom(stats,pchisq)
65 | importFrom(stats,predict)
66 | importFrom(stats,qnorm)
67 | importFrom(stats,update)
68 | importFrom(stringr,str_remove)
69 | importFrom(tibble,rownames_to_column)
70 |
--------------------------------------------------------------------------------
/revdep/library/nestedLogit/old/nestedLogit/NEWS.md:
--------------------------------------------------------------------------------
1 | # nestedLogit 0.3.0
2 |
3 | This is a major enhancement to the package, adding computations of standard errors and confidence intervals to predicted probabilities and logits.
4 |
5 | ## Enhancements
6 | * The `predict()` method now computes standard errors for probabilities and logits using the delta method. These can be obtained for either the response probabilities (and equivalent logits) or for the predicted log odds of the individual dichotomies.
7 | * A `confint()` method for the result of `predict()` generates the corresponding confidence intervals.
8 | * `as.data.frame()` methods for predicted values, either for the nested logit model or for the separate dichotomies converts these to a data frame in long format, handy for using `ggplot()`.
9 | * Added a `confint()` method for predicted probabilities and logits
10 | * The `plot()` method for `"nestedLogit"` objects now plots confidence intervals for predicted probabilities.
11 | * A new vignette, "standard-errors", describes the mathematics behind the standard error calculations.
12 | * An old vignette on plotting methods was completely re-written using the new `predict()` methods and focusing exclusively on `ggplot2().
13 |
14 | ## Other
15 | * Added an example of `lobstr::tree()` to print nested lists
16 | * Now use `fig.show="hold"` to keep `par(op)` with the code.
17 |
18 | # nestedLogit 0.2.1
19 |
20 | * Reset all `par()` and `options()` calls so as to not alter user's workspace.
21 | * now document all return values.
22 | * added a reference to DESCRIPTION. It is a book, so no doi:, url, etc.
23 | * fixed one URL that win-builder (spuriously) complains about.
24 |
25 |
26 | # nestedLogit 0.2.0
27 |
28 | * Now allow dichotomies to be specified by a nested (recursive) of binary splits of the categories [suggestion of Achim Zeileis]
29 | * The model object is now of class "nestedLogit" for uniformity.
30 | * A basic `plot()` method now operational
31 | * Added a `linearHypothesis()` method to give Wald tests for hypotheses about coefficients or their linear combinations.
32 | * Expanded vignette to illustrate some other methods.
33 | * Added a `models()` generic and method to extract separate models from the `"nestedLogit"` object
34 | * Added a `logLike()` method, and through it, gets `AIC()` and `BIC()`
35 | * Reorganized documentation to separate nested hypothesis methods.
36 |
37 | # nestedLogit 0.1.0
38 |
39 | * Initial version
40 | * Added a `NEWS.md` file to track changes to the package.
41 |
42 |
--------------------------------------------------------------------------------
/revdep/library/nestedLogit/old/nestedLogit/R/nestedLogit:
--------------------------------------------------------------------------------
1 | # File share/R/nspackloader.R
2 | # Part of the R package, https://www.R-project.org
3 | #
4 | # Copyright (C) 1995-2012 The R Core Team
5 | #
6 | # This program is free software; you can redistribute it and/or modify
7 | # it under the terms of the GNU General Public License as published by
8 | # the Free Software Foundation; either version 2 of the License, or
9 | # (at your option) any later version.
10 | #
11 | # This program is distributed in the hope that it will be useful,
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | # GNU General Public License for more details.
15 | #
16 | # A copy of the GNU General Public License is available at
17 | # https://www.r-project.org/Licenses/
18 |
19 | local({
20 | info <- loadingNamespaceInfo()
21 | pkg <- info$pkgname
22 | ns <- .getNamespace(as.name(pkg))
23 | if (is.null(ns))
24 | stop("cannot find namespace environment for ", pkg, domain = NA);
25 | dbbase <- file.path(info$libname, pkg, "R", pkg)
26 | lazyLoad(dbbase, ns, filter = function(n) n != ".__NAMESPACE__.")
27 | })
28 |
--------------------------------------------------------------------------------
/revdep/library/nestedLogit/old/nestedLogit/R/nestedLogit.rdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/revdep/library/nestedLogit/old/nestedLogit/R/nestedLogit.rdb
--------------------------------------------------------------------------------
/revdep/library/nestedLogit/old/nestedLogit/R/nestedLogit.rdx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/revdep/library/nestedLogit/old/nestedLogit/R/nestedLogit.rdx
--------------------------------------------------------------------------------
/revdep/library/nestedLogit/old/nestedLogit/WORDLIST:
--------------------------------------------------------------------------------
1 | Analytics
2 | anova
3 | Anova
4 | aspx
5 | boldsymbol
6 | carData
7 | cdots
8 | continuationLogits
9 | CRC
10 | dichotomize
11 | df
12 | doi
13 | Fienberg
14 | frac
15 | fulltime
16 | ggplot
17 | gradeschool
18 | GSS
19 | https
20 | ij
21 | im
22 | jk
23 | ldots
24 | Lifecycle
25 | McNulty
26 | newdata
27 | NORC
28 | norc
29 | nnet
30 | Weisberg
31 | highschool
32 | hincome
33 | linearHypothesis
34 | mathbf
35 | mathcal
36 | nd
37 | ne
38 | operatorname
39 | partic
40 | parttime
41 | polytomy
42 | predictNestedLogit
43 | recoding
44 | repo
45 | summarising
46 | tibbles
47 | th
48 | vec
49 | widehat
50 | womens
51 | Womenlf
52 | www
53 | Monette
54 | subseteq
55 |
56 |
--------------------------------------------------------------------------------
/revdep/library/nestedLogit/old/nestedLogit/data/Rdata.rdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/revdep/library/nestedLogit/old/nestedLogit/data/Rdata.rdb
--------------------------------------------------------------------------------
/revdep/library/nestedLogit/old/nestedLogit/data/Rdata.rds:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/revdep/library/nestedLogit/old/nestedLogit/data/Rdata.rds
--------------------------------------------------------------------------------
/revdep/library/nestedLogit/old/nestedLogit/data/Rdata.rdx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/revdep/library/nestedLogit/old/nestedLogit/data/Rdata.rdx
--------------------------------------------------------------------------------
/revdep/library/nestedLogit/old/nestedLogit/doc/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | R: Vignettes and other documentation
4 |
5 |
6 |
7 |
8 |
Vignettes and other documentation
9 |
10 |
11 |
12 |
13 |
![[Top]](/doc/html/up.jpg)
14 |
15 |
Vignettes from package 'nestedLogit'
16 |
39 |
40 |
--------------------------------------------------------------------------------
/revdep/library/nestedLogit/old/nestedLogit/help/AnIndex:
--------------------------------------------------------------------------------
1 | Anova.nestedLogit nestedHypotheses
2 | anova.nestedLogit nestedHypotheses
3 | as.character.dichotomies nestedMethods
4 | as.data.frame.predictNestedLogit as.data.frame.predictNestedLogit
5 | as.dichotomies nestedMethods
6 | as.dichotomies.matrix nestedMethods
7 | as.matrix.continuationDichotomies nestedMethods
8 | as.matrix.dichotomies nestedMethods
9 | broomMethods broomMethods
10 | coef.nestedLogit nestedMethods
11 | confint.predictNestedLogit nestedMethods
12 | continuationLogits nestedLogit
13 | dichotomy nestedLogit
14 | fitted.nestedLogit nestedMethods
15 | glance.nestedLogit broomMethods
16 | GSS GSS
17 | HealthInsurance HealthInsurance
18 | linearHypothesis.nestedLogit nestedHypotheses
19 | logits nestedLogit
20 | logLik.nestedLogit nestedHypotheses
21 | models models
22 | models.nestedLogit models
23 | nestedHypotheses nestedHypotheses
24 | nestedLogit nestedLogit
25 | nestedMethods nestedMethods
26 | plot.nestedLogit plot.nestedLogit
27 | predict.nestedLogit nestedMethods
28 | print.Anova.nestedLogit nestedHypotheses
29 | print.anova.nestedLogit nestedHypotheses
30 | print.dichotomies nestedMethods
31 | print.nestedLogit nestedMethods
32 | print.predictDichotomies nestedMethods
33 | print.predictNestedLogit nestedMethods
34 | print.summary.nestedLogit nestedMethods
35 | summary.nestedLogit nestedMethods
36 | tidy.nestedLogit broomMethods
37 | update.nestedLogit nestedMethods
38 | vcov.nestedLogit nestedMethods
39 |
--------------------------------------------------------------------------------
/revdep/library/nestedLogit/old/nestedLogit/help/aliases.rds:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/revdep/library/nestedLogit/old/nestedLogit/help/aliases.rds
--------------------------------------------------------------------------------
/revdep/library/nestedLogit/old/nestedLogit/help/figures/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/revdep/library/nestedLogit/old/nestedLogit/help/figures/logo.png
--------------------------------------------------------------------------------
/revdep/library/nestedLogit/old/nestedLogit/help/nestedLogit.rdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/revdep/library/nestedLogit/old/nestedLogit/help/nestedLogit.rdb
--------------------------------------------------------------------------------
/revdep/library/nestedLogit/old/nestedLogit/help/nestedLogit.rdx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/revdep/library/nestedLogit/old/nestedLogit/help/nestedLogit.rdx
--------------------------------------------------------------------------------
/revdep/library/nestedLogit/old/nestedLogit/help/paths.rds:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/revdep/library/nestedLogit/old/nestedLogit/help/paths.rds
--------------------------------------------------------------------------------
/revdep/library/nestedLogit/old/nestedLogit/html/R.css:
--------------------------------------------------------------------------------
1 | @media screen {
2 | .container {
3 | padding-right: 10px;
4 | padding-left: 10px;
5 | margin-right: auto;
6 | margin-left: auto;
7 | max-width: 900px;
8 | }
9 | }
10 |
11 | .rimage img { /* from knitr - for examples and demos */
12 | width: 96%;
13 | margin-left: 2%;
14 | }
15 |
16 | .katex { font-size: 1.1em; }
17 |
18 | code {
19 | color: inherit;
20 | background: inherit;
21 | }
22 |
23 | body {
24 | line-height: 1.4;
25 | background: white;
26 | color: black;
27 | }
28 |
29 | a:link {
30 | background: white;
31 | color: blue;
32 | }
33 |
34 | a:visited {
35 | background: white;
36 | color: rgb(50%, 0%, 50%);
37 | }
38 |
39 | h1 {
40 | background: white;
41 | color: rgb(55%, 55%, 55%);
42 | font-family: monospace;
43 | font-size: 1.4em; /* x-large; */
44 | text-align: center;
45 | }
46 |
47 | h2 {
48 | background: white;
49 | color: rgb(40%, 40%, 40%);
50 | font-family: monospace;
51 | font-size: 1.2em; /* large; */
52 | text-align: center;
53 | }
54 |
55 | h3 {
56 | background: white;
57 | color: rgb(40%, 40%, 40%);
58 | font-family: monospace;
59 | font-size: 1.2em; /* large; */
60 | }
61 |
62 | h4 {
63 | background: white;
64 | color: rgb(40%, 40%, 40%);
65 | font-family: monospace;
66 | font-style: italic;
67 | font-size: 1.2em; /* large; */
68 | }
69 |
70 | h5 {
71 | background: white;
72 | color: rgb(40%, 40%, 40%);
73 | font-family: monospace;
74 | }
75 |
76 | h6 {
77 | background: white;
78 | color: rgb(40%, 40%, 40%);
79 | font-family: monospace;
80 | font-style: italic;
81 | }
82 |
83 | img.toplogo {
84 | width: 4em;
85 | vertical-align: middle;
86 | }
87 |
88 | img.arrow {
89 | width: 30px;
90 | height: 30px;
91 | border: 0;
92 | }
93 |
94 | span.acronym {
95 | font-size: small;
96 | }
97 |
98 | span.env {
99 | font-family: monospace;
100 | }
101 |
102 | span.file {
103 | font-family: monospace;
104 | }
105 |
106 | span.option{
107 | font-family: monospace;
108 | }
109 |
110 | span.pkg {
111 | font-weight: bold;
112 | }
113 |
114 | span.samp{
115 | font-family: monospace;
116 | }
117 |
118 | div.vignettes a:hover {
119 | background: rgb(85%, 85%, 85%);
120 | }
121 |
--------------------------------------------------------------------------------
/revdep/problems.md:
--------------------------------------------------------------------------------
1 | *Wow, no problems at all. :)*
--------------------------------------------------------------------------------
/tests/spelling.R:
--------------------------------------------------------------------------------
1 | if(requireNamespace('spelling', quietly = TRUE))
2 | spelling::spell_check_test(vignettes = TRUE, error = FALSE,
3 | skip_on_cran = TRUE)
4 |
--------------------------------------------------------------------------------
/tests/testthat.R:
--------------------------------------------------------------------------------
1 | library(testthat)
2 | library(nestedLogit)
3 |
4 | test_check("nestedLogit")
5 |
--------------------------------------------------------------------------------
/tests/testthat/test-Effect-method.R:
--------------------------------------------------------------------------------
1 | # test that Effect.nestedLogit() correctly computes effects and their SEs
2 |
3 | data(Womenlf, package = "carData")
4 |
5 | m <- nestedLogit(partic ~ hincome + children,
6 | logits(work=dichotomy("not.work", c("parttime", "fulltime")),
7 | full=dichotomy("parttime", "fulltime")),
8 | data=Womenlf)
9 |
10 | eff.1 <- Effect("children", m)
11 | new <- eff.1$x
12 | new$hincome <- mean(Womenlf$hincome)
13 | pred.1 <- predict(m, newdata=new)
14 | test_that("Effects are computed correctly for a numeric predictor", {
15 | expect_equal(as.vector(eff.1$prob),
16 | as.vector(as.matrix(pred.1$p)))
17 | })
18 | test_that("Effect SEs are computed correctly for a numeric predictor", {
19 | expect_equal(as.vector(eff.1$se.prob),
20 | as.vector(as.matrix(pred.1$se.p)))
21 | })
22 |
23 | Womenlf$kids <- with(Womenlf, ifelse(children == "present", 1, 0))
24 | mm <- update(m, . ~ . - children + kids, data=Womenlf)
25 | eff.2 <- Effect("hincome", m)
26 | new <- eff.2$x
27 | new$kids <- mean(Womenlf$kids)
28 | pred.2 <- predict(mm, newdata=new)
29 | test_that("Effects are computed correctly for a factor predictor", {
30 | expect_equal(as.vector(eff.2$prob),
31 | as.vector(as.matrix(pred.2$p)))
32 | })
33 | test_that("Effect SEs are computed correctly for a factor predictor", {
34 | expect_equal(as.vector(eff.2$se.prob),
35 | as.vector(as.matrix(pred.2$se.p)))
36 | })
37 |
--------------------------------------------------------------------------------
/tests/testthat/test-fitted-probs.R:
--------------------------------------------------------------------------------
1 | # test that nestedLogit()/predict.nestedLogit() correctly compute fitted probabilities
2 |
3 | m2 <- nestedLogit(degree ~ parentdeg + year,
4 | continuationLogits(c("l.t.highschool", "highschool",
5 | "college", "graduate")),
6 | data=GSS)
7 |
8 | new <- expand.grid(parentdeg=c("l.t.highschool", "highschool",
9 | "college", "graduate"),
10 | year=1972:2016)
11 | pred.GSS <- as.matrix(predict(m2, new)$p)
12 |
13 | p.m2.1 <- predict(models(m2, 1), newdata=new, type="response")
14 | p.m2.2 <- predict(models(m2, 2), newdata=new, type="response")
15 | p.m2.3 <- predict(models(m2, 3), newdata=new, type="response")
16 |
17 | test_that("fitted probabilities computed correctly, test 1", {
18 | expect_equal(1 - p.m2.1, pred.GSS[, "l.t.highschool"])
19 | })
20 |
21 | test_that("fitted probabilities computed correctly, test 2", {
22 | expect_equal(p.m2.1*(1 - p.m2.2), pred.GSS[, "highschool"])
23 | })
24 |
25 | test_that("fitted probabilities computed correctly, test 3", {
26 | expect_equal(p.m2.1*p.m2.2*(1 - p.m2.3), pred.GSS[, "college"])
27 | })
28 |
29 | test_that("fitted probabilities computed correctly, test 4", {
30 | expect_equal(p.m2.1*p.m2.2*p.m2.3, pred.GSS[, "graduate"])
31 | })
32 |
--------------------------------------------------------------------------------
/tests/testthat/test-model-update.R:
--------------------------------------------------------------------------------
1 | # test that update.nested() works properly
2 |
3 | data(Womenlf, package = "carData")
4 |
5 | m1 <- nestedLogit(partic ~ hincome,
6 | logits(work=dichotomy("not.work", c("parttime", "fulltime")),
7 | full=dichotomy("parttime", "fulltime")),
8 | data=Womenlf)
9 |
10 | m2 <- nestedLogit(partic ~ hincome + children,
11 | logits(work=dichotomy("not.work", c("parttime", "fulltime")),
12 | full=dichotomy("parttime", "fulltime")),
13 | data=Womenlf)
14 |
15 | m2a <- update(m1, . ~ . + children)
16 | test_that("update.nested() works correctly, formula arg", {
17 | expect_equal(coef(m2), coef(m2a))
18 | })
19 |
20 | Ontario <- Womenlf[Womenlf$region == "Ontario", ]
21 | m3 <- nestedLogit(partic ~ hincome + children,
22 | logits(work=dichotomy("not.work", c("parttime", "fulltime")),
23 | full=dichotomy("parttime", "fulltime")),
24 | data=Ontario)
25 | m3a <- update(m2, data=Ontario)
26 | test_that("update.nested() works correctly, data arg", {
27 | expect_equal(coef(m3), coef(m3a))
28 | })
29 |
30 | m4 <- nestedLogit(partic ~ hincome + children,
31 | logits(work=dichotomy("not.work", c("parttime", "fulltime")),
32 | full=dichotomy("parttime", "fulltime")),
33 | data=Womenlf,
34 | contrasts=list(children=contr.sum))
35 | m4a <- update(m2, contrasts=list(children=contr.sum))
36 | test_that("update.nested() works correctly, contrasts arg", {
37 | expect_equal(coef(m4), coef(m4a))
38 | })
39 |
40 | m5 <- nestedLogit(partic ~ hincome + children,
41 | logits(full=dichotomy(c("not.work", "parttime"), "fulltime"),
42 | part=dichotomy("not.work", "parttime")),
43 | data=Womenlf)
44 | m5a <- update(m2, dichotomies=logits(
45 | full=dichotomy(c("not.work", "parttime"), "fulltime"),
46 | part=dichotomy("not.work", "parttime")))
47 | test_that("update.nested() works correctly, dichotomies arg", {
48 | expect_equal(coef(m5), coef(m5a))
49 | })
50 |
--------------------------------------------------------------------------------
/tests/testthat/test-probs-SEs.R:
--------------------------------------------------------------------------------
1 | # test that predict.nestedLogit() correctly computes SEs of fitted probabilities
2 |
3 | m.gss <- nestedLogit(degree ~ parentdeg + year,
4 | continuationLogits(c("l.t.highschool", "highschool",
5 | "college", "graduate")),
6 | data=GSS)
7 |
8 | new <- expand.grid(parentdeg=c("l.t.highschool", "highschool",
9 | "college", "graduate"),
10 | year=seq(1972, 2016, length=5))
11 | pred.gss <- predict(m.gss, new)
12 |
13 | GSS$y1 <- with(GSS, ifelse(degree == "l.t.highschool", 0, 1))
14 | GSS$y2 <- with(GSS, ifelse(y1 == 0, NA,
15 | ifelse(degree == "highschool", 0, 1)))
16 | GSS$y3 <- with(GSS, ifelse(degree == "college", 0,
17 | ifelse(degree == "graduate", 1, NA)))
18 | m1 <- glm(y1 ~ parentdeg + year, data=GSS, family=binomial)
19 | m2 <- glm(y2 ~ parentdeg + year, data=GSS, family=binomial)
20 | m3 <- glm(y3 ~ parentdeg + year, data=GSS, family=binomial)
21 |
22 | pr1 <- predict(m1, newdata=new, type="response", se.fit=TRUE)
23 | p1 <- pr1$fit
24 | v1 <- (pr1$se.fit)^2
25 |
26 | pr2 <- predict(m2, newdata=new, type="response", se.fit=TRUE)
27 | p2 <- pr2$fit
28 | v2 <- (pr2$se.fit)^2
29 |
30 | pr3 <- predict(m3, newdata=new, type="response", se.fit=TRUE)
31 | p3 <- pr3$fit
32 | v3 <- (pr3$se.fit)^2
33 |
34 | se.p.a <- sqrt(v1)
35 | se.p.b <- sqrt((1 - p2)^2*v1 + p1^2*v2)
36 | se.p.c <- sqrt((p2*(1 - p3))^2*v1 + (p1*(1 - p3))^2*v2 + (p1*p2)^2*v3)
37 | se.p.d <- sqrt((p2*p3)^2*v1 + (p1*p3)^2*v2 + (p1*p2)^2*v3)
38 |
39 | test_that("SEs of fitted probabilities computed correctly", {
40 | expect_equal(as.vector(cbind(se.p.a, se.p.b, se.p.c, se.p.d)),
41 | as.vector(as.matrix(pred.gss$se.p)))
42 | })
43 |
--------------------------------------------------------------------------------
/vignettes/.gitignore:
--------------------------------------------------------------------------------
1 | *.html
2 | *.R
3 |
--------------------------------------------------------------------------------
/vignettes/fig/nested-ex.pptx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/vignettes/fig/nested-ex.pptx
--------------------------------------------------------------------------------
/vignettes/fig/nested-psychiatric.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/vignettes/fig/nested-psychiatric.png
--------------------------------------------------------------------------------
/vignettes/fig/nested-wlf.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/vignettes/fig/nested-wlf.png
--------------------------------------------------------------------------------
/vignettes/fig/nested.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/vignettes/fig/nested.jpg
--------------------------------------------------------------------------------
/vignettes/fig/wlf-alt-plot-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/vignettes/fig/wlf-alt-plot-1.png
--------------------------------------------------------------------------------
/vignettes/fig/wlf-directlabels-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/vignettes/fig/wlf-directlabels-1.png
--------------------------------------------------------------------------------
/vignettes/fig/wlf-effect-plot-1-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/vignettes/fig/wlf-effect-plot-1-1.png
--------------------------------------------------------------------------------
/vignettes/fig/wlf-effect-plot-2-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/vignettes/fig/wlf-effect-plot-2-1.png
--------------------------------------------------------------------------------
/vignettes/fig/wlf-geomtextpath-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/vignettes/fig/wlf-geomtextpath-1.png
--------------------------------------------------------------------------------
/vignettes/fig/wlf-gglogits-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/vignettes/fig/wlf-gglogits-1.png
--------------------------------------------------------------------------------
/vignettes/fig/wlf-ggplot-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/vignettes/fig/wlf-ggplot-1.png
--------------------------------------------------------------------------------
/vignettes/fig/wlf-ggplot-alt1-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/vignettes/fig/wlf-ggplot-alt1-1.png
--------------------------------------------------------------------------------
/vignettes/fig/wlf-ggplot-dichot1-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/vignettes/fig/wlf-ggplot-dichot1-1.png
--------------------------------------------------------------------------------
/vignettes/fig/wlf-ggplot-dichot2-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/vignettes/fig/wlf-ggplot-dichot2-1.png
--------------------------------------------------------------------------------
/vignettes/fig/wlf-ggplot-logit-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/vignettes/fig/wlf-ggplot-logit-1.png
--------------------------------------------------------------------------------
/vignettes/fig/wlf-ggplot-p1-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/vignettes/fig/wlf-ggplot-p1-1.png
--------------------------------------------------------------------------------
/vignettes/fig/wlf-ggplot-p2-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/vignettes/fig/wlf-ggplot-p2-1.png
--------------------------------------------------------------------------------
/vignettes/fig/wlf-logits-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/vignettes/fig/wlf-logits-1.png
--------------------------------------------------------------------------------
/vignettes/fig/wlf-matplot-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/vignettes/fig/wlf-matplot-1.png
--------------------------------------------------------------------------------
/vignettes/fig/wlf-plot-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/vignettes/fig/wlf-plot-1.png
--------------------------------------------------------------------------------
/vignettes/nested-psychiatric.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/vignettes/nested-psychiatric.png
--------------------------------------------------------------------------------
/vignettes/nested.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friendly/nestedLogit/261d84632db9977e5d995a168f6576e20ddd8b0c/vignettes/nested.jpg
--------------------------------------------------------------------------------
/vignettes/packages.bib:
--------------------------------------------------------------------------------
1 | @Manual{R-base,
2 | title = {R: A Language and Environment for Statistical Computing},
3 | author = {{R Core Team}},
4 | organization = {R Foundation for Statistical Computing},
5 | address = {Vienna, Austria},
6 | year = {2023},
7 | url = {https://www.R-project.org/},
8 | }
9 |
10 | @Manual{R-broom,
11 | title = {broom: Convert Statistical Objects into Tidy Tibbles},
12 | author = {David Robinson and Alex Hayes and Simon Couch},
13 | year = {2023},
14 | note = {R package version 1.0.5},
15 | url = {https://CRAN.R-project.org/package=broom},
16 | }
17 |
18 | @Manual{R-car,
19 | title = {car: Companion to Applied Regression},
20 | author = {John Fox and Sanford Weisberg and Brad Price},
21 | year = {2023},
22 | note = {R package version 3.1-2},
23 | url = {https://CRAN.R-project.org/package=car},
24 | }
25 |
26 | @Manual{R-carData,
27 | title = {carData: Companion to Applied Regression Data Sets},
28 | author = {John Fox and Sanford Weisberg and Brad Price},
29 | year = {2022},
30 | note = {R package version 3.0-5},
31 | url = {https://CRAN.R-project.org/package=carData},
32 | }
33 |
34 | @Manual{R-dplyr,
35 | title = {dplyr: A Grammar of Data Manipulation},
36 | author = {Hadley Wickham and Romain François and Lionel Henry and Kirill Müller and Davis Vaughan},
37 | year = {2023},
38 | note = {R package version 1.1.2},
39 | url = {https://CRAN.R-project.org/package=dplyr},
40 | }
41 |
42 | @Manual{R-effects,
43 | title = {effects: Effect Displays for Linear, Generalized Linear, and Other Models},
44 | author = {John Fox and Sanford Weisberg and Brad Price and Michael Friendly and Jangman Hong},
45 | year = {2022},
46 | note = {R package version 4.2-2},
47 | url = {https://CRAN.R-project.org/package=effects},
48 | }
49 |
50 | @Manual{R-geomtextpath,
51 | title = {geomtextpath: Curved Text in ggplot2},
52 | author = {Allan Cameron and Teun {van den Brand}},
53 | year = {2022},
54 | note = {R package version 0.1.1},
55 | url = {https://allancameron.github.io/geomtextpath/},
56 | }
57 |
58 | @Manual{R-ggeffects,
59 | title = {ggeffects: Create Tidy Data Frames of Marginal Effects for ggplot from
60 | Model Outputs},
61 | author = {Daniel Lüdecke},
62 | year = {2023},
63 | note = {R package version 1.2.3},
64 | url = {https://strengejacke.github.io/ggeffects/},
65 | }
66 |
67 | @Manual{R-ggplot2,
68 | title = {ggplot2: Create Elegant Data Visualisations Using the Grammar of Graphics},
69 | author = {Hadley Wickham and Winston Chang and Lionel Henry and Thomas Lin Pedersen and Kohske Takahashi and Claus Wilke and Kara Woo and Hiroaki Yutani and Dewey Dunnington},
70 | year = {2023},
71 | note = {R package version 3.4.2},
72 | url = {https://CRAN.R-project.org/package=ggplot2},
73 | }
74 |
75 | @Manual{R-knitr,
76 | title = {knitr: A General-Purpose Package for Dynamic Report Generation in R},
77 | author = {Yihui Xie},
78 | year = {2023},
79 | note = {R package version 1.43},
80 | url = {https://yihui.org/knitr/},
81 | }
82 |
83 | @Manual{R-nestedLogit,
84 | title = {nestedLogit: Nested Dichotomy Logistic Regression Models},
85 | author = {John Fox and Michael Friendly},
86 | year = {2023},
87 | note = {R package version 0.3.2},
88 | url = {https://github.com/friendly/nestedLogit},
89 | }
90 |
91 | @Manual{R-nnet,
92 | title = {nnet: Feed-Forward Neural Networks and Multinomial Log-Linear Models},
93 | author = {Brian Ripley},
94 | year = {2023},
95 | note = {R package version 7.3-19},
96 | url = {http://www.stats.ox.ac.uk/pub/MASS4/},
97 | }
98 |
99 | @Book{car2019,
100 | title = {An {R} Companion to Applied Regression},
101 | edition = {Third},
102 | author = {John Fox and Sanford Weisberg},
103 | year = {2019},
104 | publisher = {Sage},
105 | address = {Thousand Oaks {CA}},
106 | url = {https://socialsciences.mcmaster.ca/jfox/Books/Companion/},
107 | }
108 |
109 | @Book{effects2019,
110 | title = {An R Companion to Applied Regression},
111 | edition = {3rd},
112 | author = {John Fox and Sanford Weisberg},
113 | year = {2019},
114 | publisher = {Sage},
115 | address = {Thousand Oaks CA},
116 | url = {https://socialsciences.mcmaster.ca/jfox/Books/Companion/index.html},
117 | }
118 |
119 | @Article{effects2018,
120 | title = {Visualizing Fit and Lack of Fit in Complex Regression Models with Predictor Effect Plots and Partial Residuals},
121 | author = {John Fox and Sanford Weisberg},
122 | journal = {Journal of Statistical Software},
123 | year = {2018},
124 | volume = {87},
125 | number = {9},
126 | pages = {1--27},
127 | doi = {10.18637/jss.v087.i09},
128 | }
129 |
130 | @Article{effects2003,
131 | title = {Effect Displays in {R} for Generalised Linear Models},
132 | author = {John Fox},
133 | journal = {Journal of Statistical Software},
134 | year = {2003},
135 | volume = {8},
136 | number = {15},
137 | pages = {1--27},
138 | doi = {10.18637/jss.v008.i15},
139 | }
140 |
141 | @Article{effects2009,
142 | title = {Effect Displays in {R} for Multinomial and Proportional-Odds Logit Models: Extensions to the {effects} Package},
143 | author = {John Fox and Jangman Hong},
144 | journal = {Journal of Statistical Software},
145 | year = {2009},
146 | volume = {32},
147 | number = {1},
148 | pages = {1--24},
149 | doi = {10.18637/jss.v032.i01},
150 | }
151 |
152 | @Article{ggeffects2018,
153 | title = {ggeffects: Tidy Data Frames of Marginal Effects from Regression Models.},
154 | volume = {3},
155 | doi = {10.21105/joss.00772},
156 | number = {26},
157 | journal = {Journal of Open Source Software},
158 | author = {Daniel Lüdecke},
159 | year = {2018},
160 | pages = {772},
161 | }
162 |
163 | @Book{ggplot22016,
164 | author = {Hadley Wickham},
165 | title = {ggplot2: Elegant Graphics for Data Analysis},
166 | publisher = {Springer-Verlag New York},
167 | year = {2016},
168 | isbn = {978-3-319-24277-4},
169 | url = {https://ggplot2.tidyverse.org},
170 | }
171 |
172 | @Book{knitr2015,
173 | title = {Dynamic Documents with {R} and knitr},
174 | author = {Yihui Xie},
175 | publisher = {Chapman and Hall/CRC},
176 | address = {Boca Raton, Florida},
177 | year = {2015},
178 | edition = {2nd},
179 | note = {ISBN 978-1498716963},
180 | url = {https://yihui.org/knitr/},
181 | }
182 |
183 | @InCollection{knitr2014,
184 | booktitle = {Implementing Reproducible Computational Research},
185 | editor = {Victoria Stodden and Friedrich Leisch and Roger D. Peng},
186 | title = {knitr: A Comprehensive Tool for Reproducible Research in {R}},
187 | author = {Yihui Xie},
188 | publisher = {Chapman and Hall/CRC},
189 | year = {2014},
190 | note = {ISBN 978-1466561595},
191 | }
192 |
193 | @Book{nnet2002,
194 | title = {Modern Applied Statistics with S},
195 | author = {W. N. Venables and B. D. Ripley},
196 | publisher = {Springer},
197 | edition = {Fourth},
198 | address = {New York},
199 | year = {2002},
200 | note = {ISBN 0-387-95457-0},
201 | url = {https://www.stats.ox.ac.uk/pub/MASS4/},
202 | }
203 |
204 |
--------------------------------------------------------------------------------
/vignettes/references.bib:
--------------------------------------------------------------------------------
1 | @Misc{Atkinson-etal:1984,
2 | author = {Atkinson, Tom and Blishen, Bernard R. and Ornstein, Michael D. and Stevenson, H. Michael},
3 | title = {{Quality of Canadian Life: Social Change in Canada}, 1977},
4 | year = {1984},
5 | doi = {10.3886/ICPSR07879.V1},
6 | language = {en},
7 | publisher = {ICPSR - Interuniversity Consortium for Political and Social Research},
8 | }
9 |
10 | @book{Fienberg:80,
11 | Address = {Cambridge, MA},
12 | Author = {S. E. Fienberg},
13 | Edition = {Second edition},
14 | Isbn = {0-262-06071-X},
15 | Lccn = {QA 278.F53 1980},
16 | Publisher = {MIT Press},
17 | Title = {The Analysis of Cross-Classified Categorical Data},
18 | Year = {1980}}
19 |
20 | @article{Fox:03:effects,
21 | Author = {Fox, John},
22 | Journal = {Journal of Statistical Software},
23 | Number = 15,
24 | Pages = {1--27},
25 | Title = {Effect displays in {R} for generalized linear models},
26 | Volume = 8,
27 | Year = {2003}
28 | }
29 |
30 | @book{Fox:2016:ARA,
31 | author = {Fox, John},
32 | title = {Applied Regression Analysis and Generalized Linear Models},
33 | publisher = {SAGE},
34 | address = {Thousand Oaks {CA}},
35 | isbn = {1452205663},
36 | year = {2016},
37 | edition = {Third edition},
38 | language = {eng},
39 | lccn = {2014959146},
40 | url = {https://www.john-fox.ca/AppliedRegression/index.html}
41 | }
42 |
43 | @book{FoxWeisberg:2011,
44 | Address = {Thousand Oaks {CA}},
45 | Author = {John Fox and Sandford Weisberg},
46 | Edition = {Second edition},
47 | Publisher = {Sage},
48 | Title = {An {R} Companion to Applied Regression},
49 | Url = {https://www.john-fox.ca/Companion/index.html},
50 | Year = {2011},
51 | Bdsk-Url-1 = {https://www.john-fox.ca/Companion/index.html}}
52 |
53 | @book{FriendlyMeyer:2016:DDAR,
54 | Author = {Michael Friendly and Meyer, David},
55 | Title = {Discrete Data Analysis with {R}: Visualization and Modeling Techniques for Categorical and Count Data},
56 | Address = {Boca Raton, FL},
57 | Isbn = {978-1-4987-2583-5},
58 | Publisher = {Chapman \& Hall/CRC},
59 | Year = {2016}
60 | }
61 |
62 | @Book{FoxWeisberg:2019:CAR,
63 | title = {An {R} Companion to Applied Regression},
64 | edition = {Third edition},
65 | author = {John Fox and Sanford Weisberg},
66 | year = {2019},
67 | publisher = {Sage},
68 | address = {Thousand Oaks {CA}},
69 | url = {https://www.john-fox.ca/Companion/index.html},
70 | }
71 |
72 | @Book{Fox:1984:LSM,
73 | title="Linear Statistical Models and Related Methods",
74 | author={John Fox},
75 | year={1984},
76 | publisher={Wiley},
77 | address={New York}
78 | }
79 |
80 | @Manual{R-equatiomatic,
81 | title = {equatiomatic: Transform Models into LaTeX Equations},
82 | author = {Daniel Anderson and Andrew Heiss and Jay Sumners},
83 | year = {2023},
84 | note = {https://github.com/datalorax/equatiomatic},
85 | }
86 |
87 | @Book{Fox:2021:Primer,
88 | title = {A Mathematical Primer for Social Statistics},
89 | edition = {Second edition},
90 | author = {John Fox},
91 | year = {2021},
92 | publisher = {Sage},
93 | address = {Thousand Oaks {CA}},
94 | url = {https://www.john-fox.ca/MathPrimer/index.html},
95 | }
96 |
97 |
--------------------------------------------------------------------------------