cmltest: Test for linearity of the conditional median in simple...

View source: R/cmltest.R

cmltestR Documentation

Test for linearity of the conditional median in simple regression

Description

A test based on regression depth for linearity of the conditional median z given the simple regression dataset x. The computation of the regression depth of z with respect to x is done by the function rdepth. The test is only valid when x contains no duplicates.

Usage

cmltest(x, z)

Arguments

x

An n by 2 regression data matrix.
The first column is the explanatory variable, the second column corresponds to the response variable.

z

A matrix with one row containing an intercept and slope.

Details

The following hypothesis test is performed:
H_0: The data come from a model with: med(x_2|x_1) = z_1 + z_2 * x_1
The test statistic being used is the regression depth of z with respect to x.

Value

pval

The p-value of the hypothesis test.

Author(s)

P. Segaert

References

Van Aelst S., Rousseeuw P.J., Hubert M., Struyf A. (2002). The deepest regression method. Journal of Multivariate Analysis, 81, 138–166.

Rousseeuw P.J., Struyf A. (2002). A depth test for symmetry. In: Goodness-of-Fit Tests and Model Validity, Birkhäuser Boston, pages 401–412.

See Also

rdepth, rdepthmedian

Examples


data(stars)

# Compute the least squares fit. Due to outliers
# this fit will be bad and thus H0 should be rejected. 
temp <- lsfit(x = stars[,1], y = stars[,2])$coefficients
intercept <- temp[1]
slope <- temp[2]
z <- matrix(c(intercept, slope), nrow = 1)
pvalue1 <- cmltest(x = stars[!duplicated(stars), ], z = z)
pvalue1

# Let's now test the deepest regression line. 
result <- rdepthmedian(x = stars)
pvalue2 <- cmltest(x = stars[!duplicated(stars), ], z = matrix(result$deepest, nrow = 1))
pvalue2

plot(stars)
abline(a = intercept, b = slope)
abline(result$deepest, col = "red")
text(x = 3.8, y = 5.3, labels = paste("p-value", round(pvalue1, digits = 3)))
text(x = 4.45, y = 4.8, labels = paste("p-value", round(pvalue2, digits = 3)),
     col = "red")

mrfDepth documentation built on Oct. 6, 2023, 5:07 p.m.