npcmstest  R Documentation 
npcmstest
implements a consistent test for correct
specification of parametric regression models (linear or nonlinear) as
described in Hsiao, Li, and Racine (2007).
npcmstest(formula, data = NULL, subset, xdat, ydat, model = stop(paste(sQuote("model")," has not been provided")), distribution = c("bootstrap", "asymptotic"), boot.method = c("iid","wild","wildrademacher"), boot.num = 399, pivot = TRUE, density.weighted = TRUE, random.seed = 42, ...)
formula 
a symbolic description of variables on which the test is to be performed. The details of constructing a formula are described below. 
data 
an optional data frame, list or environment (or object
coercible to a data frame by 
subset 
an optional vector specifying a subset of observations to be used. 
model 
a model object obtained from a call to 
xdat 
a pvariate data frame of explanatory data (training data) used to calculate the regression estimators. 
ydat 
a one (1) dimensional numeric or integer vector of dependent data, each
element i corresponding to each observation (row) i of

distribution 
a character string used to specify the method of estimating the
distribution of the statistic to be calculated. 
boot.method 
a character string used to specify the bootstrap method.

boot.num 
an integer value specifying the number of bootstrap replications to
use. Defaults to 
pivot 
a logical value specifying whether the statistic should be
normalised such that it approaches N(0,1) in
distribution. Defaults to 
density.weighted 
a logical value specifying whether the statistic should be
weighted by the density of 
random.seed 
an integer used to seed R's random number generator. This is to ensure replicability. Defaults to 42. 
... 
additional arguments supplied to control bandwidth selection on the
residuals. One can specify the bandwidth type,
kernel types, and so on. To do this, you may specify any of 
npcmstest
returns an object of type cmstest
with the
following components, components will contain information
related to Jn
or In
depending on the value of pivot
:
Jn 
the statistic 
In 
the statistic 
Omega.hat 
as described in Hsiao, C. and Q. Li and J.S. Racine. 
q.* 
the various quantiles of the statistic 
P 
the Pvalue of the statistic 
Jn.bootstrap 
if 
In.bootstrap 
if 
summary
supports object of type cmstest
.
npcmstest
supports regression objects generated by
lm
and uses features specific to objects of type
lm
hence if you attempt to pass objects of a different
type the function cannot be expected to work.
If you are using data of mixed types, then it is advisable to use the
data.frame
function to construct your input data and not
cbind
, since cbind
will typically not work as
intended on mixed data types and will coerce the data to the same
type.
Tristen Hayfield tristen.hayfield@gmail.com, Jeffrey S. Racine racinej@mcmaster.ca
Aitchison, J. and C.G.G. Aitken (1976), “Multivariate binary discrimination by the kernel method,” Biometrika, 63, 413420.
Hsiao, C. and Q. Li and J.S. Racine (2007), “A consistent model specification test with mixed categorical and continuous data,” Journal of Econometrics, 140, 802826.
Li, Q. and J.S. Racine (2007), Nonparametric Econometrics: Theory and Practice, Princeton University Press.
Maasoumi, E. and J.S. Racine and T. Stengos (2007), “Growth and convergence: a profile of distribution dynamics and mobility,” Journal of Econometrics, 136, 483508.
Murphy, K. M. and F. Welch (1990), “Empirical ageearnings profiles,” Journal of Labor Economics, 8, 202229.
Pagan, A. and A. Ullah (1999), Nonparametric Econometrics, Cambridge University Press.
Wang, M.C. and J. van Ryzin (1981), “A class of smooth estimators for discrete distributions,” Biometrika, 68, 301309.
## Not run: # EXAMPLE 1: For this example, we conduct a consistent model # specification test for a parametric wage regression model that is # quadratic in age. The work of Murphy and Welch (1990) would suggest # that this parametric regression model is misspecified. data("cps71") attach(cps71) model < lm(logwage~age+I(age^2), x=TRUE, y=TRUE) plot(age, logwage) lines(age, fitted(model)) # Note  this may take a few minutes depending on the speed of your # computer... npcmstest(model = model, xdat = age, ydat = logwage) # Sleep for 5 seconds so that we can examine the output... Sys.sleep(5) # Next try Murphy & Welch's (1990) suggested quintic specification. model < lm(logwage~age+I(age^2)+I(age^3)+I(age^4)+I(age^5), x=TRUE, y=TRUE) plot(age, logwage) lines(age, fitted(model)) X < data.frame(age) # Note  this may take a few minutes depending on the speed of your # computer... npcmstest(model = model, xdat = age, ydat = logwage) # Sleep for 5 seconds so that we can examine the output... Sys.sleep(5) # Note  you can pass in multiple arguments to this function. For # instance, to use local linear rather than local constant regression, # you would use npcmstest(model, X, regtype="ll"), while you could also # change the kernel type (default is second order Gaussian), numerical # search tolerance, or feed in your own vector of bandwidths and so # forth. detach(cps71) # EXAMPLE 2: For this example, we replicate the application in Maasoumi, # Racine, and Stengos (2007) (see oecdpanel for details). We # estimate a parametric model that is used in the literature, then # subject it to the model specification test. data("oecdpanel") attach(oecdpanel) model < lm(growth ~ oecd + factor(year) + initgdp + I(initgdp^2) + I(initgdp^3) + I(initgdp^4) + popgro + inv + humancap + I(humancap^2) + I(humancap^3)  1, x=TRUE, y=TRUE) X < data.frame(factor(oecd), factor(year), initgdp, popgro, inv, humancap) npcmstest(model = model, xdat = X, ydat = growth) detach(oecdpanel) ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.