An independent variable is an input whose relationship with an outcome is being tested or modeled. It is also called a predictor or x-variable; the outcome is the dependent or y-variable. A model may use one predictor or several to describe patterns, assess relationships, or estimate outcomes for new observations. section 9.1
Start with the question you need to answer. A clear hypothesis names both the predictor and the outcome, then states the expected relationship in terms stakeholders can understand. For example, individual tutoring can be the predictor and test score the outcome; the hypothesis may predict higher scores with tutoring. section 3.1.2
The role of an independent variable depends on how the data is collected and used:
- In a controlled experiment, researchers manipulate a condition and measure the outcome. Random assignment and control of other conditions help them attribute an observed difference to that condition. section 3.2.3
- In a group comparison, the independent variable can be group membership, such as treatment versus control. A within-subjects design instead measures participants before and after exposure to a condition. section 3.2.4
- In a statistical model, predictors are inputs to an equation fitted to observed data. A useful fit can support estimates and explanations, but prediction alone does not establish cause. section 9.1 section 9.3.1
Estimating a house price
Square footage and number of bedrooms can serve as predictors, with sale price as the outcome. In a linear multiple regression, each input value is multiplied by its fitted coefficient; the results are added to an intercept to estimate a price. The fitted equation can then estimate prices for houses outside the original sample, without promising exact results. section 9.1.2 section 9.1
import statsmodels.api as sm
import pandas as pd
housing_prices = pd.read_csv("housing_prices.csv") #1
X = housing_prices[["sq_footage", "n_bedrooms"]]
y = housing_prices["price"] #2
X = sm.add_constant(X) #3
model = sm.OLS(y, X).fit() #4
print(model.summary())
The listing separates square footage and bedrooms into X, price into y, and fits a statsmodels OLS regression—making the predictor–outcome distinction concrete. section 9.1.2
Choose predictors for a reason, not merely because they are available. For explanatory work, each input needs a logical or theoretical justification, and its direction and contribution should be interpretable. Check model output and residuals: correlated predictors, unmet regression assumptions, or too many inputs can weaken accuracy and interpretability. Where predictors include sensitive personal data, such as wearable activity and health information, account for consent and disclosure risks before analysis. section 9.3.1 section 9.2.2 section 8.1.3



