# Nonparametric equivalent of ANCOVA for continuous dependent variables

I have an independent categorical variable ($X$ with two categories, $x_{1}$ and $x_{2}$) and two continuous dependent variables ($y$ and $z$).

Using a Mann Whitney test, I know that $y$ is significantly associated with $x_{1}$ and $z$ is likewise significantly associated with $x_{1}$. However, it could be that either $y$ confounds the relationship seen between $x_{1}$ and $z$, or vice versa, i.e. $z$ confounds the relationship seen between $x_{1}$ and $y$.

What distribution-free tests can I use to try account for each factor in tests of $y$ versus $X$ and $z$ versus $X$?

How can I achieve this in R and SPSS?

• Non-parametric ANCOVA is available in the sm R package (sm.ancova).
– chl
Oct 27, 2012 at 18:02
• @chi Is it me being confused or is the OP asking about distribution-free ANCOVA (where 'nonparametric' refers to the distributional assumption), while sm is (I think) addressing smoothing (where 'nonparametric' refers to the form of the relationship between y and a continuous covariate). These are different things. See items 1. vs 2. in the introductory section of the relevant wikipedia page. Such confusion of terminology causes endless problems! Apr 4, 2013 at 23:50
• this is not what ANCOVA does. That requires a continuous dependent variable, and two independent variables, one categorical and one continuous. Jan 28, 2018 at 20:24

Turning my comment to an answer, the sm package offers non-parametric ANCOVA as sm.ancova. Here is a toy example:

data(anorexia, package="MASS")
anorexia$Treat <- relevel(anorexia$Treat , ref="Cont")
# visual check for the parallel group assumption
xyplot(Postwt ~ Prewt, data=anorexia, groups=Treat, aspect="iso", type=c("p","r"),
auto.key=list(space="right", lines=TRUE, points=FALSE))
# fit two nested models (equal and varying slopes across groups)
anorex.aov0 <- aov(Postwt ~ Prewt + Treat, data=anorexia) # ≈ lm(Postwt ~ Prewt + Treat + offset(Prewt), data=anorexia)
anorex.aov1 <- aov(Postwt ~ Prewt * Treat, data=anorexia)
# check if we need the interaction term
anova(anorex.aov0, anorex.aov1)
summary.lm(anorex.aov1) The above shows that the parallel group assumption is not realistic and that we must account for the interaction (p=0.007) between the factor group and continuous covariate.

Here is what we would get with sm.ancova, with default smoothing parameter and equal-group as the reference model:

> with(anorexia, ancova.np <- sm.ancova(Prewt, Postwt, Treat, model="equal"))
Test of equality :  h =  1.90502    p-value =  0.0036
Band available only to compare two groups. There is another R package for non-parametric ANCOVA (I haven't tested it, though): fANCOVA, with T.aov allowing to test for the equality of nonparametric curves or surfaces based on an ANOVA-type statistic.

If relation between both regression models are linear, the function sen.adichie from NSM3 package (https://cran.r-project.org/web/packages/NSM3/) test the parallelism of several regression lines. And a Kruskal-Wallis test of aligned observations (ao_ij = y_ij - b x_ij) can to test the elevations (intercepts) of parallel lines.

• Although implementation is often mixed with substantive content in questions, we are supposed to be a site for providing information about statistics, machine learning, etc., not code / packages. It can be good to provide that kind of information as well, but please elaborate your substantive answer well enough for people who don't use R. Apr 25, 2019 at 19:01