ncd_gen.Rd
This routine computes all models considered for cross-sectional dependence using endogenously
generated weight matrices. Currently "lmcd" for linear regression, "logitcd" (logit model),
"poiscd" (poisson model), "probitcd" (probit model), "nbcd" (negative binomial) are supported.
Note: the data should first be sorted by unit ID Pid
, then by time ID Tid
ncd_gen(pars, Y, X, Xm = NULL, Xi = X, Tid, Pid, fun, k = 1, nt, utid, modclass = "lmcd", rval = "crit", eta = 0.5, dWzero = FALSE)
pars | vector of parameter values at which to evaluate the function |
---|---|
Y | outcome variable |
X | matrix of covariates or design matrix |
Xm | matrix of other control variables |
Xi | matrix of variable(s) that drive cross-sectional dependence |
Tid | time ID |
Pid | unit ID |
fun | a function that parameterises cross-sectional dependence. it can be user-written. It must take exactly three inputs: xi,xj, and k. see polyexp, polyexp_mul, inter_xij for example. |
k | order of polynomial approximation for |
nt | number of terms in approximation; should be of length equal to output of |
utid | unique time IDs to be used in the estimation; should leave at least 1 period for lagged Xi |
modclass | the class of model. See description above for classes supported. |
rval | character string naming the output to return; "crit" - value of criterion, "critobs" - observation-specific criterion values, squared residuals for "lmcd", negative log-likelihoods for MLE methods, etc., or "Xweight" vector X*W where W collects weight matrices through time. |
eta | extra parameter to be passed, eg. \(\theta\) for negative binomial,\(\tau\) for quantile regression. |
dWzero | logical. Should the diagonal elements of the weight matrix be set to zero?
Defaults to |
criterion value or vector of observation-specific criterion values if crit_obs=TRUE
pars=c(1.0,0.5,0.8); N = 5; Tp = 6; fnp<- function(x,y,k){-(0.5*y^4+(x-y)^4)^.25} #dummy k datpois=gdat_cd(pars=pars,N=N,Tp=Tp,seed=2,fun=fnp,eta = 200,modclass="poiscd") #poisson data k=1; lp=k*(k+1)/2; startp = rep(0.2,(lp+2)) RpacSPD::ncd_gen(pars=startp,Y=datpois$Y,X=datpois$X,Xm=NULL,Xi=datpois$X,Tid=datpois$tpID, Pid=datpois$psID,fun=fnp,k=k,nt=lp,utid=c(2:Tp),modclass="poiscd") #return function value#> [1] -37.20221RpacSPD::ncd_gen(pars=startp,Y=datpois$Y,X=datpois$X,Xm=NULL,Xi=datpois$X,Tid=datpois$tpID, Pid=datpois$psID,fun=fnp,k=k,nt=lp,utid=c(2:Tp),modclass="poiscd",rval="Xw") #return Xw#> [1] NA 0.35017894 2.65093026 -0.06148076 1.71964642 1.63012233 #> [7] NA 0.31796577 2.63856312 -0.06686897 1.70835897 1.63485915 #> [13] NA 0.33301962 2.60768315 -0.06386062 1.73261868 1.64187779 #> [19] NA 0.32662226 2.65649662 -0.06859766 1.72054858 1.65385322 #> [25] NA 0.32439823 2.53148271 -0.05733242 1.71294087 1.64035289