{"id":26781953,"url":"https://github.com/mwt/rart","last_synced_at":"2026-03-07T22:04:13.298Z","repository":{"id":47158109,"uuid":"354948559","full_name":"mwt/rART","owner":"mwt","description":"R Package for Approximate Randomization Tests with a Small Number of Clusters","archived":false,"fork":false,"pushed_at":"2022-06-05T17:52:03.000Z","size":198,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-05-02T03:38:16.346Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mwt.png","metadata":{"files":{"readme":"README.md","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}},"created_at":"2021-04-05T19:27:35.000Z","updated_at":"2024-05-02T03:38:16.347Z","dependencies_parsed_at":"2022-08-29T16:31:00.350Z","dependency_job_id":null,"html_url":"https://github.com/mwt/rART","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/mwt%2FrART","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mwt%2FrART/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mwt%2FrART/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mwt%2FrART/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mwt","download_url":"https://codeload.github.com/mwt/rART/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246156456,"owners_count":20732410,"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":[],"created_at":"2025-03-29T08:18:54.825Z","updated_at":"2026-03-07T22:04:13.266Z","avatar_url":"https://github.com/mwt.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"# rART\n\nThe `rART` package provides functions for Approximate Randomization\nTests with a Small Number of Clusters introduced in “Randomization tests\nunder an approximate symmetry assumption” (Canay et al. 2017) and\nfurther described in “A User’s Guide to Approximate Randomization Tests\nwith a Small Number of Clusters” (Cai et al. 2022).\n\n# Installation\n\nYou can install rART using the following command:\n\n``` r\ndevtools::install_github(\"mwt/rART\")\n```\n\n# Example\n\nThe package is centered around a single function `artlm` which runs the\nmain regression. Several companion functions are provided in order to\nuse the method. In order to demonstrate this, we generate some data.\n\n``` r\ncn \u003c- 100 # cluster size\nnc \u003c- 10   # number of clusters\n\nx1 \u003c- rnorm(cn * nc, sd = 2)\nx2 \u003c- rnorm(cn * nc, mean = x1)\nx3 \u003c- runif(cn * nc)\n\neps \u003c- matrix(runif(cn * nc), cn, nc)\n\n# make some correlation within groups\neps \u003c- as.vector(eps + eps[sample(cn),] + eps[sample(cn),])\ngroup = factor(rep(1:nc, each = cn))\n\n# true model\ny \u003c- 1 + 10*x1 + x2/20 + eps\n\ndf \u003c- data.frame(y, x1, x2, x3, group)\n\nhead(df)\n#\u003e           y         x1          x2        x3 group\n#\u003e 1 -8.990301 -1.1209513 -2.11675002 0.3044642     1\n#\u003e 2 -1.943071 -0.4603550 -1.50031002 0.8328188     1\n#\u003e 3 34.619987  3.1174166  3.09943639 0.5936475     1\n#\u003e 4  3.566540  0.1410168  0.00884165 0.8071966     1\n#\u003e 5  4.400315  0.2585755 -2.29076730 0.2940508     1\n#\u003e 6 37.156422  3.4301300  4.47070343 0.1410852     1\n```\n\n# Regression\n\nThe linear ART regression is `artlm`. It is exactly the same as `lm`.\nHowever, it requires a cluster variable or vector to be specified.\n\n``` r\n(artlm1 \u003c- artlm(y ~ x1 + x2, cluster=group, data=df))\n#\u003e \n#\u003e Call:\n#\u003e artlm(formula = y ~ x1 + x2, data = df, cluster = group)\n#\u003e \n#\u003e Coefficients:\n#\u003e (Intercept)           x1           x2  \n#\u003e     2.51695     10.02792      0.03328\n```\n\nIt supports all the features that `lm` supports. For example, you can\nadd fixed effects.\n\n``` r\n(artlm2 \u003c- artlm(y ~ x1 + x2 + group - 1, cluster=group, data=df))\n#\u003e \n#\u003e Call:\n#\u003e artlm(formula = y ~ x1 + x2 + group - 1, data = df, cluster = group)\n#\u003e \n#\u003e Coefficients:\n#\u003e       x1        x2    group1    group2    group3    group4    group5    group6  \n#\u003e 10.02793   0.03229   2.58429   2.53483   2.43459   2.43422   2.51628   2.59488  \n#\u003e   group7    group8    group9   group10  \n#\u003e  2.36401   2.55289   2.53291   2.62133\n```\n\nYou can also specify that you are only interested in a subset of the\nvariables. For example, suppose I am only interested in `x1`.\n\n``` r\n(artlm3 \u003c- artlm(y ~ x1 + x2 + group - 1, cluster=group, select = \"x1\", data=df))\n#\u003e \n#\u003e Call:\n#\u003e artlm(formula = y ~ x1 + x2 + group - 1, data = df, cluster = group, \n#\u003e     select = \"x1\")\n#\u003e \n#\u003e Coefficients:\n#\u003e       x1        x2    group1    group2    group3    group4    group5    group6  \n#\u003e 10.02793   0.03229   2.58429   2.53483   2.43459   2.43422   2.51628   2.59488  \n#\u003e   group7    group8    group9   group10  \n#\u003e  2.36401   2.55289   2.53291   2.62133\n```\n\nIncluding the `select` option allows you to choose the parameters you\nare interested in. The result will not display in the regression object\nitself. However, chosen variables will not de displayed in `summary`\netc.\n\n# Summarizing models\n\nYou can run the simplest form of ART by running `summary` on any\nregression object. For example, we can apply it to our weighted fixed\neffects regression.\n\n``` r\nsummary(artlm2)\n#\u003e \n#\u003e Call:\n#\u003e artlm(formula = y ~ x1 + x2 + group - 1, data = df, cluster = group)\n#\u003e \n#\u003e Residuals:\n#\u003e      Min       1Q   Median       3Q      Max \n#\u003e -1.49058 -0.38165  0.01422  0.37043  1.30953 \n#\u003e \n#\u003e Coefficients:\n#\u003e    Estimate Crit. value t value Pr(\u003e|t|)   \n#\u003e x1 10.02793    19.03458  31.700  0.00195 **\n#\u003e x2  0.03229     0.11896   0.113  0.07031 . \n#\u003e ---\n#\u003e Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1\n#\u003e \n#\u003e Residual standard error: 0.504 on 988 degrees of freedom\n#\u003e Multiple R-squared:  0.9994, Adjusted R-squared:  0.9994 \n#\u003e F-statistic: 1.332e+05 on 12 and 988 DF,  p-value: \u003c 2.2e-16\n```\n\nThis gives us the OLS estimates, the t-statistic, the p-value, and the\ncritical value of the t-test for 95% confidence.\n\nIf we summarize the regression where we selected to view only `x1`, then\nwe will only see this one variable in the summary. Note that no\nselection is required to ignore the group fixed effects because ART\ncannot be applied to these coefficients.\n\n``` r\nsummary(artlm3)\n#\u003e \n#\u003e Call:\n#\u003e artlm(formula = y ~ x1 + x2 + group - 1, data = df, cluster = group, \n#\u003e     select = \"x1\")\n#\u003e \n#\u003e Residuals:\n#\u003e      Min       1Q   Median       3Q      Max \n#\u003e -1.49058 -0.38165  0.01422  0.37043  1.30953 \n#\u003e \n#\u003e Coefficients:\n#\u003e    Estimate Crit. value t value Pr(\u003e|t|)   \n#\u003e x1    10.03       19.03    31.7  0.00195 **\n#\u003e ---\n#\u003e Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1\n#\u003e \n#\u003e Residual standard error: 0.504 on 988 degrees of freedom\n#\u003e Multiple R-squared:  0.9994, Adjusted R-squared:  0.9994 \n#\u003e F-statistic: 1.332e+05 on 12 and 988 DF,  p-value: \u003c 2.2e-16\n```\n\n# Confidence intervals\n\nConfidence intervals are computed using the `confint` command as usual.\n\n``` r\nconfint(artlm2)\n#\u003e           2.5 %      97.5 %\n#\u003e x1  9.987563195 10.06423501\n#\u003e x2 -0.003333396  0.07527805\n```\n\nYou can adjust the level of significance using the `level` parameter.\n\n``` r\nconfint(artlm2, level = 0.98)\n#\u003e            1 %        99 %\n#\u003e x1  9.97521696 10.07359180\n#\u003e x2 -0.01446102  0.08521455\n```\n\nThe command will only display selected variables. So, if we use `artlm3`\nwhere we selected only `x1`, then we will only see the confidence\ninterval for this one term. More importantly, the function will not\ncompute intervals for unselected parameters.\n\n``` r\nconfint(artlm3)\n#\u003e     2.5 %    97.5 % \n#\u003e  9.987563 10.064235\n```\n\nIt is also possible to select variables in `confint` instead of in the\nregression.\n\n``` r\nconfint(artlm2, parm = \"x2\")\n#\u003e        2.5 %       97.5 % \n#\u003e -0.003333396  0.075278053\n```\n\n# Linear tests\n\nYou can conduct arbitrary linear tests using `ARTHypothesis`. For\nexample, suppose I wanted to test to see if\n*β*\u003csub\u003e1\u003c/sub\u003e = *β*\u003csub\u003e2\u003c/sub\u003e. Then, I can run.\n\n``` r\nARTHypothesis(artlm2, \"x1 = x2\")\n#\u003e Linear ART hypothesis test\n#\u003e \n#\u003e Hypothesis:\n#\u003e x1 - x2 = 0\n#\u003e \n#\u003e   Crit. value t value Pr(\u003e|t|)   \n#\u003e 1      18.986  31.587 0.001953 **\n#\u003e ---\n#\u003e Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1\n```\n\nYou can also supply the constraint vector and constant value manually\nlike so.\n\n``` r\nARTHypothesis(artlm2, c(1,-1), 0)\n#\u003e Linear ART hypothesis test\n#\u003e \n#\u003e Hypothesis:\n#\u003e x1 - x2 = 0\n#\u003e \n#\u003e   Crit. value t value Pr(\u003e|t|)   \n#\u003e 1      18.986  31.587 0.001953 **\n#\u003e ---\n#\u003e Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1\n```\n\nYou cannot construct a linear test using a parameter that was not\nselected in the original regression.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmwt%2Frart","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmwt%2Frart","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmwt%2Frart/lists"}