Type: | Package |
Title: | Transforms Contingency Tables to Data Frames, and Analyses Them |
Version: | 0.1.1 |
Author: | Scott D. Graham |
Maintainer: | Scott D. Graham <scott.grah95@gmail.com> |
Description: | Contingency Tables are a pain to work with when you want to run regressions. This package takes them, flattens them into a long data frame, so you can more easily analyse them! As well, you can calculate other related statistics. All of this is done so in a 'tidy' manner, so it should tie in nicely with 'tidyverse' series of packages. |
Depends: | R(≥ 3.4.2), stats, dplyr, tibble, magrittr |
Suggests: | testthat |
License: | MIT + file LICENSE |
Encoding: | UTF-8 |
LazyData: | true |
RoxygenNote: | 6.0.1 |
NeedsCompilation: | no |
Packaged: | 2017-11-15 18:38:31 UTC; scott_000 |
Repository: | CRAN |
Date/Publication: | 2017-11-16 09:49:33 UTC |
Flatten i*j*k contingency tables into tidy data.
Description
flatten_ct() takes a i*j*k array, and turns it into a tibble
Usage
flatten_ct(data)
Arguments
data |
An i*j*k array. |
Value
A tibble with 3 columns.
Examples
flatten_ct(lung_cancer)
Calculate the Chi^2 and G^2 Statistics
Description
Calculates the goodness of fit test statistics for contingency tables
Usage
goodness_of_fit(model, type = "Chisq", ...)
Arguments
model |
a GLM regression model. |
type |
either "Chisq" or "Gsq", which determines the type of goodness of fit test that is ran. Defaults to "Chisq". |
... |
Further arguments passed to or from other methods. |
Value
A list with class "ct_goodness_of_fit
" containing the following components:
test
the type of test used.
model
the name of the inputted model.
statistic
The value of the test statistic as determined by the type parameter
df
The number of degrees of freedom.
This equals the number of combinations for explanatory variables less the number of parameters in the model
p.value
The p-value calculated under a Chi-Squared distribution.
Examples
lung_logit <-
lung_cancer %>%
flatten_ct() %>%
glm(
Lung ~ Smoking
,family = binomial
,data = .
)
goodness_of_fit(model = lung_logit, type = "Chisq")
lung_logit %>%
goodness_of_fit(type = "Gsq")
lung_cancer %>%
flatten_ct() %>%
glm(
Lung ~ City + Smoking
,family = binomial
,data = .
) %>%
goodness_of_fit()
Lung Cancer by whether or not a person smokes and City.
Description
Based on data in Z. Liu, Int. J. Epidemiol., 21: 197–201, 1992.
Usage
lung_cancer
Format
An Array with 2*2*8 dimensions
- Smoking
Whether or not a person smokes.
- Lung
Whether or not a person has lung cancer.
- City
Name of the city a person lives in.
Examples
lung_cancer
Print method for goodness_of_fit()
Description
Creates a nice looking output for the goodness_of_fit() function
Usage
## S3 method for class 'ct_goodness_of_fit'
print(x, ...)
Arguments
x |
A list |
... |
Further arguments passed to or from other methods. |