{"id":14068293,"url":"https://github.com/EvilGRAHAM/flatr","last_synced_at":"2025-07-30T03:32:46.500Z","repository":{"id":172279747,"uuid":"109433036","full_name":"EvilGRAHAM/flatr","owner":"EvilGRAHAM","description":"Tidy and analyse contingency tables","archived":false,"fork":false,"pushed_at":"2018-02-21T22:17:39.000Z","size":38191,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-12-04T09:39:12.658Z","etag":null,"topics":["contingency-table","glm","r","regression","tidy","tidy-data"],"latest_commit_sha":null,"homepage":"","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/EvilGRAHAM.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2017-11-03T19:05:49.000Z","updated_at":"2020-09-30T23:29:28.000Z","dependencies_parsed_at":"2023-07-06T13:45:10.025Z","dependency_job_id":null,"html_url":"https://github.com/EvilGRAHAM/flatr","commit_stats":{"total_commits":39,"total_committers":1,"mean_commits":39.0,"dds":0.0,"last_synced_commit":"0bf60878ea3a2e412f093401746927801b9d5d83"},"previous_names":["evilgraham/flatr"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/EvilGRAHAM/flatr","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EvilGRAHAM%2Fflatr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EvilGRAHAM%2Fflatr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EvilGRAHAM%2Fflatr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EvilGRAHAM%2Fflatr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/EvilGRAHAM","download_url":"https://codeload.github.com/EvilGRAHAM/flatr/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EvilGRAHAM%2Fflatr/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267803984,"owners_count":24146527,"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","status":"online","status_checked_at":"2025-07-30T02:00:09.044Z","response_time":70,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["contingency-table","glm","r","regression","tidy","tidy-data"],"created_at":"2024-08-13T07:06:04.742Z","updated_at":"2025-07-30T03:32:46.129Z","avatar_url":"https://github.com/EvilGRAHAM.png","language":"R","funding_links":[],"categories":["R"],"sub_categories":[],"readme":"---\noutput:\n  md_document:\n    variant: markdown_github\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r, echo = FALSE, include = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"README-\"\n)\nlibrary(flatr)\ndata(\"lung_cancer\")\n```\n\n# flatr \u003cimg src=\"man/figures/logo.png\" align=\"right\" /\u003e\n[![Travis-CI Build Status](https://travis-ci.org/EvilGRAHAM/flatr.svg?branch=master)](https://travis-ci.org/EvilGRAHAM/flatr)\n\n## Overview\n`flatr` is a package designed to make the analysis of contingency tables easier. \n\nContingency tables are a popular means of presenting categorical data in textbooks, as they take up very little space, while still allowing to present all the data. However, this means makes it tough to run analysis on them. `flatr` helps ease this pain by turning $i \\times j \\times k$ contingency tables into \"tidy\" data. \n\n## Functions\n* `flatten_ct()` takes an $i \\times j \\times k$ contingency table, and turns it into a tibble.\n\n* `goodness_of_fit()` takes a logistic or probit regression model, and does a $\\chi^{2}$ Goodness of Fit Test. The test statistic is one of:\n\n  + ![Chi Squared Equation](https://latex.codecogs.com/gif.latex?%5Cchi%5E%7B2%7D%20%3D%20%5Csum_%7B%5Cforall%20i%2Cj%7D%5Cfrac%7B%5Cleft%28%20O_%7Bi%2Cj%7D%20-%20E_%7Bi%2Cj%7D%20%5Cright%29%5E%7B2%7D%7D%7BE_%7Bi%2Cj%7D%7D)\n\n  + ![G Squared Equation](https://latex.codecogs.com/gif.latex?G%5E%7B2%7D%20%3D%202%5Csum_%7B%5Cforall%20i%2Cj%7DO_%7Bi%2Ci%7D%20%5Cln%5Cleft%28%20%5Cfrac%7BO_%7Bi%2Ci%7D%7D%7BE_%7Bi%2Ci%7D%7D%20%5Cright%29)\n\n## Tidy Data\n`flatr` is designed to work with the [tidyverse](https://www.tidyverse.org/) series of packages. Tidy data is data in a \"long\" format, where each variable has its own column.\n\n## Usage\n| Beijing | Lung |     |\n|--------:|------|-----|\n| Smoking | Yes  | No  |\n|     Yes | 126  | 100 |\n|      No | 35   | 61  |\n\n| Shanghai | Lung |     |\n|---------:|------|-----|\n|  Smoking | Yes  | No  |\n|      Yes | 908  | 688 |\n|       No | 497  | 807 |\n\n| Shenyang | Lung |     |\n|---------:|------|-----|\n|  Smoking | Yes  | No  |\n|      Yes | 913  | 747 |\n|       No | 336  | 598 |\n\n| Nanjing | Lung |     |\n|--------:|------|-----|\n| Smoking | Yes  | No  |\n|     Yes | 235  | 172 |\n|      No | 58   | 121 |\n\n|  Harbin | Lung |     |\n|--------:|------|-----|\n| Smoking | Yes  | No  |\n|     Yes | 402  | 308 |\n|      No | 121  | 215 |\n\n| Zhengzhou | Lung |     |\n|----------:|------|-----|\n|   Smoking | Yes  | No  |\n|       Yes | 182  | 156 |\n|        No | 72   | 98  |\n\n| Taiyuan | Lung |    |\n|--------:|------|----|\n| Smoking | Yes  | No |\n|     Yes | 60   | 99 |\n|      No | 11   | 43 |\n\n| Nanchang | Lung |    |\n|---------:|------|----|\n|  Smoking | Yes  | No |\n|      Yes | 104  | 89 |\n|       No | 21   | 36 |\n```{r message = FALSE}\nlung_tidy \u003c- flatten_ct(lung_cancer)\nlung_tidy\n\nlung_logit \u003c- glm(Lung ~ Smoking + City, family = binomial, data = lung_tidy)\ngoodness_of_fit(model = lung_logit, response = \"Lung\", type = \"Chisq\")\n\nlung_tidy %\u003e% \n  glm(\n    Lung ~ Smoking + City\n    ,family = binomial(link = \"probit\")\n    ,data = .\n  ) %\u003e% \n  goodness_of_fit(response = \"Lung\", type = \"Gsq\")\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FEvilGRAHAM%2Fflatr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FEvilGRAHAM%2Fflatr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FEvilGRAHAM%2Fflatr/lists"}