{"id":13686798,"url":"https://github.com/friendly/nestedLogit","last_synced_at":"2025-05-01T12:31:26.377Z","repository":{"id":154963317,"uuid":"629096343","full_name":"friendly/nestedLogit","owner":"friendly","description":"Nested Dichotomy Logistic Regression Models","archived":false,"fork":false,"pushed_at":"2024-07-13T01:19:52.000Z","size":7567,"stargazers_count":10,"open_issues_count":2,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-11-06T05:20:33.376Z","etag":null,"topics":["logistic-regression","multinomial-logistic-regression","polytomous-variables","r-package"],"latest_commit_sha":null,"homepage":"https://friendly.github.io/nestedLogit/","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/friendly.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-04-17T15:57:19.000Z","updated_at":"2024-06-03T14:47:28.000Z","dependencies_parsed_at":null,"dependency_job_id":"b7b58ce8-f154-415a-b986-7d105b821fee","html_url":"https://github.com/friendly/nestedLogit","commit_stats":{"total_commits":274,"total_committers":2,"mean_commits":137.0,"dds":0.3832116788321168,"last_synced_commit":"0fe4707575f11e0fedda45e3ce68762915fafd46"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/friendly%2FnestedLogit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/friendly%2FnestedLogit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/friendly%2FnestedLogit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/friendly%2FnestedLogit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/friendly","download_url":"https://codeload.github.com/friendly/nestedLogit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224257226,"owners_count":17281671,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["logistic-regression","multinomial-logistic-regression","polytomous-variables","r-package"],"created_at":"2024-08-02T15:00:40.139Z","updated_at":"2024-11-12T10:30:13.680Z","avatar_url":"https://github.com/friendly.png","language":"HTML","readme":"---\noutput: github_document\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r setup, include = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  warning = FALSE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\",\n  fig.height = 5,\n  fig.width = 5\n#  out.width = \"100%\"\n)\n\nlibrary(nestedLogit)\n```\n\n\u003c!-- badges: start --\u003e\n[![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable)\n[![Last Commit](https://img.shields.io/github/last-commit/friendly/nestedLogit)](https://github.com/friendly/nestedLogit)\n[![CRAN status](https://www.r-pkg.org/badges/version/nestedLogit)](https://cran.r-project.org/package=nestedLogit)\n[![Downloads](https://cranlogs.r-pkg.org/badges/nestedLogit?color=brightgreen)](https://www.r-pkg.org:443/pkg/nestedLogit)\n[![](https://img.shields.io/badge/pkgdown%20site-blue)](https://friendly.github.io/nestedLogit)\n\n\u003c!-- badges: end --\u003e\n\n# nestedLogit \u003cimg src=\"man/figures/logo.png\" style=\"float:right; height:200px;\" /\u003e\n**Version 0.3.3**\n\nThe `nestedLogit` package provides functions for fitting nested dichotomy logistic regression models\nfor a polytomous response. Nested dichotomies are statistically independent, and hence provide an\nadditive decomposition of tests for the overall polytomous response. When the dichotomies make\nsense substantively, this method can be a simpler alternative to the standard multinomial logistic model\nwhich compares response categories to a reference level.\n\n## Installation\n\n\n+-------------------+-----------------------------------------------------+\n| CRAN version      | `install.packages(\"nestedLogit\")`                   |\n+-------------------+-----------------------------------------------------+\n| Development       | `remotes::install_github(\"friendly/nestedLogit\")`   |\n| version           |                                                     |\n+-------------------+-----------------------------------------------------+\n\n\n\n\n## Package overview\n\nThe package provides one main function, `nestedLogit()` for fitting the set of $(m-1)$\nbinary logistic regression models for a polytomous response with $m$ levels.\nThese can be specified using helper functions,\n\n* `dichotomy()`: constructs a _single_ dichotomy among the levels of a response factor;\n* `logits()`: creates the set of dichotomies, typically using `dichotomy()` for each.\n* `continuationLogits()`: provides a convenient way to generate all dichotomies for an ordered response.\n\nFor instance, a 4-category response, with levels `r LETTERS[1:4]`, and successive binary splits\nfor the dichotomies of interest\ncould be specified as:\n\n\n```{r}\n(ABCD \u003c-\n  logits(AB.CD = dichotomy(c(\"A\", \"B\"), c(\"C\", \"D\")),\n           A.B = dichotomy(\"A\", \"B\"),\n           C.D = dichotomy(\"C\", \"D\")\n         )\n)\n```\n\nThese dichotomies are effectively a tree structure of lists, which can be displayed simply using\n`lobstr::tree()`.\n\n```{r tree}\nlobstr::tree(ABCD)\n```\n\n\nAlternatively, the nested dichotomies can be specified more compactly as a nested (i.e., recursive) list \nwith optionally named elements. For example, where people might choose a method of transportation\namong the categories `plane`, `train`, `bus`, `car`, a sensible set of three dichotomies could\nbe specified as:\n\n```{r transport}\ntransport \u003c- list(\n  air = \"plane\",\n  ground = list(\n    public = list(\"train\", \"bus\"),\n    private = \"car\"\n  ))\n\nlobstr::tree(transport)\n```\n\n\nThere are also methods including `as.matrix.dichotomies()`, `as.character.dichotomies()`\nto facilitate working with `dichotomies` objects in other representations. The `ABCD` example\nabove corresponds to the matrix below, whose rows represent the dichotomies and columns\nare the response levels:\n\n```{r}\nas.matrix(ABCD)\n\nas.character(ABCD)\n```\n\n\nThe result of `nestedLogit()` is an object of class `\"nestedLogit\"`. It contains\nthe set of $(m-1)$ `glm()` models fit to the dichotomies.\n\n### Methods\n\n```{r child=\"man/partials/methods.Rmd\"}\n```\n\n\n## Examples\n\nThis example uses data on women's labor force participation to fit a nested logit model for\nthe response, `partic`, representing categories\n`not.work`, `parttime` and `fulltime` for 263 women from a 1977\nsurvey in Canada. This dataset is explored in more detail in the\npackage vignette, `vignette(\"nestedLogits\", package = \"nestedLogit\")`.\n\nA model for the complete polytomy can be specified as two nested\ndichotomies, using helper functions `dichotomy()` and `logits()`, as shown in the example that follows:\n\n* `work`: {not.work} vs. {parttime, fulltime}\n* `full`: {parttime} vs. {fulltime}, but only for those working\n\n`nestedLogit()` effectively fits each of these dichotomies\nas logistic regression models via `glm(..., family = binomial)`\n\n```{r wlf-model}\ndata(Womenlf, package = \"carData\")\n\n# Use `logits()` and `dichotomy()` to specify the comparisons of interest\ncomparisons \u003c- logits(work=dichotomy(\"not.work\", \n                                     working=c(\"parttime\", \"fulltime\")),\n                      full=dichotomy(\"parttime\", \"fulltime\"))\n\nm \u003c- nestedLogit(partic ~ hincome + children,\n                 dichotomies = comparisons,\n                 data=Womenlf)\ncoef(m)\n```\nThe `\"nestedLogit\"` object contains the components of the fitted model. The structure can be shown nicely\nusing `lobstr::tree()`:\n\n```{r}\nm |\u003e lobstr::tree(max_depth=1)\n```\n\nThe separate models for the `work` and `full` dichotomies can be extracted via `models()`. These\nare the binomial `glm()` models.\n```{r}\nmodels(m) |\u003e lobstr::tree(max_depth = 1)\n```\n\n`Anova()` produces analysis of variance deviance tests for the terms in this model for each of the submodels, as well as for the combined responses of the polytomy. The `LR Chisq` and `df` for terms in the combined model are the sums of those for\nthe submodels.\n\n\n```{r wlf-anova}\ncar::Anova(m)\n```\n\n### Plots\nA basic plot of predicted probabilities can be produced using\nthe `plot()` method for `\"nestedLogit\"` objects.\nIt can be called several times to give multi-panel plots.\nBy default, a 95% pointwise confidence envelope is added to the plot.\nHere, they are plotted with `conf.level = 0.68` to give $\\pm 1$ std. error bounds.\n\n```{r wlf-plot}\n#| out.width = \"100%\",\n#| fig.asp = 0.55,\n#| echo = 1:3\nop \u003c- par(mfcol=c(1, 2), mar=c(4, 4, 3, 1) + 0.1)\nplot(m, \"hincome\", list(children=\"absent\"),\n     conf.level = 0.68,\n     xlab=\"Husband's Income\", legend=FALSE)\nplot(m, \"hincome\", list(children=\"present\"),\n     conf.level = 0.68,\n     xlab=\"Husband's Income\")\npar(op)\n```\n\n## Vignettes\n\n* A more general discussion of nested dichotomies logistic regression and detailed examples can be found \nin `vignette(\"nestedLogit\")`\n\n\n* A variety of other plots can be produced using `ggplot()`, as described in the vignette,\n`vignette(\"plotting-ggplot\")`.\n\n* A new vignette, \"`vignette(\"standard-errors\")`, describes the mathematics behind the calculation of\nstandard errors using the delta method.\n\n## Authors\n* John Fox\n* Michael Friendly\n\n## References\n\nS. Fienberg (1980) _The Analysis of Cross-Classified Categorical Data_, 2nd Edition, MIT Press, Section 6.6.\n\nJ. Fox (2016) _Applied Regression Analysis and Generalized Linear Models_, 3rd Edition, Sage, Section 14.2.2.\n\nM. Friendly and D. Meyers (2016) _Discrete Data Analysis with R_, CRC Press, Section 8.2.\n","funding_links":[],"categories":["HTML"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffriendly%2FnestedLogit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffriendly%2FnestedLogit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffriendly%2FnestedLogit/lists"}