Multivariate Regression and Prediction
multivariate regression, prediction, npreg, wage1, partial plots, np
For regressors \(X=x\), npreg() estimates the conditional mean \(g(x)=E(Y\mid X=x)\). This page covers fitting, partial-regression plots, and prediction when \(x\) contains several numeric and categorical predictors. It streamlines the regression_multivar_a.R teaching script rather than reproducing a published empirical estimate.
A small mixed-data regression
The bundled wage1 data contain 526 observations from the 1976 U.S. Current Population Survey, supplied by Jeffrey M. Wooldridge. The response is log wage; the predictors combine numeric and categorical variables.
## 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 + experThe formula identifies the response and regressors; it does not impose an ordinary linear-additive model.
Partial regression plots
For multivariate fits, plot() displays one coordinate of \(g(x)\) at a time.
## Start with asymptotic partial-regression plots for a quick read
plot(fit_multi, errors = "asymptotic")Each partial-regression plot varies one covariate while holding the others at representative values such as medians or modes. It is a slice through the fitted multivariate surface, not a bivariate regression fitted in isolation.
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.
Inspect the fitted object and asymptotic partial plots before requesting the more expensive bootstrap route. Move to npRmpi when the serial specification is established and runtime, rather than model definition, is the bottleneck.
Where to go next
Reference
Wooldridge, J. M. (2000), Introductory Econometrics: A Modern Approach, South-Western College Publishing.