{"id":24629515,"url":"https://github.com/stufield/power","last_synced_at":"2025-03-20T04:35:49.762Z","repository":{"id":142778181,"uuid":"485490487","full_name":"stufield/power","owner":"stufield","description":"Informal suite of functions to calculate simple power calculations via p-value simulation.","archived":false,"fork":false,"pushed_at":"2024-12-09T23:14:44.000Z","size":1074,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-25T06:13:07.006Z","etag":null,"topics":["power","pvalue","r","typeii"],"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/stufield.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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-04-25T18:35:03.000Z","updated_at":"2024-12-09T23:14:48.000Z","dependencies_parsed_at":null,"dependency_job_id":"b5e47a5e-caa6-433f-802f-f62166803b5b","html_url":"https://github.com/stufield/power","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stufield%2Fpower","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stufield%2Fpower/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stufield%2Fpower/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stufield%2Fpower/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stufield","download_url":"https://codeload.github.com/stufield/power/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244554042,"owners_count":20471172,"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":["power","pvalue","r","typeii"],"created_at":"2025-01-25T06:13:10.443Z","updated_at":"2025-03-20T04:35:49.745Z","avatar_url":"https://github.com/stufield.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"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}\noptions(width = 100)\nSys.setlocale(\"LC_COLLATE\", \"en_US.UTF-8\") # ensure common sorting envir\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\",\n  out.width = \"100%\"\n)\nver \u003c- desc::desc_get_version(\".\")\nver \u003c- paste0(\"https://img.shields.io/badge/Version-\", ver,\n              \"-success.svg?style=flat\u0026logo=github\")\n```\n\n# The power package\n\n\u003c!-- badges: start --\u003e\n![GitHub version](`r ver`)\n[![CRAN status](http://www.r-pkg.org/badges/version/power)](https://cran.r-project.org/package=power)\n[![R-CMD-check](https://github.com/stufield/power/workflows/R-CMD-check/badge.svg)](https://github.com/stufield/power/actions)\n[![](https://cranlogs.r-pkg.org/badges/grand-total/power)](https://cran.r-project.org/package=power)\n[![Codecov test coverage](https://codecov.io/gh/stufield/power/branch/main/graph/badge.svg)](https://app.codecov.io/gh/stufield/power?branch=main)\n[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://choosealicense.com/licenses/mit/)\n[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)\n\u003c!-- badges: end --\u003e\n\n\nThe `power` package contains some simple functions to empirically\nsimulate and estimate statistical power under various statistical\ntest conditions. In general, simulations are performed with *known*\neffect sizes or differences, and the proportion of detected significant\n*p*-values represents the empirical power, i.e. $1 - \\beta$ or \n`1 - TypeII` error.\n\nThe goal is typically get an idea of the required sample size\ngiven an experimental design, statistical test, effect size, and \ndesired power.\n\n\n---------------\n\n\n## Installation\n\nThe `power` package is not currently on [CRAN](https://CRAN.R-project.org)\nbut you can install the latest version from \n[github](https://github.com/stufield/power) via:\n\n```{r install-github, eval = FALSE}\nremotes::install_github(\"stufield/power\")\n```\n\n\n## Loading `power`\n\nLoading the `power` package is as simple as:\n\n```{r load}\nlibrary(power)\n```\n\n\n## Plot power curves\n\nThe simplest way to generally plot power curves is via `plot_power_curves()`\nwhich uses `power.t.test()` under the hood:\n\n```{r plot-power-curves, fig.height = 6, fig.width = 11}\nplot_power_curves(\n  delta_vec = seq(0.5, 2, 0.1),\n  power_vec = seq(0.5, 0.9, 0.1)\n)\n```\n\n## Power curves and KS-distance\n\nThere is a loose \"rule-of-thumb\" relationship between Sensitivity/Specificity\nand KS-distance, and of course, KS is related to effect size. So we\ncan visualize this relationship also via a standard power curve:\n\n```{r ks-curves, fig.height = 6, fig.width = 11}\nks_tables \u003c- ks_power_table()\nks_tables\n\n# `power` as y-axis\nplot(ks_tables)\n\n# `n` as y-axis\nplot(ks_tables, plot_power = FALSE)\n```\n\n\n-------------\n\n\n## Two-Groups\n### Empirical Power via Simulation\n\nA more robust (?) empirical calculation of power can be\ngenerated via simulation:\n\n```{r power-curve-n, fig.height = 6, fig.width = 11}\n# constant effect size (delta)\nsize_tbl \u003c- withr::with_seed(1,\n  t_power_curve(seq(10, 50, 2), delta = 0.75, nsim = 25L)\n)\nsize_tbl\n\nplot(size_tbl)\n```\n\n```{r power-curve-d, fig.height = 6, fig.width = 11}\n# constant sample size (n)\ndelta_tbl \u003c- withr::with_seed(2,\n  t_power_curve(seq(0.5, 2.5, 0.1), n = 10, nsim = 25L)\n)\ndelta_tbl\n\nplot(delta_tbl)\n```\n\n### Solve for Sample Size\n\nTo solve for the sample size given a corresponding power value\nyou must have simulate power keeping \"delta\" (effect size) constant\nand varying `n`. For example, the `size_tbl` object created above:\n\n```{r solve-n}\nsolve_n(size_tbl, 0.8)\n```\n\n\n\n## Fisher's Exact for Count Data\n\nFor count data, Fisher's Exact tests assume a 2x2 contingency \nmatrix and equal proportions across the margins (rows x cols):\n\n```{r fisher-power}\nfisher_power(0.85, 0.75, 200, 200, nsim = 200L)\n```\n\n### Fisher's Power Curve\n\n```{r fisher-curve}\nf_tbl \u003c- fisher_power_curve(seq(50, 400, 5), p = 0.85, p_diff = -0.1,\n                            nsim = 200L)\nf_tbl\n```\n\n\n### Plot the Power Curve\n```{r plot-fisher-curve, fig.height = 6, fig.width = 11}\ngg_pwr \u003c- plot(f_tbl)\ngg_pwr\n```\n\n### Solve for `n`\n\n```{r solve-n-fisher}\npwr_n \u003c- solve_n(f_tbl, 0.8)\npwr_n\n```\n\n\nVisually check the curve and add the solution to the `ggplot`.\n\n\n```{r plot-fisher-curve2, fig.height = 6, fig.width = 11}\ngg_pwr +\n  ggplot2::annotate(\"segment\",\n    x        = c(pwr_n[[\"n\"]], min(f_tbl$n)),\n    xend     = c(pwr_n[[\"n\"]],pwr_n[[\"n\"]]),\n    y        = c(min(f_tbl$power), pwr_n[[\"power\"]]),\n    yend     = c(pwr_n[[\"power\"]], pwr_n[[\"power\"]]),\n    linetype = \"dashed\", colour = \"#00A499\")\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstufield%2Fpower","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstufield%2Fpower","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstufield%2Fpower/lists"}