| Title: | Chi-Squared Test for Goodness of Fit and Independence Test |
|---|---|
| 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. |
| Authors: | Atchanut Rattanalertnusorn [cre, aut], Jiranan Choojai [aut], Chutima Philadee [aut], Kittipong Klinjan [aut], Issaraporn Thiamsorn [aut] |
| Maintainer: | Atchanut Rattanalertnusorn <[email protected]> |
| License: | GPL-3 |
| Version: | 1.0.0 |
| Built: | 2026-06-22 14:15:42 UTC |
| Source: | https://github.com/cran/Mychisq |
This function is for the goodness of fit test of one categorical variable
gofchisq(x, p, conf.level = 0.95)gofchisq(x, p, conf.level = 0.95)
x |
an observed frequency vector |
p |
probability of each group |
conf.level |
confidence level for testing hypothesis, default is |
output for the goodness of fit test
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>.
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)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)
This function is for the independence test of two categorical variables
indchisq(O, conf.level = 0.95)indchisq(O, conf.level = 0.95)
O |
an observed matrix has |
conf.level |
confidence level for testing hypothesis, default is |
output for the independence test
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>.
v <- c(80,60,150,50,40,20) X<- matrix(v,ncol=2,byrow = TRUE) # 3x2 indchisq(X)v <- c(80,60,150,50,40,20) X<- matrix(v,ncol=2,byrow = TRUE) # 3x2 indchisq(X)
The plot of Chi-squared distribution with k degrees of freedom
plotchisq(df = 8)plotchisq(df = 8)
df |
degrees of freedom |
The figure of Chi-squared distribution with k degrees of freedom
plotchisq(df=15)plotchisq(df=15)
A function 'sigmaCI()' is used to compute a confidence interval of the population standard deviation when given a numeric vector
sigmaCI(x, conf.level = 0.95)sigmaCI(x, conf.level = 0.95)
x |
a numeric vector |
conf.level |
a confidence level, default is |
a confidence interval of the population standard deviation
Rattanalertnusorn, A. (2024). R and its application (3rd ed.). TPN press. <https://www.researchgate.net/publication/371944275_porkaermxarlaeakarprayuktchingan_R_and_its_applications>.
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)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)
The function 'sigmatest()' is used to test the hypothesis about the population variance
sigmatest( x, sigma, alternative = c("two.sided"), conf.level = 0.95, verbose = TRUE )sigmatest( x, sigma, alternative = c("two.sided"), conf.level = 0.95, verbose = TRUE )
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 |
output of one sample Chi-squared test for variance
Rattanalertnusorn, A. (2024). R and its application (3rd ed.). TPN press. <https://www.researchgate.net/publication/371944275_porkaermxarlaeakarprayuktchingan_R_and_its_applications>.
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)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)
A function 'varCI()' is used to calculate a confidence interval for the population variance when given a numerical vector
varCI(x, conf.level = 0.95)varCI(x, conf.level = 0.95)
x |
a numeric vector |
conf.level |
a confidence level, default is |
a confidence interval of the population variance
Rattanalertnusorn, A. (2024). R and its application (3rd ed.). TPN press. <https://www.researchgate.net/publication/371944275_porkaermxarlaeakarprayuktchingan_R_and_its_applications>.
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)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)