Contenu principal

rjtest

R2026b

Ryan–Joiner test

Since R2026b

Description

h = rjtest(x) returns a test decision, using the Ryan–Joiner test, for the null hypothesis that the data in vector x comes from a normal distribution. The alternative hypothesis is that the data does not come from such a distribution. The result h is 1 if the test rejects the null hypothesis at the 5% significance level, and 0 otherwise.

example

h = rjtest(x,Name=Value) returns a test decision with additional options specified by one or more name-value arguments. For example, you can change the significance level, or calculate the p-value using a Monte Carlo approximation.

Tip

It is recommended that you specify MonteCarloTolerance when the sample data x contains more than 100 values.

example

[h,p] = rjtest(___) also returns the p-value p, using any of the input argument combinations in the previous syntaxes.

example

[h,p,rjstat,critval] = rjtest(___) also returns the test statistic rjstat and the critical value critval for the test.

example

Examples

collapse all

Load the data set.

load cereal

Test the null hypothesis that the sodium level follows a normal distribution across different cereal types.

h = rjtest(Sodium)
h = 
1

The returned value h = 1 indicates that rjtest rejects the null hypothesis at the default 5% significance level.

Load the data set.

load cereal

Test the null hypothesis that the sodium level follows a normal distribution across different cereal types at the 1% significance level.

[h,p] = rjtest(Sodium,Alpha=0.01)
h = 
1
p = 
0.0099

Both the returned value h = 1 and the returned p-value less than α = 0.01 indicate that rjtest rejects the null hypothesis.

Load the data set.

load carbig

Test the null hypothesis that the car mileage, in miles per gallon (MPG), follows a normal distribution across different models of cars. Use a Monte Carlo simulation to obtain an estimated p-value.

rng(0,"twister") % For reproducibility
[h,p,rjstat,critval] = rjtest(MPG,MonteCarloTolerance=0.0001)
h = 
1
p = 
0
rjstat = 
0.9846
critval = 
0.9963

The returned value h = 1 indicates that rjtest rejects the null hypothesis at the default 5% significance level. Because a Ryan–Joiner test statistic value close to 1 indicates normality, the fact that rjstat is smaller than the critical value critval also indicates rejection of the null hypothesis.

Input Arguments

collapse all

Sample data for the hypothesis test, specified as a numeric vector. The function treats NaN values in x as missing values and ignores them. After the function removes NaN values, x must contain at least four observations.

Name-Value Arguments

collapse all

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Example: rjtest(x,Alpha=0.01,MonteCarloTolerance=0.01) specifies a hypothesis test at the 1% significance level, and determines the p-value p using a Monte Carlo simulation with a maximum Monte Carlo standard error of 0.01 for p.

Significance level of the hypothesis test, specified as a scalar value in the range (0,1).

Example: Alpha=0.01

Data Types: single | double

Maximum Monte Carlo standard error for the p-value p specified as a positive scalar value. If you specify a value for MonteCarloTolerance, the function computes a Monte Carlo approximation for p directly (see Ryan–Joiner test). The function selects a sufficiently large number of Monte Carlo replications to ensure the Monte Carlo standard error for p is less than the value specified for MonteCarloTolerance. It is recommended that you specify MonteCarloTolerance when the sample data x contains more than 100 values.

Example: MonteCarloTolerance=0.001

Data Types: single | double

Output Arguments

collapse all

Hypothesis test result, returned as 1 or 0.

  • A value of 1 indicates the rejection of the null hypothesis at the Alpha significance level.

  • A value of 0 indicates a failure to reject the null hypothesis at the Alpha significance level.

p-value of the hypothesis test, returned as a scalar value in the range (0,1). p is the probability of observing a test statistic as extreme as, or more extreme than, the observed value under the null hypothesis. A small value of p indicates that the null hypothesis might not be valid. For more information, see Ryan–Joiner test.

Test statistic for the Ryan–Joiner test, returned as a nonnegative scalar value. A test statistic value close to 1 indicates normality. Lower values indicate departures from normality. For more information, see Ryan–Joiner test.

Critical value for the Ryan–Joiner test at the Alpha significance level, returned as a nonnegative scalar value. The null hypothesis is rejected when rjstat < critval. For more information, see Ryan–Joiner test.

More About

collapse all

References

[1] Ryan, T. A., and B. L. Joiner. "Normal Probability Plots and Tests for Normality," Technical Report, Statistics Department, The Pennsylvania State University, 1976.

Version History

Introduced in R2026b