| Type: | Package |
| Title: | Chi-Squared Test for Goodness of Fit and Independence Test |
| Version: | 1.0.0 |
| Language: | en-US |
| Maintainer: | Atchanut Rattanalertnusorn <atchanut_r@rmutt.ac.th> |
| Description: | The chi-squared test for goodness of fit and an independence test. In addition, the chi-squared test for the population variance, the function for computing a confidence interval for the population variance, and the function for calculating the population standard deviation are provided. |
| License: | GPL-3 |
| Encoding: | UTF-8 |
| Imports: | stats,graphics |
| RoxygenNote: | 7.3.2 |
| Suggests: | testthat (≥ 3.0.0) |
| Config/testthat/edition: | 3 |
| NeedsCompilation: | no |
| Packaged: | 2026-06-22 07:12:45 UTC; User |
| Author: | Atchanut Rattanalertnusorn [cre, aut], Jiranan Choojai [aut], Chutima Philadee [aut], Kittipong Klinjan [aut], Issaraporn Thiamsorn [aut] |
| Repository: | CRAN |
| Date/Publication: | 2026-06-22 08:00:02 UTC |
Goodness of fit test
Description
This function is for the goodness of fit test of one categorical variable
Usage
gofchisq(x, p, conf.level = 0.95)
Arguments
x |
an observed frequency vector |
p |
probability of each group |
conf.level |
confidence level for testing hypothesis, default is |
Value
output for the goodness of fit test
References
Chernoff, H. and Lehmann, E.L. (1954) The Use of Maximum Likelihood Estimates in Chi-Square Tests for Goodness of Fit. Annals of Mathematical Statistics, 25, 579-586. <doi.org/10.1214/aoms/1177728726>.
Examples
x=c(12,9,10,7,12)
prob=c(1/5,1/5,1/5,1/5,1/5) #1:1:1:1:1
gofchisq(x=x,p=prob)
Independence test
Description
This function is for the independence test of two categorical variables
Usage
indchisq(O, conf.level = 0.95)
Arguments
O |
an observed matrix has |
conf.level |
confidence level for testing hypothesis, default is |
Value
output for the independence test
References
Plackett, R. L. (1983). Karl Pearson and the Chi-Squared Test. International Statistical Review / Revue Internationale de Statistique, 51(1), 59–72. <doi.org/10.2307/1402731>.
Examples
v <- c(80,60,150,50,40,20)
X<- matrix(v,ncol=2,byrow = TRUE) # 3x2
indchisq(X)
Plot of Chi-squared distribution
Description
The plot of Chi-squared distribution with k degrees of freedom
Usage
plotchisq(df = 8)
Arguments
df |
degrees of freedom |
Value
The figure of Chi-squared distribution with k degrees of freedom
Examples
plotchisq(df=15)
Confidence interval for the population standard deviation
Description
A function 'sigmaCI()' is used to compute a confidence interval of the population standard deviation when given a numeric vector
Usage
sigmaCI(x, conf.level = 0.95)
Arguments
x |
a numeric vector |
conf.level |
a confidence level, default is |
Value
a confidence interval of the population standard deviation
References
Rattanalertnusorn, A. (2024). R and its application (3rd ed.). TPN press. <https://www.researchgate.net/publication/371944275_porkaermxarlaeakarprayuktchingan_R_and_its_applications>.
Examples
heigth <- c(155.5, 165.5, 170, 164.5, 180, 162, 173, 158.5, 168.5, 175, 164.5, 167)
sigmaCI(x=heigth,conf.level = 0.90)
Hypothesis testing for the population variance
Description
The function 'sigmatest()' is used to test the hypothesis about the population variance
Usage
sigmatest(
x,
sigma,
alternative = c("two.sided"),
conf.level = 0.95,
verbose = TRUE
)
Arguments
x |
a numeric vector |
sigma |
a population standard deviation under the null hypothesis |
alternative |
an alternative hypothesis, default is "two.sided"; the user can change to "greater" or "less" |
conf.level |
a confidence level for hypothesis testing, default is |
verbose |
a special variable is used for protected unexpected print output; the default is TRUE, do NOT change |
Value
output of one sample Chi-squared test for variance
References
Rattanalertnusorn, A. (2024). R and its application (3rd ed.). TPN press. <https://www.researchgate.net/publication/371944275_porkaermxarlaeakarprayuktchingan_R_and_its_applications>.
Examples
heigth <- c(155.5, 165.5, 170, 164.5, 180, 162, 173, 158.5, 168.5, 175, 164.5, 167)
sigmatest(x=heigth, sigma = 3, alternative = "two.sided", conf.level = 0.95)
Confidence interval for the population variance
Description
A function 'varCI()' is used to calculate a confidence interval for the population variance when given a numerical vector
Usage
varCI(x, conf.level = 0.95)
Arguments
x |
a numeric vector |
conf.level |
a confidence level, default is |
Value
a confidence interval of the population variance
References
Rattanalertnusorn, A. (2024). R and its application (3rd ed.). TPN press. <https://www.researchgate.net/publication/371944275_porkaermxarlaeakarprayuktchingan_R_and_its_applications>.
Examples
heigth <- c(155.5, 165.5, 170, 164.5, 180, 162, 173, 158.5, 168.5, 175, 164.5, 167)
varCI(x=heigth,conf.level = 0.90)