Multivariate Regression and Prediction
multivariate regression, prediction, npreg, wage1, partial plots, np
This page covers the common case where a model has more than one regressor and you want a practical route to fitting, plotting, and predicting. It streamlines the retained regression_multivar_a.R teaching script rather than reproducing a published empirical estimate.
A small mixed-data regression
The bundled wage1 data are a random sample of 526 observations from the 1976 U.S. Current Population Survey, supplied by Jeffrey M. Wooldridge. They remain a useful first example because they combine numeric and categorical predictors in a way that mirrors applied work.
## Fit a small mixed-data regression with one factor and two numeric regressors
library(np)
data(wage1, package = "np")
fit_multi <- npreg(lwage ~ female + educ + exper,
regtype = "ll",
data = wage1)
summary(fit_multi)The important point is that female is a factor while educ and exper are numeric. In np, that is not incidental. The variable classes are part of the estimator definition because they determine which kernel components are used.
Why this differs from a linear model
The formula looks familiar:
## The familiar formula syntax still identifies response and regressors
lwage ~ female + educ + experBut the estimator is not fitting an ordinary linear-additive model. The formula is simply the interface for telling np which variable is the response and which are the regressors.
Partial regression plots
For multivariate fits, plot() is often the quickest way to see what the model is doing.
## Start with asymptotic partial-regression plots for a quick read
plot(fit_multi, errors = "asymptotic")These are partial-regression plots. One covariate is allowed to vary while the others are held fixed at representative values such as medians or modes. That is why the resulting plots are usually easier to interpret than a raw scatterplot against one regressor at a time.
If you want bootstrap-based intervals instead, the workflow is the same but the computation can be much heavier.
## Switch to bootstrap intervals only when you need the heavier route
plot(fit_multi, errors = "bootstrap")Prediction
Prediction works by supplying a newdata frame with the same predictor structure.
## Predict on a small new-data frame that preserves the factor structure
predict(fit_multi,
newdata = wage1[1:5, c("female", "educ", "exper")])This is often the safest pattern because it preserves the factor structure from the original data.
A practical workflow
One practical sequence is:
- fit a small model first,
- inspect
summary(fit_multi), - look at the partial-regression plots,
- only then move on to heavier plotting or bootstrap intervals,
- move to
npRmpionly after the serial workflow is the right one but too slow for the job at hand.
Where to go next
Reference
Wooldridge, J. M. (2000), Introductory Econometrics: A Modern Approach, South-Western College Publishing.