Which is the dependent variable?
I was looking at this Data Science question on TestDome.
Implement the desired_marketing_expenditure function, which returns the required amount of money that needs to be invested in a new marketing campaign to sell the desired number of units.
Use the data from previous marketing campaigns to evaluate how the number of units sold grows linearly as the amount of money invested increases.
For example, for the desired number of 60,000 units sold and previous campaign data from the table below, the function should return the float 250,000.
because what I'm trying to find is the marketing expenditure given a number of units sold.
from which then it calculates the marketing_expenditure by rearranging the equation.
The two approaches are not equivalent and give different results as depending on what is the dependent / independent variable the linear regression algorithm tries to minimise different square distances to different regression lines.
Which approach is correct and why?
You know what? Let's implement that function. I will use Python.
Well, that number is wrong, just what I expected. The input number is $60\,000$ and the function returns $22\,000$.
I like this. The input number is $60\,000$ and the function returns $250\,877$. What did I assume? That marketing_expenditure is the dependent variable and units_sold is the independent variable, just what you said in your question. What do I want to predict? $Z$. So let $Z$ be the dependent variable.
However, the confusion... the damn confusion is present because the guy does something neither you or I would do. Let me give an example.
The goal is to find $a$ and $b$ with linear regression. You and I naturally assume that $t$ is the independent variable and $v$ is the dependent variable. Say you find $a = 2.5$ and $b = 1.3$ (with the correct units, but we don't care for the moment). Then I tell you that find $t$ given $v = 4.8$, what would you do? Rearrange the equation?
I am with you, if you want to predict marketing_expenditure, marketing_expenditure is the dependent variable (besides, with Python it's easier than the other option). There must be strong reasons (other than casuality) to change the order of the variables, I don't see those in this example.
The questions in the first highlighted section call for you to do both - and also maybe neither!
This is very poorly worded. To me, "implement a function" doesn't call for regression at all. It sounds like there is an already existing function, and you should just do something with it. However, if regression is called for, then it seems like number of units is the DV. That is, to me, also strange. You can't manipulate the number of units sold, you can manipulate the amount spent, but the way it's worded, it looks like they want you to do it that way.
This clearly does call for linear regression, but here the DV is clearly number of units.
So, what to do? Can you contact the people who wrote TestDome? Can you ignore this?
Thanks for contributing an answer to Cross Validated!
Not the answer you're looking for? Browse other questions tagged r regression python linear or ask your own question.
Regression model for predicting sales?
Which are the most important predictors (and how great is their impact) of a continuous dependent variable?
Which analytic strategy is the best for discrete dependent variable?
Linear regression - Can I log transform dependent variable and one of the independent ones and keep the rest not transformed?
What was Apollo 13 "Little Jolt" after MECO?