# Check if dependency between two variables is linear

There are a number of values for dependent variable (let's name it Y) and the same number of corresponding values for independent variable (let's name it X).

How can i check if dependency Y(X) is linear? If my table would looks like (i.e. independent variable X will take only two values 0 or 1):

Is it possible in that case that dependency Y(X) is linear? Why?

• You should say what you mean by a linear relationship. Ordinarily, one says that ordinary (Pearson) correlation measures the linear component of association. So $|r|$ sufficiently near $1$ might be a criterion for linearity. // In your first dataset relationship seems linear, but not in the second. // I can't easily convert your 'pictures' to numbers, so I didn't actually find correlations for either. – BruceET Aug 29 '19 at 17:41
• @Bruce Only some people make that claim about $|r|.$ I think it's overblown and misleading. A different interpretation of "linearity" is that alternative non-linear models aren't worth the additional complexity. There are two standard, textbook approaches to this: add a quadratic term or bin the independent variable(s). Run an ANOVA on the nested model. If it's not significant, conclude you haven't detected any nonlinearity. These are often called "goodness of fit" tests (which you surely know, but many of our visitors do not). – whuber Aug 29 '19 at 18:13
• Thanks for link. – BruceET Aug 29 '19 at 18:36
• @BruceET In the protocol i'm going to apply was mentioned: Note that if observations are, instead, linearly related to gradients, we have to use a Canonical Correlation Analysis (CANCOR) or Redundancy Analysis (RDA) instead of a Canonical Correspondence Analysis (CCA). So i'm not sure which definition author exactly mean. – Denis Aug 29 '19 at 18:52
• @ whuber Thanks a lot. Could you provide some tutorial for these two methods (add a quadratic term and bin the independent variable) you mentioned please (if possible in r). I'm not a statistician and it's not easy to figure out that. What i already understand now from your post i have to make some linear models (perhaps with lm function) and then test them with ANOVA. But it's not clear which models i could make with one independent variable. Thank you again. – Denis Aug 29 '19 at 21:32

• I'm wondering if it's possible in theory to have a linear dependency between X and Y if X take only two possible values 0 or 1? – Denis Aug 29 '19 at 22:00
• Adding some more to James's answer: If your $x \in \{0,1\}$ and if you consider $y$ to be random (which is an automatic assumption when you talk about "fitting" a curve on x-y plot) then there is trivially a linear relationship between $E(y)$ and $x$. Think of this in terms of a box plot of $y$ w.r.t $x$. Box plot can also help you understand if the distribution of $y$ is different for $x=0,1$. – Dayne Aug 30 '19 at 3:57
• Thanks! What is w.r.t? For only two points it's clear now. Thanks for the explanation. But what would be in case of multiple X and Y like in the 2-nd table (it's just a toy example). Is it possible? – Denis Aug 30 '19 at 8:44