# What is the correct way of assessing if a relationship between Y and X is affected by a quantitative variable A and a categorical variable B?

The question might be silly, but I wondered if is correct to use linear regressions when you want to assess how a numerical variable A and a categorical variable B affects the linear relationship between X and Y.

I ask that because I am not interested in assessing if A or B affects Y. Instead, I am interested in assessing if the relationship (linear) between Y and X is affected by A and B, being A a discrete numerical variable and B a categorical one.

I think the common way of evaluating this would be a linear regression of the next form:

Y = b0 + b1.X + b2.A + b3.B + E

Is it mathematically right?

Thanks!!

This depends very much on the underlying relationships between your variables. The phrasing of your question 'is this mathematically right?' therefore misses the point.

In your equation you assume that the variables $$A$$ and $$B$$ simply have an additive effect on $$Y$$, but that the marginal effect of $$X$$ on $$Y$$ is independent of $$A$$ and $$B$$

$$A$$ and $$B$$ can affect the linear relationship between $$X$$ and $$Y$$ it other ways as well and there could e.g. be relationships of the form:

$$Y = b_0 + b_1 X + b_2AX + b_3BX$$

This would mean that the marginal effect of $$X$$ on $$Y$$ depends on the variables $$A$$ and $$B$$.

An example in a simplfied framework with only $$Y$$, $$X$$ and $$A$$:

$$Y = b_0 + b_1X + b_3XA$$ $$Y$$ could e.g. be your knowledge, $$X$$ the amount of books you read and $$A$$ your ability to read. The amount of knowledge you gain by your parents giving your books therefore depends on your ability to read.

• Thanks @Sebastian!! This arises from this specific case: stats.stackexchange.com/questions/461416/…. Beyond the question I formulated in that post, I was wondering if it was correct to pose a linear regression in the way I did. As I explain in the post, I have two devices that measure activity of an animal. One of the devices gives "real data" (device 2) and the other one (Device 1) gives an estimation of the real activity. Apr 19 '20 at 19:21
• The association of activity between devices can be done at different time intervals (2 hours, 1 hour, etc), and Device 1 uses High, Medium or Low amount of data to estimate activity. Then, I was wondering if the relationship between activities from Device 2 (real activity) and Device 1 (estimated activity) changes depending on the time interval and the amount of data. Is in this case correct to assume that Time.Interval (discrete variable) and Amount of data (ordinal variable) simply have additive effects? Apr 19 '20 at 19:22