Title: | Weighted Scores Method for Regression Models with Dependent Data |
---|---|
Description: | The weighted scores method and composite likelihood information criteria as an intermediate step for variable/correlation selection for longitudinal ordinal and count data in Nikoloulopoulos, Joe and Chaganty (2011) <doi:10.1093/biostatistics/kxr005>, Nikoloulopoulos (2016) <doi:10.1002/sim.6871> and Nikoloulopoulos (2017) <arXiv:1510.07376>. |
Authors: | Aristidis K. Nikoloulopoulos [aut, cre], Harry Joe [aut] |
Maintainer: | Aristidis K. Nikoloulopoulos <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.9.5.3 |
Built: | 2024-11-26 06:25:39 UTC |
Source: | CRAN |
The weighted scores method and CL1 information criteria as an intermediate step for variable/correlation selection for longitudinal ordinal and count data in Nikoloulopoulos, Joe and Chaganty (2011) and Nikoloulopoulos (2016, 2017).
This package contains R functions to implement:
The weighted scores method for regression models with dependent data and negative binomial (Nikoloulopoulos, Joe and Chaganty, 2011), GLM (Nikoloulopoulos, 2016) and ordinal probit/logistic (Nikoloulopoulos, 2017) margins.
The composite likelihood information criteria for regression models with dependent data and ordinal probit/logistic margins (Nikoloulopoulos, 2016, 2017).
Aristidis K. Nikoloulopoulos.
Nikoloulopoulos, A.K., Joe, H. and Chaganty, N.R. (2011) Weighted scores method for regression models with dependent data. Biostatistics, 12, 653–665. doi:10.1093/biostatistics/kxr005.
Nikoloulopoulos, A.K. (2016) Correlation structure and variable selection in generalized estimating equations via composite likelihood information criteria. Statistics in Medicine, 35, 2377–2390. doi:10.1002/sim.6871.
Nikoloulopoulos, A.K. (2017) Weighted scores method for longitudinal ordinal data. Arxiv e-prints, <arXiv:1510.07376>. https://arxiv.org/abs/1510.07376.
Approximation of bivariate standard normal cumulative distribution function (Johnson and Kotz, 1972).
approxbvncdf(r,x1,x2,x1s,x2s,x1c,x2c,x1f,x2f,t1,t2)
approxbvncdf(r,x1,x2,x1s,x2s,x1c,x2c,x1f,x2f,t1,t2)
r |
The correlation parameter of bivariate standard normal distribution. |
x1 |
|
x2 |
|
x1s |
|
x2s |
|
x1c |
|
x2c |
|
x1f |
|
x2f |
|
t1 |
|
t2 |
|
The approximation for the bivariate normal cdf is from Johnson and Kotz (1972),
page 118.
Let ,
where
is bivariate normal with means 0, variances 1 and
correlation
.
An expansion, due to Pearson (1901), is
where
Since
we have
A good approximation is obtained truncating the series
at term for
, and at
term for
.
Higher order terms may be required for
.
An approximation of bivariate normal cumulative distribution function.
Johnson, N. L. and Kotz, S. (1972) Continuous Multivariate Distributions. Wiley, New York.
Pearson, K. (1901) Mathematical contributions to the theory of evolution-VII. On the correlation of characters not quantitatively measureable. Philosophical Transactions of the Royal Society of London, Series A, 195, 1–47.
Rheumatoid self-assessment scores for 302 patients, measured on a five-level ordinal response scale at three follow-up times.
data(arthritis)
data(arthritis)
A data frame with 888 observations on the following 7 variables:
id
Patient identifier variable.
y
Self-assessment score of rheumatoid arthritis measured on a five-level ordinal response scale.
sex
Coded as (1) for female and (2) for male.
age
Recorded at the baseline.
trt
Treatment group variable, coded as (1) for the placebo group and (2) for the drug group.
baseline
Self-assessment score of rheumatoid arthritis at the baseline.
time
Follow-up time recorded in months.
Lipsitz, S.R. and Kim, K. and Zhao, L. (1994). Analysis of repeated categorical data using generalized estimating equations. Statistics in Medicine, 13, 1149–1163.
data(arthritis)
data(arthritis)
Bivariate composite likelihood for multivariate normal copula with categorical and count regression.
bcl(r,b,gam,xdat,ydat,id,tvec,margmodel,corstr,link) bcl.ord(r,b,gam,xdat,ydat,id,tvec,corstr,link)
bcl(r,b,gam,xdat,ydat,id,tvec,margmodel,corstr,link) bcl.ord(r,b,gam,xdat,ydat,id,tvec,corstr,link)
r |
The vector of normal copula parameters. |
b |
The regression coefficients. |
gam |
The uinivariate parameters that are not regression coefficients. That is the parameter |
xdat |
|
ydat |
|
id |
An index for individuals or clusters. |
tvec |
A vector with the time indicator of individuals or clusters. |
margmodel |
Indicates the marginal model. Choices are “poisson” for Poisson, “bernoulli” for Bernoulli, and “nb1” , “nb2” for the NB1 and NB2 parametrization of negative binomial in Cameron and Trivedi (1998). |
corstr |
Indicates the latent correlation structure of normal copula. Choices are “exch”, “ar”, and “unstr” for exchangeable, ar(1) and unstructured correlation structure, respectively. |
link |
The link function. Choices are “log” for the log link function, “logit” for the logit link function, and “probit” for the probit link function. |
The CL1 composite likelihood in Zhao and Joe (2005). That is the sum of bivariate marginal log-likelihoods.
bcl.ord
is a variant of the code for ordinal (probit and logistic) regression.
The negative bivariate composite likelihood for multivariate normal copula with Poisson or binary or negative binomial or ordinal regression.
Aristidis K. Nikoloulopoulos [email protected]
Harry Joe [email protected]
Zhao, Y. and Joe, H. (2005) Composite likelihood estimation in multivariate data analysis. The Canadian Journal of Statistics, 33, 335–356.
Cameron, A. C. and Trivedi, P. K. (1998) Regression Analysis of Count Data. Cambridge: Cambridge University Press.
The response vector consists of quarterly numbers of hospital visits over a
one year period for a child age at four or younger, and three baseline covariates
are age, sex, and maternal smoking status. The sample size of this study is
children.
data(childvisit)
data(childvisit)
A data frame with 292 observations on the following 6 variables.
id
The child ID.
age
The age in months.
sex
The sex indicator.
matsmst
The maternal smoking status.
quarter
The time indicator.
hospvis
The response vector of quarterly numbers of hospital visits.
Song P.X.K. (2007). Correlated Data Analysis: Modeling, Analytics, and Application. Correlated Data Analysis: Modeling, Analytics, and Application. Book Webpage/Supplementary Material. Springer, NY.
Optimization routine for bivariate composite likelihood for MVN copula.
cl1(b,gam,xdat,ydat,id,tvec,margmodel,corstr,link) cl1.ord(b,gam,xdat,ydat,id,tvec,corstr,link)
cl1(b,gam,xdat,ydat,id,tvec,margmodel,corstr,link) cl1.ord(b,gam,xdat,ydat,id,tvec,corstr,link)
b |
The regression coefficients. |
gam |
The uinivariate parameters that are not regression coefficients. That is the parameter |
xdat |
|
ydat |
|
id |
An index for individuals or clusters. |
tvec |
A vector with the time indicator of individuals or clusters. |
margmodel |
Indicates the marginal model. Choices are “poisson” for Poisson, “bernoulli” for Bernoulli, and “nb1” , “nb2” for the NB1 and NB2 parametrization of negative binomial in Cameron and Trivedi (1998). |
corstr |
Indicates the latent correlation structure of normal copula. Choices are “exch”, “ar”, and “unstr” for exchangeable, ar(1) and unstructured correlation structure, respectively. |
link |
The link function. Choices are “log” for the log link function, “logit” for the logit link function, and “probit” for the probit link function. |
The CL1 composite likelihood method in Zhao and Joe (2005). The univariate parameters are estimated from the sum of univariate marginal log-likelihoods and then the dependence parameters are estimated from the sum of bivariate marginal log-likelihoods with the univariate parameters fixed from the first step.
Note that bcl.ord
is a variant of the code for ordinal (probit and logistic) regression.
A list containing the following components:
minimum |
The negative value of the sum of bivariate marginal log-likelihoods at CL1 estimates. |
estimate |
The CL1 estimates. |
gradient |
The gradient at the estimated minimum of CL1. |
code |
An integer indicating why the optimization process terminated,
same as in |
Aristidis K. Nikoloulopoulos [email protected]
Harry Joe [email protected]
Zhao, Y. and Joe, H. (2005) Composite likelihood estimation in multivariate data analysis. The Canadian Journal of Statistics, 33, 335–356.
################################################################################ # NB1 regression for count data ################################################################################ ################################################################################ # read and set up data set ################################################################################ data(childvisit) # covariates season1<-childvisit$q season1[season1>1]<-0 xdat<-cbind(1,childvisit$sex,childvisit$age,childvisit$m,season1) # response ydat<-childvisit$hosp #id id<-childvisit$id #time tvec<-childvisit$q ################################################################################ # select the marginal model ################################################################################ margmodel="nb1" ################################################################################ # select the correlation structure ################################################################################ corstr="exch" ################################################################################ # perform CL1 estimation ################################################################################ i.est<-iee(xdat,ydat,margmodel) cat("\niest: IEE estimates\n") print(c(i.est$reg,i.est$gam)) est.rho<-cl1(b=i.est$reg,gam=i.est$gam,xdat,ydat,id,tvec,margmodel,corstr) cat("\nest.rho: CL1 estimates\n") print(est.rho$e) ################################################################################ # Ordinal regression ################################################################################ ################################################################################ # read and set up data set ################################################################################ data(arthritis) nn=nrow(arthritis) bas2<-bas3<-bas4<-bas5<-rep(0,nn) bas2[arthritis$b==2]<-1 bas3[arthritis$b==3]<-1 bas4[arthritis$b==4]<-1 bas5[arthritis$b==5]<-1 t2<-t3<-rep(0,nn) t2[arthritis$ti==3]<-1 t3[arthritis$ti==5]<-1 xdat=cbind(t2,t3,arthritis$trt,bas2,bas3,bas4,bas5,arthritis$age) ydat=arthritis$y id<-arthritis$id #time tvec<-arthritis$time ################################################################################ # select the link ################################################################################ link="logit" ################################################################################ # select the correlation structure ################################################################################ corstr="exch" ################################################################################ # perform CL1 estimation ################################################################################ i.est<-iee.ord(xdat,ydat,link) cat("\niest: IEE estimates\n") print(c(i.est$reg,i.est$gam)) est.rho<-cl1.ord(b=i.est$reg,gam=i.est$gam,xdat,ydat,id,tvec,corstr,link) cat("\nest.rho: CL1 estimates\n") print(est.rho$e)
################################################################################ # NB1 regression for count data ################################################################################ ################################################################################ # read and set up data set ################################################################################ data(childvisit) # covariates season1<-childvisit$q season1[season1>1]<-0 xdat<-cbind(1,childvisit$sex,childvisit$age,childvisit$m,season1) # response ydat<-childvisit$hosp #id id<-childvisit$id #time tvec<-childvisit$q ################################################################################ # select the marginal model ################################################################################ margmodel="nb1" ################################################################################ # select the correlation structure ################################################################################ corstr="exch" ################################################################################ # perform CL1 estimation ################################################################################ i.est<-iee(xdat,ydat,margmodel) cat("\niest: IEE estimates\n") print(c(i.est$reg,i.est$gam)) est.rho<-cl1(b=i.est$reg,gam=i.est$gam,xdat,ydat,id,tvec,margmodel,corstr) cat("\nest.rho: CL1 estimates\n") print(est.rho$e) ################################################################################ # Ordinal regression ################################################################################ ################################################################################ # read and set up data set ################################################################################ data(arthritis) nn=nrow(arthritis) bas2<-bas3<-bas4<-bas5<-rep(0,nn) bas2[arthritis$b==2]<-1 bas3[arthritis$b==3]<-1 bas4[arthritis$b==4]<-1 bas5[arthritis$b==5]<-1 t2<-t3<-rep(0,nn) t2[arthritis$ti==3]<-1 t3[arthritis$ti==5]<-1 xdat=cbind(t2,t3,arthritis$trt,bas2,bas3,bas4,bas5,arthritis$age) ydat=arthritis$y id<-arthritis$id #time tvec<-arthritis$time ################################################################################ # select the link ################################################################################ link="logit" ################################################################################ # select the correlation structure ################################################################################ corstr="exch" ################################################################################ # perform CL1 estimation ################################################################################ i.est<-iee.ord(xdat,ydat,link) cat("\niest: IEE estimates\n") print(c(i.est$reg,i.est$gam)) est.rho<-cl1.ord(b=i.est$reg,gam=i.est$gam,xdat,ydat,id,tvec,corstr,link) cat("\nest.rho: CL1 estimates\n") print(est.rho$e)
Composite likelihood (CL1) information criteria.
clic1dePar(nbcl,r,b,gam,xdat,id,tvec,corstr,WtScMat,link,mvncmp) clic(nbcl,r,b,gam,xdat,id,tvec,corstr,WtScMat,link,mvncmp)
clic1dePar(nbcl,r,b,gam,xdat,id,tvec,corstr,WtScMat,link,mvncmp) clic(nbcl,r,b,gam,xdat,id,tvec,corstr,WtScMat,link,mvncmp)
nbcl |
The negative value of the sum of bivariate marginal log-likelihoods at CL1 estimates. |
r |
The CL1 estimates of the latent correlations. |
b |
The CL1 estimates of the regression coefficients. |
gam |
The CL1 estimates of the cutpoints. |
xdat |
|
id |
An index for individuals or clusters. |
tvec |
A vector with the time indicator of individuals or clusters. |
WtScMat |
A list containing the following components.
omega: The array with the |
corstr |
Indicates the latent correlation structure of normal copula. Choices are “exch”, “ar”, and “unstr” for exchangeable, ar(1) and unstructured correlation structure, respectively. |
link |
The link function. Choices are “logit” for the logit link function, and “probit” for the probit link function. |
mvncmp |
The method of computation of the MVN rectangle probabilities.
Choices are 1 for |
First, consider the sum of univariate log-likelihoods
and then the sum of bivariate log-likelihoods
where and
denotes the standard bivariate normal density with correlation
.
Let be the
column vector of all
univariate parameters. Differentiating
with respect to
leads to the independent estimating equations or univariate composite score functions:
Differentiating with respect to
leads to the bivariate composite score functions (Zhao and Joe, 2005):
where and
.
The CL1 estimates
and
of the discretized MVN model are obtained
by solving the above CL1 estimating functions.
The asymptotic covariance matrix for the estimator that solves them, also known as the inverse Godambe (Godambe, 1991) information matrix, is
where . First set
, then
where ,
,
and
.
The covariance matrix of the composite score functions
is given as below
where
To this end, the composite AIC (Varin and Vidoni, 2005) and BIC (Gao and Song, 2011) criteria have the forms:
A list containing the following components:
AIC |
The CL1AIC. |
BIC |
The CL1BIC. |
Aristidis K. Nikoloulopoulos [email protected]
Gao, X. and Song, P.X.K. (2011). Composite likelihood EM algorithm with applications to multivariate hidden Markov model. Statistica Sinica 21, 165–185.
Godambe, V. P. (1991) Estimating Functions. Oxford: Oxford University Press
Nikoloulopoulos, A.K., Joe, H. and Chaganty, N.R. (2011) Weighted scores method for regression models with dependent data. Biostatistics, 12, 653–665. doi:10.1093/biostatistics/kxr005.
Nikoloulopoulos, A.K. (2016) Correlation structure and variable selection in generalized estimating equations via composite likelihood information criteria. Statistics in Medicine, 35, 2377–2390. doi:10.1002/sim.6871.
Nikoloulopoulos, A.K. (2017) Weighted scores method for longitudinal ordinal data. Arxiv e-prints, <arXiv:1510.07376>. https://arxiv.org/abs/1510.07376.
Varin, C. and Vidoni, P. (2005). A note on composite likelihood inference and model selection. Biometrika 92, 519–528.
Zhao, Y. and Joe, H. (2005) Composite likelihood estimation in multivariate data analysis. The Canadian Journal of Statistics, 33, 335–356.
################################################################################ # Binary regression ################################################################################ ################################################################################ # read and set up the data set ################################################################################ data(childvisit) # covariates season1<-childvisit$q season1[season1>1]<-0 xdat<-cbind(childvisit$sex,childvisit$age,childvisit$m,season1) # response ydat<-childvisit$hosp ydat[ydat>0]=1 ydat=2-ydat #id id<-childvisit$id #time tvec<-childvisit$q ################################################################################ # select the link ################################################################################ link="logit" ################################################################################ # select the correlation structure ################################################################################ corstr="exch" ################################################################################ # perform CL1 estimation ################################################################################ i.est<-iee.ord(xdat,ydat,link) cat("\niest: IEE estimates\n") print(c(i.est$reg,i.est$gam)) est.rho<-cl1.ord(b=i.est$reg,gam=i.est$gam,xdat,ydat,id,tvec,corstr,link) cat("\nest.rho: CL1 estimates\n") print(est.rho$e) cat("\nest.rho: negative CL1 log-likelhood\n") print(est.rho$m) ################################################################################ # obtain the fixed weight matrices ################################################################################ WtScMat<-weightMat.ord(b=i.est$reg,gam=i.est$gam,rh=0.1961,xdat,ydat,id, tvec,corstr,link) ################################################################################ # obtain the CL1 information criteria ################################################################################ out<-clic1dePar(nbcl=est.rho$m,r=est.rho$e,i.est$r,i.est$g,xdat,id,tvec,corstr,WtScMat,link,1)
################################################################################ # Binary regression ################################################################################ ################################################################################ # read and set up the data set ################################################################################ data(childvisit) # covariates season1<-childvisit$q season1[season1>1]<-0 xdat<-cbind(childvisit$sex,childvisit$age,childvisit$m,season1) # response ydat<-childvisit$hosp ydat[ydat>0]=1 ydat=2-ydat #id id<-childvisit$id #time tvec<-childvisit$q ################################################################################ # select the link ################################################################################ link="logit" ################################################################################ # select the correlation structure ################################################################################ corstr="exch" ################################################################################ # perform CL1 estimation ################################################################################ i.est<-iee.ord(xdat,ydat,link) cat("\niest: IEE estimates\n") print(c(i.est$reg,i.est$gam)) est.rho<-cl1.ord(b=i.est$reg,gam=i.est$gam,xdat,ydat,id,tvec,corstr,link) cat("\nest.rho: CL1 estimates\n") print(est.rho$e) cat("\nest.rho: negative CL1 log-likelhood\n") print(est.rho$m) ################################################################################ # obtain the fixed weight matrices ################################################################################ WtScMat<-weightMat.ord(b=i.est$reg,gam=i.est$gam,rh=0.1961,xdat,ydat,id, tvec,corstr,link) ################################################################################ # obtain the CL1 information criteria ################################################################################ out<-clic1dePar(nbcl=est.rho$m,r=est.rho$e,i.est$r,i.est$g,xdat,id,tvec,corstr,WtScMat,link,1)
Inverse Godambe matrix.
godambe(param,WtScMat,xdat,ydat,id,tvec,margmodel,link) godambe.ord(param,WtScMat,xdat,ydat,id,tvec,link)
godambe(param,WtScMat,xdat,ydat,id,tvec,margmodel,link) godambe.ord(param,WtScMat,xdat,ydat,id,tvec,link)
param |
The weighted scores estimates of regression and not regression parameters. |
WtScMat |
A list containing the following components.
omega: The array with the |
xdat |
|
ydat |
|
id |
An index for individuals or clusters. |
tvec |
A vector with the time indicator of individuals or clusters. |
margmodel |
Indicates the marginal model. Choices are “poisson” for Poisson, “bernoulli” for Bernoulli, and “nb1” , “nb2” for the NB1 and NB2 parametrization of negative binomial in Cameron and Trivedi (1998). |
link |
The link function. Choices are “log” for the log link function, “logit” for the logit link function, and “probit” for the probit link function. |
If the are assumed fixed for the
second stage of solving the weighted scores equations
the asymptotic covariance matrix of the
solution is
with
where is the true covariance matrix of
.
The inverse of
is known as
Godambe information matrix (Godambe, 1991).
Note that godambe.ord
is a variant of the code for ordinal (probit and logistic) regression.
The inverse Godambe matrix.
Aristidis K. Nikoloulopoulos [email protected]
Harry Joe [email protected]
Godambe, V. P. (1991) Estimating Functions. Oxford: Oxford University Press
Nikoloulopoulos, A.K., Joe, H. and Chaganty, N.R. (2011) Weighted scores method for regression models with dependent data. Biostatistics, 12, 653–665. doi:10.1093/biostatistics/kxr005.
Nikoloulopoulos, A.K. (2016) Correlation structure and variable selection in generalized estimating equations via composite likelihood information criteria. Statistics in Medicine, 35, 2377–2390. doi:10.1002/sim.6871.
Nikoloulopoulos, A.K. (2017) Weighted scores method for longitudinal ordinal data. Arxiv e-prints, <arXiv:1510.07376>. https://arxiv.org/abs/1510.07376.
wtsc
,
solvewtsc
,
weightMat
,
wtsc.wrapper
################################################################################ # Poisson regression ################################################################################ ################################################################################ # read and set up the data set ################################################################################ data(childvisit) # covariates season1<-childvisit$q season1[season1>1]<-0 xdat<-cbind(1,childvisit$sex,childvisit$age,childvisit$m,season1) # response ydat<-childvisit$hosp #id id<-childvisit$id #time tvec<-childvisit$q ################################################################################ # select the marginal model ################################################################################ margmodel="poisson" ################################################################################ # select the correlation structure ################################################################################ corstr="exch" ################################################################################ # perform CL1 estimation ################################################################################ i.est<-iee(xdat,ydat,margmodel) cat("\niest: IEE estimates\n") print(c(i.est$reg,i.est$gam)) est.rho<-cl1(b=i.est$reg,gam=i.est$gam,xdat,ydat,id,tvec,margmodel,corstr) cat("\nest.rho: CL1 estimates\n") print(est.rho$e) ################################################################################ # obtain the fixed weight matrices ################################################################################ WtScMat<-weightMat(b=i.est$reg,gam=i.est$gam,rh=est.rho$e, xdat,ydat,id,tvec,margmodel,corstr) ################################################################################ # obtain the weighted scores estimates ################################################################################ # solve the nonlinear system of equations ws<-solvewtsc(start=c(i.est$reg,i.est$gam),WtScMat,xdat,ydat,id, tvec,margmodel,link) cat("ws=parameter estimates\n") print(ws$r) ################################################################################ # obtain the inverse Godambe matrix ################################################################################ acov<-godambe(ws$r,WtScMat,xdat,ydat,id,tvec,margmodel) cat("\nacov: inverse Godambe matrix with W based on first-stage wt matrices\n") print(acov) ################################################################################ # Ordinal regression ################################################################################ ################################################################################ # read and set up data set ################################################################################ data(arthritis) nn=nrow(arthritis) bas2<-bas3<-bas4<-bas5<-rep(0,nn) bas2[arthritis$b==2]<-1 bas3[arthritis$b==3]<-1 bas4[arthritis$b==4]<-1 bas5[arthritis$b==5]<-1 t2<-t3<-rep(0,nn) t2[arthritis$ti==3]<-1 t3[arthritis$ti==5]<-1 xdat=cbind(t2,t3,arthritis$trt,bas2,bas3,bas4,bas5,arthritis$age) ydat=arthritis$y id<-arthritis$id #time tvec<-arthritis$time ################################################################################ # select the link ################################################################################ link="probit" ################################################################################ # select the correlation structure ################################################################################ corstr="exch" ################################################################################ # perform CL1 estimation ################################################################################ i.est<-iee.ord(xdat,ydat,link) cat("\niest: IEE estimates\n") print(c(i.est$reg,i.est$gam)) est.rho<-cl1.ord(b=i.est$reg,gam=i.est$gam,xdat,ydat,id,tvec,corstr,link) cat("\nest.rho: CL1 estimates\n") print(est.rho$e) ################################################################################ # obtain the fixed weight matrices ################################################################################ WtScMat<-weightMat.ord(b=i.est$reg,gam=i.est$gam,rh=est.rho$e,xdat,ydat,id, tvec,corstr,link) ################################################################################ # obtain the weighted scores estimates ################################################################################ # solve the nonlinear system of equations ws<-solvewtsc.ord(start=c(i.est$reg,i.est$gam),WtScMat,xdat,ydat,id, tvec,link) cat("ws=parameter estimates\n") print(ws$r) ################################################################################ # obtain the inverse Godambe matrix ################################################################################ acov<-godambe.ord(ws$r,WtScMat,xdat,ydat,id,tvec,link) cat("\nacov: inverse Godambe matrix with W based on first-stage wt matrices\n") print(acov)
################################################################################ # Poisson regression ################################################################################ ################################################################################ # read and set up the data set ################################################################################ data(childvisit) # covariates season1<-childvisit$q season1[season1>1]<-0 xdat<-cbind(1,childvisit$sex,childvisit$age,childvisit$m,season1) # response ydat<-childvisit$hosp #id id<-childvisit$id #time tvec<-childvisit$q ################################################################################ # select the marginal model ################################################################################ margmodel="poisson" ################################################################################ # select the correlation structure ################################################################################ corstr="exch" ################################################################################ # perform CL1 estimation ################################################################################ i.est<-iee(xdat,ydat,margmodel) cat("\niest: IEE estimates\n") print(c(i.est$reg,i.est$gam)) est.rho<-cl1(b=i.est$reg,gam=i.est$gam,xdat,ydat,id,tvec,margmodel,corstr) cat("\nest.rho: CL1 estimates\n") print(est.rho$e) ################################################################################ # obtain the fixed weight matrices ################################################################################ WtScMat<-weightMat(b=i.est$reg,gam=i.est$gam,rh=est.rho$e, xdat,ydat,id,tvec,margmodel,corstr) ################################################################################ # obtain the weighted scores estimates ################################################################################ # solve the nonlinear system of equations ws<-solvewtsc(start=c(i.est$reg,i.est$gam),WtScMat,xdat,ydat,id, tvec,margmodel,link) cat("ws=parameter estimates\n") print(ws$r) ################################################################################ # obtain the inverse Godambe matrix ################################################################################ acov<-godambe(ws$r,WtScMat,xdat,ydat,id,tvec,margmodel) cat("\nacov: inverse Godambe matrix with W based on first-stage wt matrices\n") print(acov) ################################################################################ # Ordinal regression ################################################################################ ################################################################################ # read and set up data set ################################################################################ data(arthritis) nn=nrow(arthritis) bas2<-bas3<-bas4<-bas5<-rep(0,nn) bas2[arthritis$b==2]<-1 bas3[arthritis$b==3]<-1 bas4[arthritis$b==4]<-1 bas5[arthritis$b==5]<-1 t2<-t3<-rep(0,nn) t2[arthritis$ti==3]<-1 t3[arthritis$ti==5]<-1 xdat=cbind(t2,t3,arthritis$trt,bas2,bas3,bas4,bas5,arthritis$age) ydat=arthritis$y id<-arthritis$id #time tvec<-arthritis$time ################################################################################ # select the link ################################################################################ link="probit" ################################################################################ # select the correlation structure ################################################################################ corstr="exch" ################################################################################ # perform CL1 estimation ################################################################################ i.est<-iee.ord(xdat,ydat,link) cat("\niest: IEE estimates\n") print(c(i.est$reg,i.est$gam)) est.rho<-cl1.ord(b=i.est$reg,gam=i.est$gam,xdat,ydat,id,tvec,corstr,link) cat("\nest.rho: CL1 estimates\n") print(est.rho$e) ################################################################################ # obtain the fixed weight matrices ################################################################################ WtScMat<-weightMat.ord(b=i.est$reg,gam=i.est$gam,rh=est.rho$e,xdat,ydat,id, tvec,corstr,link) ################################################################################ # obtain the weighted scores estimates ################################################################################ # solve the nonlinear system of equations ws<-solvewtsc.ord(start=c(i.est$reg,i.est$gam),WtScMat,xdat,ydat,id, tvec,link) cat("ws=parameter estimates\n") print(ws$r) ################################################################################ # obtain the inverse Godambe matrix ################################################################################ acov<-godambe.ord(ws$r,WtScMat,xdat,ydat,id,tvec,link) cat("\nacov: inverse Godambe matrix with W based on first-stage wt matrices\n") print(acov)
Independent estimating equations for binary and count regression.
iee(xdat,ydat,margmodel,link)
iee(xdat,ydat,margmodel,link)
xdat |
|
ydat |
|
margmodel |
Indicates the marginal model. Choices are “poisson” for Poisson, “bernoulli” for Bernoulli, and “nb1” , “nb2” for the NB1 and NB2 parametrization of negative binomial in Cameron and Trivedi (1998). |
link |
The link function. Choices are “log” for the log link function, “logit” for the logit link function, and “probit” for the probit link function. |
The univariate parameters are estimated from the sum of univariate marginal log-likelihoods.
A list containing the following components:
coef |
The vector with the estimated regression parameters. |
gam |
The vector with the estimated parameters that are not regression parameters. This is NULL for Poisson and binary regression. |
Aristidis K. Nikoloulopoulos [email protected]
Harry Joe [email protected]
Cameron, A. C. and Trivedi, P. K. (1998) Regression Analysis of Count Data. Cambridge: Cambridge University Press.
################################################################################ # read and set up data set ################################################################################ data(toenail) # covariates xdat<-cbind(1,toenail$treat,toenail$time,toenail$treat*toenail$time) # response ydat<-toenail$y #id id<-toenail$id #time tvec<-toenail$time ################################################################################ # select the marginal model ################################################################################ margmodel="bernoulli" ################################################################################ # perform the IEE method ################################################################################ i.est<-iee(xdat,ydat,margmodel) cat("\niest: IEE estimates\n") print(c(i.est$reg,i.est$gam))
################################################################################ # read and set up data set ################################################################################ data(toenail) # covariates xdat<-cbind(1,toenail$treat,toenail$time,toenail$treat*toenail$time) # response ydat<-toenail$y #id id<-toenail$id #time tvec<-toenail$time ################################################################################ # select the marginal model ################################################################################ margmodel="bernoulli" ################################################################################ # perform the IEE method ################################################################################ i.est<-iee(xdat,ydat,margmodel) cat("\niest: IEE estimates\n") print(c(i.est$reg,i.est$gam))
Maximum Likelihood for Ordinal Probit and Logit: Newton-Raphson minimization of negative log-likelihood.
iee.ord(x,y,link,iprint=0,maxiter=20,toler=1.e-6)
iee.ord(x,y,link,iprint=0,maxiter=20,toler=1.e-6)
x |
vector or matrix of explanatory variables. Each row corresponds to an observation and each column to a variable. The number of rows of x should equal the number of data values in y, and there should be fewer columns than rows. Missing values are not allowed. |
y |
numeric vector containing the ordinal response. The values must be in the range 1,2,..., number of categories. Missing values are not allowed. |
link |
The link function.Choices are “logit” for the logit link function, and “probit” for the probit link function. |
iprint |
logical indicator, default is FALSE, for whether the iterations for numerical maximum likelihood should be printed. |
maxiter |
maximum number of Newton-Raphson iterations, default = 20. |
toler |
tolerance for convergence in Newton-Raphson iterations, default = 1.e-6. |
The ordinal probit model is similar to the ordinal logit model. The parameter estimate of ordinal logit are roughly 1.8 to 2 times those of ordinal probit.
list of MLE of parameters and their associated standard errors, in the order cutpt1,...,cutpt(number of categ-1),b1,...b(number of covariates).
negloglik |
value of negative log-likelihood, evaluated at MLE |
gam |
MLE of ordered cutpoint parameters |
reg |
MLE of regression parameters |
cov |
estimated covariance matrix of the parameters |
Aristidis K. Nikoloulopoulos [email protected]
Harry Joe [email protected]
Anderson, J.A. and Pemberton, J.D. (1985). The grouped continuous model for multivariate ordered categorical variables and covariate adjustment. Biometrics, 41, 875–885.
################################################################################ # Ordinal regression ################################################################################ ################################################################################ # read and set up data set ################################################################################ data(arthritis) nn=nrow(arthritis) bas2<-bas3<-bas4<-bas5<-rep(0,nn) bas2[arthritis$b==2]<-1 bas3[arthritis$b==3]<-1 bas4[arthritis$b==4]<-1 bas5[arthritis$b==5]<-1 t2<-t3<-rep(0,nn) t2[arthritis$ti==3]<-1 t3[arthritis$ti==5]<-1 xdat=cbind(t2,t3,arthritis$trt,bas2,bas3,bas4,bas5,arthritis$age) ydat=arthritis$y ################################################################################ # select the link ################################################################################ link="probit" ################################################################################ i.est<- iee.ord(xdat,ydat,link) print(i.est)
################################################################################ # Ordinal regression ################################################################################ ################################################################################ # read and set up data set ################################################################################ data(arthritis) nn=nrow(arthritis) bas2<-bas3<-bas4<-bas5<-rep(0,nn) bas2[arthritis$b==2]<-1 bas3[arthritis$b==3]<-1 bas4[arthritis$b==4]<-1 bas5[arthritis$b==5]<-1 t2<-t3<-rep(0,nn) t2[arthritis$ti==3]<-1 t3[arthritis$ti==5]<-1 xdat=cbind(t2,t3,arthritis$trt,bas2,bas3,bas4,bas5,arthritis$age) ydat=arthritis$y ################################################################################ # select the link ################################################################################ link="probit" ################################################################################ i.est<- iee.ord(xdat,ydat,link) print(i.est)
Negative log-likelihood assuming independence within clusters.
marglik(param,xdat,ydat,margmodel,link)
marglik(param,xdat,ydat,margmodel,link)
param |
The vector of regression and not regression parameters. |
xdat |
|
ydat |
|
margmodel |
Indicates the marginal model. Choices are “poisson” for Poisson, “bernoulli” for Bernoulli, and “nb1” , “nb2” for the NB1 and NB2 parametrization of negative binomial in Cameron and Trivedi (1998). |
link |
The link function. Choices are “log” for the log link function, “logit” for the logit link function, and “probit” for the probit link function. |
The negative sum of univariate marginal log-likelihoods.
Minus log-likelihood assuming independence.
Aristidis K. Nikoloulopoulos [email protected]
Harry Joe [email protected]
Cameron, A. C. and Trivedi, P. K. (1998) Regression Analysis of Count Data. Cambridge: Cambridge University Press.
Density and cdf of the univariate marginal distribution.
dmargmodel(y,mu,gam,invgam,margmodel) pmargmodel(y,mu,gam,invgam,margmodel) dmargmodel.ord(y,mu,gam,link) pmargmodel.ord(y,mu,gam,link)
dmargmodel(y,mu,gam,invgam,margmodel) pmargmodel(y,mu,gam,invgam,margmodel) dmargmodel.ord(y,mu,gam,link) pmargmodel.ord(y,mu,gam,link)
y |
Vector of (non-negative integer) quantiles. |
mu |
The parameter |
gam |
The parameter(s) |
invgam |
The inverse of parameter |
margmodel |
Indicates the marginal model. Choices are “poisson” for Poisson, “bernoulli” for Bernoulli, and “nb1” , “nb2” for the NB1 and NB2 parametrization of negative binomial in Cameron and Trivedi (1998). See details. |
link |
The link function. Choices are “logit” for the logit link function, and “probit” for the probit link function. |
Negative binomial distribution
NB allows for overdispersion
and its probability mass function (pmf) is given by
with mean and variance
.
Cameron and Trivedi (1998) present the NBk parametrization where
and
,
.
In this function we use the NB1 parametrization
, and the NB2 parametrization
; the latter
is the same as in Lawless (1987).
margmodel.ord
is a variant of the code for ordinal (probit and logistic) model. In this case, the response is assumed to have density
where is a function of
and the
-dimensional regression vector
, and
is the $q$-dimensional vector of the univariate cutpoints (
). Note that
normal leads to the probit model and
logistic
leads to the cumulative logit model for ordinal response.
The density and cdf of the univariate distribution.
Aristidis K. Nikoloulopoulos [email protected]
Harry Joe [email protected]
Cameron, A. C. and Trivedi, P. K. (1998) Regression Analysis of Count Data. Cambridge: Cambridge University Press.
Lawless, J. F. (1987) Negative binomial and mixed Poisson regression. The Canadian Journal of Statistics, 15, 209–225.
y<-3 gam<-2.5 invgam<-1/2.5 mu<-0.5 margmodel<-"nb2" dmargmodel(y,mu,gam,invgam,margmodel) pmargmodel(y,mu,gam,invgam,margmodel) link="probit" dmargmodel.ord(y,mu,gam,link) pmargmodel.ord(y,mu,gam,link)
y<-3 gam<-2.5 invgam<-1/2.5 mu<-0.5 margmodel<-"nb2" dmargmodel(y,mu,gam,invgam,margmodel) pmargmodel(y,mu,gam,invgam,margmodel) link="probit" dmargmodel.ord(y,mu,gam,link) pmargmodel.ord(y,mu,gam,link)
Derivatives of Multivariate Normal Rectangle Probabilities based on Approximations
mvn.deriv.margin(lb,ub,mu,sigma,k,ksign,type=1,eps=1.e-05,nsim=0) mvn.deriv.rho(lb,ub,mu,sigma,j1,k1,type=1,eps=1.e-05,nsim=0)
mvn.deriv.margin(lb,ub,mu,sigma,k,ksign,type=1,eps=1.e-05,nsim=0) mvn.deriv.rho(lb,ub,mu,sigma,j1,k1,type=1,eps=1.e-05,nsim=0)
lb |
vector of lower limits of integral/probability |
ub |
vector of upper limits of integral/probability |
mu |
mean vector |
sigma |
covariance matrix, it is assumed to be positive-definite |
type |
indicator, type=1 refers to the first order approximation, type=2 is the second order approximation. |
eps |
accuracy/tolerance for bivariate marginal rectangle probabilities |
nsim |
an optional integer if random permutations are used in the approximation for dimension >=6; nsim=2000 recommended for dim>=6 |
k |
margin for which derivative is to be taken, that is, deriv of mvnapp(lb,ub,mu,sigma) with respect to lb[k] or ub[k]; |
ksign |
=-1 for deriv of mvnapp(lb,ub,mu,sigma) with respect to lb[k] =+1 for deriv of mvnapp(lb,ub,mu,sigma) with respect to ub[k] |
j1 |
correlation for which derivative is to be taken, that is, deriv of mvnapp(lb,ub,mu,sigma) with respect to rho[j1,k1], where rho is a correlation corresponding to sigma |
k1 |
See above explanation with j1 |
derivative with respect to margin lb[k], ub[k], or correlation rho[j1][k1] corresponding to sigmamatrix
Harry Joe [email protected]
Joe, H (1995). Approximations to multivariate normal rectangle probabilities based on conditional expectations. Journal of American Statistical Association, 90, 957–964.
# step size for numerical derivatives (accuracy of mvnapp etc may be about 1.e-4 to 1.e-5) heps = 1.e-3 cat("compare numerical and analytical derivatives based on mvnapp\n") cat("\ncase 1: dim=3\n"); m=3 mu=rep(0,m) a=c(0,0,0) b=c(1,1.5,2) rr=matrix(c(1,.3,.3,.3,1,.4,.3,.4,1),m,m) pr=mvnapp(a,b,mu,rr)$pr # not checking ifail returned from mvnapp cat("pr=mvnapp(avec,bvec,mu=0,sigma=corrmat)=",pr,"\n") cat("derivative wrt a_k,b_k, k=1,...,",m,"\n") for(k in 1:m) { cat(" k=", k, " lower\n") a2=a a2[k]=a[k]+heps pr2=mvnapp(a2,b,mu,rr)$pr da.numerical = (pr2-pr)/heps da.analytic= mvn.deriv.margin(a,b,mu,rr,k,-1)$deriv cat(" numerical: ", da.numerical, ", analytic: ", da.analytic,"\n") cat(" k=", k, " upper\n") b2=b b2[k]=b[k]+heps pr2=mvnapp(a,b2,mu,rr)$pr db.numerical = (pr2-pr)/heps db.analytic= mvn.deriv.margin(a,b,mu,rr,k,1)$deriv cat(" numerical: ", db.numerical, ", analytic: ", db.analytic,"\n") } cat("derivative wrt rho(j,k)\n") for(j in 1:(m-1)) { for(k in (j+1):m) { cat(" (j,k)=", j,k,"\n") rr2=rr rr2[j,k]=rr[j,k]+heps rr2[k,j]=rr[k,j]+heps pr2=mvnapp(a,b,mu,rr2)$pr drh.numerical = (pr2-pr)/heps drh.analytic= mvn.deriv.rho(a,b,mu,rr2,j,k)$deriv cat(" numerical: ", drh.numerical, ", analytic: ", drh.analytic,"\n") } } #============================================= cat("\ncase 2: dim=5\n"); m=5 mu=rep(0,m) a=c(0,0,0,-1,-1) b=c(1,1.5,2,2,2) rr=matrix(c(1,.3,.3,.3,.4, .3,1,.4,.4,.4, .3,.4,1,.4,.4, .3,.4,.4,1,.4, .4,.4,.4,.4,1),m,m) pr=mvnapp(a,b,mu,rr)$pr # not checking ifail returned from mvnapp cat("pr=mvnapp(avec,bvec,mu=0,sigma=corrmat)=",pr,"\n") cat("derivative wrt a_k,b_k, k=1,...,",m,"\n") for(k in 1:m) { cat(" k=", k, " lower\n") a2=a a2[k]=a[k]+heps pr2=mvnapp(a2,b,mu,rr)$pr da.numerical = (pr2-pr)/heps da.analytic= mvn.deriv.margin(a,b,mu,rr,k,-1)$deriv cat(" numerical: ", da.numerical, ", analytic: ", da.analytic,"\n") cat(" k=", k, " upper\n") b2=b b2[k]=b[k]+heps pr2=mvnapp(a,b2,mu,rr)$pr db.numerical = (pr2-pr)/heps db.analytic= mvn.deriv.margin(a,b,mu,rr,k,1)$deriv cat(" numerical: ", db.numerical, ", analytic: ", db.analytic,"\n") } cat("derivative wrt rho(j,k): first order approx\n") for(j in 1:(m-1)) { for(k in (j+1):m) { cat(" (j,k)=", j,k,"\n") rr2=rr rr2[j,k]=rr[j,k]+heps rr2[k,j]=rr[k,j]+heps pr2=mvnapp(a,b,mu,rr2)$pr drh.numerical = (pr2-pr)/heps drh.analytic= mvn.deriv.rho(a,b,mu,rr2,j,k)$deriv cat(" numerical: ", drh.numerical, ", analytic: ", drh.analytic,"\n") } } cat("\nsecond order approx\n") pr=mvnapp(a,b,mu,rr,type=2)$pr cat("pr=mvnapp(avec,bvec,mu=0,sigma=corrmat,type=2)=",pr,"\n") cat("derivative wrt a_k,b_k, k=1,...,",m,"\n") for(k in 1:m) { cat(" k=", k, " lower\n") a2=a a2[k]=a[k]+heps pr2=mvnapp(a2,b,mu,rr,type=2)$pr da.numerical = (pr2-pr)/heps da.analytic= mvn.deriv.margin(a,b,mu,rr,k,-1,type=2)$deriv cat(" numerical: ", da.numerical, ", analytic: ", da.analytic,"\n") cat(" k=", k, " upper\n") b2=b b2[k]=b[k]+heps pr2=mvnapp(a,b2,mu,rr,type=2)$pr db.numerical = (pr2-pr)/heps db.analytic= mvn.deriv.margin(a,b,mu,rr,k,1,type=2)$deriv cat(" numerical: ", db.numerical, ", analytic: ", db.analytic,"\n") } cat("derivative wrt rho(j,k): second order approx\n") for(j in 1:(m-1)) { for(k in (j+1):m) { cat(" (j,k)=", j,k,"\n") rr2=rr rr2[j,k]=rr[j,k]+heps rr2[k,j]=rr[k,j]+heps pr2=mvnapp(a,b,mu,rr2,type=2)$pr drh.numerical = (pr2-pr)/heps drh.analytic= mvn.deriv.rho(a,b,mu,rr2,j,k,type=2)$deriv cat(" numerical: ", drh.numerical, ", analytic: ", drh.analytic,"\n") } }
# step size for numerical derivatives (accuracy of mvnapp etc may be about 1.e-4 to 1.e-5) heps = 1.e-3 cat("compare numerical and analytical derivatives based on mvnapp\n") cat("\ncase 1: dim=3\n"); m=3 mu=rep(0,m) a=c(0,0,0) b=c(1,1.5,2) rr=matrix(c(1,.3,.3,.3,1,.4,.3,.4,1),m,m) pr=mvnapp(a,b,mu,rr)$pr # not checking ifail returned from mvnapp cat("pr=mvnapp(avec,bvec,mu=0,sigma=corrmat)=",pr,"\n") cat("derivative wrt a_k,b_k, k=1,...,",m,"\n") for(k in 1:m) { cat(" k=", k, " lower\n") a2=a a2[k]=a[k]+heps pr2=mvnapp(a2,b,mu,rr)$pr da.numerical = (pr2-pr)/heps da.analytic= mvn.deriv.margin(a,b,mu,rr,k,-1)$deriv cat(" numerical: ", da.numerical, ", analytic: ", da.analytic,"\n") cat(" k=", k, " upper\n") b2=b b2[k]=b[k]+heps pr2=mvnapp(a,b2,mu,rr)$pr db.numerical = (pr2-pr)/heps db.analytic= mvn.deriv.margin(a,b,mu,rr,k,1)$deriv cat(" numerical: ", db.numerical, ", analytic: ", db.analytic,"\n") } cat("derivative wrt rho(j,k)\n") for(j in 1:(m-1)) { for(k in (j+1):m) { cat(" (j,k)=", j,k,"\n") rr2=rr rr2[j,k]=rr[j,k]+heps rr2[k,j]=rr[k,j]+heps pr2=mvnapp(a,b,mu,rr2)$pr drh.numerical = (pr2-pr)/heps drh.analytic= mvn.deriv.rho(a,b,mu,rr2,j,k)$deriv cat(" numerical: ", drh.numerical, ", analytic: ", drh.analytic,"\n") } } #============================================= cat("\ncase 2: dim=5\n"); m=5 mu=rep(0,m) a=c(0,0,0,-1,-1) b=c(1,1.5,2,2,2) rr=matrix(c(1,.3,.3,.3,.4, .3,1,.4,.4,.4, .3,.4,1,.4,.4, .3,.4,.4,1,.4, .4,.4,.4,.4,1),m,m) pr=mvnapp(a,b,mu,rr)$pr # not checking ifail returned from mvnapp cat("pr=mvnapp(avec,bvec,mu=0,sigma=corrmat)=",pr,"\n") cat("derivative wrt a_k,b_k, k=1,...,",m,"\n") for(k in 1:m) { cat(" k=", k, " lower\n") a2=a a2[k]=a[k]+heps pr2=mvnapp(a2,b,mu,rr)$pr da.numerical = (pr2-pr)/heps da.analytic= mvn.deriv.margin(a,b,mu,rr,k,-1)$deriv cat(" numerical: ", da.numerical, ", analytic: ", da.analytic,"\n") cat(" k=", k, " upper\n") b2=b b2[k]=b[k]+heps pr2=mvnapp(a,b2,mu,rr)$pr db.numerical = (pr2-pr)/heps db.analytic= mvn.deriv.margin(a,b,mu,rr,k,1)$deriv cat(" numerical: ", db.numerical, ", analytic: ", db.analytic,"\n") } cat("derivative wrt rho(j,k): first order approx\n") for(j in 1:(m-1)) { for(k in (j+1):m) { cat(" (j,k)=", j,k,"\n") rr2=rr rr2[j,k]=rr[j,k]+heps rr2[k,j]=rr[k,j]+heps pr2=mvnapp(a,b,mu,rr2)$pr drh.numerical = (pr2-pr)/heps drh.analytic= mvn.deriv.rho(a,b,mu,rr2,j,k)$deriv cat(" numerical: ", drh.numerical, ", analytic: ", drh.analytic,"\n") } } cat("\nsecond order approx\n") pr=mvnapp(a,b,mu,rr,type=2)$pr cat("pr=mvnapp(avec,bvec,mu=0,sigma=corrmat,type=2)=",pr,"\n") cat("derivative wrt a_k,b_k, k=1,...,",m,"\n") for(k in 1:m) { cat(" k=", k, " lower\n") a2=a a2[k]=a[k]+heps pr2=mvnapp(a2,b,mu,rr,type=2)$pr da.numerical = (pr2-pr)/heps da.analytic= mvn.deriv.margin(a,b,mu,rr,k,-1,type=2)$deriv cat(" numerical: ", da.numerical, ", analytic: ", da.analytic,"\n") cat(" k=", k, " upper\n") b2=b b2[k]=b[k]+heps pr2=mvnapp(a,b2,mu,rr,type=2)$pr db.numerical = (pr2-pr)/heps db.analytic= mvn.deriv.margin(a,b,mu,rr,k,1,type=2)$deriv cat(" numerical: ", db.numerical, ", analytic: ", db.analytic,"\n") } cat("derivative wrt rho(j,k): second order approx\n") for(j in 1:(m-1)) { for(k in (j+1):m) { cat(" (j,k)=", j,k,"\n") rr2=rr rr2[j,k]=rr[j,k]+heps rr2[k,j]=rr[k,j]+heps pr2=mvnapp(a,b,mu,rr2,type=2)$pr drh.numerical = (pr2-pr)/heps drh.analytic= mvn.deriv.rho(a,b,mu,rr2,j,k,type=2)$deriv cat(" numerical: ", drh.numerical, ", analytic: ", drh.analytic,"\n") } }
Approximation to multivariate normal rectangle probabilities using methods in Joe (1995, JASA)
mvnapp(lb,ub,mu,sigma,type=1,eps=1.e-05,nsim=0)
mvnapp(lb,ub,mu,sigma,type=1,eps=1.e-05,nsim=0)
lb |
vector of lower limits of integral/probability |
ub |
vector of upper limits of integral/probability |
mu |
mean vector |
sigma |
covariance matrix, it is assumed to be positive-definite |
type |
indicator, type=1 refers to the first order approximation, type=2 is the second order approximation. |
eps |
accuracy/tolerance for bivariate marginal rectangle probabilities |
nsim |
an optional integer if random permutations are used in the approximation for dimension >=6; nsim=2000 recommended for dim>=6 |
prob |
rectangle probability with approximation |
esterr |
indicator of accuracy in the approximation |
ifail |
= 0 if no problems >= 1 if problems from using Schervish's code in dimensions 2 to 4. |
Harry Joe [email protected]
Joe, H (1995). Approximations to multivariate normal rectangle probabilities based on conditional expectations. Journal of American Statistical Association, 90, 957–964.
m<-2 rh<-0.5 a<-c(-1,-1) b<-c(1,1) mu<-rep(0,m) s<-matrix(c(1,rh,rh,1),2,2) print(mvnapp(a,b,mu,s)) print(mvnapp(a,b,mu,s,type=2)) print(mvnapp(a,b,mu,s,type=2,nsim=3)) m<-3 rh<-0.3 a<-c(-1,-1,-2) b<-c(1,1,.5) mu<-rep(0,m) s<-matrix(c(1,.5,.6,.5,1,.7,.6,.7,1),3,3) print(mvnapp(a,b,mu,s)) print(mvnapp(a,b,mu,s,type=2)) print(mvnapp(a,b,mu,s,type=2,nsim=3)) m<-4 rh<- -0.1 a<-c(-1,-2.5,-2,-1.5) b<-c(1.68,1.11,.5,.25) mu<-rep(0,m) s<-matrix(c(1,.5,.3,.4,.5,1,.5,.4,.3,.5,1,.4,.4,.4,.4,1),m,m) print(mvnapp(a,b,mu,s)) print(mvnapp(a,b,mu,s,type=2)) print(mvnapp(a,b,mu,s,type=2,nsim=3)) m<-5 rh<-.4 a<-rep(-1,m) b<-rep(2,m) mu<-rep(0,m) s<-matrix(c(1,rh,rh,rh,rh,rh,1,rh,rh,rh,rh,rh,1,rh,rh,rh,rh,rh,1, rh,rh,rh,rh,rh,1),m,m) print(mvnapp(a,b,mu,s)) print(mvnapp(a,b,mu,s,type=2)) print(mvnapp(a,b,mu,s,type=2,nsim=3)) m<-6 a<-c(-1,-1,-1,-1.5,-1,-2) b<-rep(7,m) mu<-rep(0,m) s<-matrix(c(1,rh,rh,rh,rh,rh,rh,1,rh,rh,rh,rh,rh,rh,1,rh,rh,rh,rh,rh,rh,1, rh,rh,rh,rh,rh,rh,1,rh,rh,rh,rh,rh,rh,1),m,m) print(mvnapp(a,b,mu,s)) print(mvnapp(a,b,mu,s,type=2)) print(mvnapp(a,b,mu,s,type=2,nsim=3))
m<-2 rh<-0.5 a<-c(-1,-1) b<-c(1,1) mu<-rep(0,m) s<-matrix(c(1,rh,rh,1),2,2) print(mvnapp(a,b,mu,s)) print(mvnapp(a,b,mu,s,type=2)) print(mvnapp(a,b,mu,s,type=2,nsim=3)) m<-3 rh<-0.3 a<-c(-1,-1,-2) b<-c(1,1,.5) mu<-rep(0,m) s<-matrix(c(1,.5,.6,.5,1,.7,.6,.7,1),3,3) print(mvnapp(a,b,mu,s)) print(mvnapp(a,b,mu,s,type=2)) print(mvnapp(a,b,mu,s,type=2,nsim=3)) m<-4 rh<- -0.1 a<-c(-1,-2.5,-2,-1.5) b<-c(1.68,1.11,.5,.25) mu<-rep(0,m) s<-matrix(c(1,.5,.3,.4,.5,1,.5,.4,.3,.5,1,.4,.4,.4,.4,1),m,m) print(mvnapp(a,b,mu,s)) print(mvnapp(a,b,mu,s,type=2)) print(mvnapp(a,b,mu,s,type=2,nsim=3)) m<-5 rh<-.4 a<-rep(-1,m) b<-rep(2,m) mu<-rep(0,m) s<-matrix(c(1,rh,rh,rh,rh,rh,1,rh,rh,rh,rh,rh,1,rh,rh,rh,rh,rh,1, rh,rh,rh,rh,rh,1),m,m) print(mvnapp(a,b,mu,s)) print(mvnapp(a,b,mu,s,type=2)) print(mvnapp(a,b,mu,s,type=2,nsim=3)) m<-6 a<-c(-1,-1,-1,-1.5,-1,-2) b<-rep(7,m) mu<-rep(0,m) s<-matrix(c(1,rh,rh,rh,rh,rh,rh,1,rh,rh,rh,rh,rh,rh,1,rh,rh,rh,rh,rh,rh,1, rh,rh,rh,rh,rh,rh,1,rh,rh,rh,rh,rh,rh,1),m,m) print(mvnapp(a,b,mu,s)) print(mvnapp(a,b,mu,s,type=2)) print(mvnapp(a,b,mu,s,type=2,nsim=3))
Covariance matrix of the univariates scores.
scoreCov(scnu,scgam,pmf,index,margmodel) scoreCov.ord(scgam,pmf,index)
scoreCov(scnu,scgam,pmf,index,margmodel) scoreCov.ord(scgam,pmf,index)
scnu |
The matrix of the score functions with respect to |
scgam |
The matrix of the score functions with respect to |
pmf |
The matrix of rectangle probabilities. |
index |
The bivariate pair. |
margmodel |
Indicates the marginal model. Choices are “poisson” for Poisson, “bernoulli” for Bernoulli, and “nb1” , “nb2” for the NB1 and NB2 parametrization of negative binomial in Cameron and Trivedi (1998). |
The covariance matrix of
computed from the
fitted discretized MVN model with estimated parameters
.
Note that scoreCov.ord
is a variant of the code for ordinal (probit and logistic) regression.
Covariance matrix of the univariates scores .
Aristidis K. Nikoloulopoulos [email protected]
Harry Joe [email protected]
Solving the weighted scores equations with inputs of the weight matrices and the data.
solvewtsc(start,WtScMat,xdat,ydat,id,tvec,margmodel,link) solvewtsc.ord(start,WtScMat,xdat,ydat,id,tvec,link)
solvewtsc(start,WtScMat,xdat,ydat,id,tvec,margmodel,link) solvewtsc.ord(start,WtScMat,xdat,ydat,id,tvec,link)
start |
A starting value of the vector of regression and not regression parameters. The CL1 estimates of regression and not regression parameters is a good starting value. |
WtScMat |
A list containing the following components.
omega: The array with the |
xdat |
|
ydat |
|
id |
An index for individuals or clusters. |
tvec |
A vector with the time indicator of individuals or clusters. |
margmodel |
Indicates the marginal model. Choices are “poisson” for Poisson, “bernoulli” for Bernoulli, and “nb1” , “nb2” for the NB1 and NB2 parametrization of negative binomial in Cameron and Trivedi (1998). |
link |
The link function. Choices are “log” for the log link function, “logit” for the logit link function, and “probit” for the probit link function. |
Obtain robust estimates of the univariate parameters
solving the weighted scores equation,
where
is based on
the covariance matrix of
computed from the
fitted discretized MVN model with estimated parameters
. A reliable non-linear system solver is used.
Note that solvewtsc.ord
is a variant of the code for ordinal (probit and logistic) regression.
A list containing the following components:
root |
The weighted scores estimates. |
f.root |
The value of the wtsc function evaluated at the root. |
iter |
The number of iterations used. |
estim.precis |
The estimated precision for root. |
Aristidis K. Nikoloulopoulos [email protected]
Harry Joe [email protected]
Nikoloulopoulos, A.K., Joe, H. and Chaganty, N.R. (2011) Weighted scores method for regression models with dependent data. Biostatistics, 12, 653–665. doi:10.1093/biostatistics/kxr005.
Nikoloulopoulos, A.K. (2016) Correlation structure and variable selection in generalized estimating equations via composite likelihood information criteria. Statistics in Medicine, 35, 2377–2390. doi:10.1002/sim.6871.
Nikoloulopoulos, A.K. (2017) Weighted scores method for longitudinal ordinal data. Arxiv e-prints, <arXiv:1510.07376>. https://arxiv.org/abs/1510.07376.
wtsc
,
weightMat
,
godambe
,
wtsc.wrapper
################################################################################ # NB2 regression ################################################################################ ################################################################################ # read and set up the data set ################################################################################ data(childvisit) # covariates season1<-childvisit$q season1[season1>1]<-0 xdat<-cbind(1,childvisit$sex,childvisit$age,childvisit$m,season1) # response ydat<-childvisit$hosp #id id<-childvisit$id #time tvec<-childvisit$q ################################################################################ # select the marginal model ################################################################################ margmodel="nb2" ################################################################################ # select the correlation structure ################################################################################ corstr="exch" ################################################################################ # perform CL1 estimation ################################################################################ i.est<-iee(xdat,ydat,margmodel) cat("\niest: IEE estimates\n") print(c(i.est$reg,i.est$gam)) est.rho<-cl1(b=i.est$reg,gam=i.est$gam,xdat,ydat,id,tvec,margmodel,corstr,link) cat("\nest.rho: CL1 estimates\n") print(est.rho$e) ################################################################################ # obtain the fixed weight matrices ################################################################################ WtScMat<-weightMat(b=i.est$reg,gam=i.est$gam,rh=est.rho$e, xdat,ydat,id,tvec,margmodel,corstr) ################################################################################ # obtain the weighted scores estimates ################################################################################ # solve the nonlinear system of equations ws<-solvewtsc(start=c(i.est$reg,i.est$gam),WtScMat,xdat,ydat,id, tvec,margmodel,link) cat("ws=parameter estimates\n") print(ws$r) ################################################################################ # Ordinal regression ################################################################################ ################################################################################ # read and set up data set ################################################################################ data(arthritis) nn=nrow(arthritis) bas2<-bas3<-bas4<-bas5<-rep(0,nn) bas2[arthritis$b==2]<-1 bas3[arthritis$b==3]<-1 bas4[arthritis$b==4]<-1 bas5[arthritis$b==5]<-1 t2<-t3<-rep(0,nn) t2[arthritis$ti==3]<-1 t3[arthritis$ti==5]<-1 xdat=cbind(t2,t3,arthritis$trt,bas2,bas3,bas4,bas5,arthritis$age) ydat=arthritis$y id<-arthritis$id #time tvec<-arthritis$time ################################################################################ # select the link ################################################################################ link="probit" ################################################################################ # select the correlation structure ################################################################################ corstr="exch" ################################################################################ # perform CL1 estimation ################################################################################ i.est<-iee.ord(xdat,ydat,link) cat("\niest: IEE estimates\n") print(c(i.est$reg,i.est$gam)) est.rho<-cl1.ord(b=i.est$reg,gam=i.est$gam,xdat,ydat,id,tvec,corstr,link) cat("\nest.rho: CL1 estimates\n") print(est.rho$e) ################################################################################ # obtain the fixed weight matrices ################################################################################ WtScMat<-weightMat.ord(b=i.est$reg,gam=i.est$gam,rh=est.rho$e,xdat,ydat,id, tvec,corstr,link) ################################################################################ # obtain the weighted scores estimates ################################################################################ # solve the nonlinear system of equations ws<-solvewtsc.ord(start=c(i.est$reg,i.est$gam),WtScMat,xdat,ydat,id, tvec,link) cat("ws=parameter estimates\n") print(ws$r)
################################################################################ # NB2 regression ################################################################################ ################################################################################ # read and set up the data set ################################################################################ data(childvisit) # covariates season1<-childvisit$q season1[season1>1]<-0 xdat<-cbind(1,childvisit$sex,childvisit$age,childvisit$m,season1) # response ydat<-childvisit$hosp #id id<-childvisit$id #time tvec<-childvisit$q ################################################################################ # select the marginal model ################################################################################ margmodel="nb2" ################################################################################ # select the correlation structure ################################################################################ corstr="exch" ################################################################################ # perform CL1 estimation ################################################################################ i.est<-iee(xdat,ydat,margmodel) cat("\niest: IEE estimates\n") print(c(i.est$reg,i.est$gam)) est.rho<-cl1(b=i.est$reg,gam=i.est$gam,xdat,ydat,id,tvec,margmodel,corstr,link) cat("\nest.rho: CL1 estimates\n") print(est.rho$e) ################################################################################ # obtain the fixed weight matrices ################################################################################ WtScMat<-weightMat(b=i.est$reg,gam=i.est$gam,rh=est.rho$e, xdat,ydat,id,tvec,margmodel,corstr) ################################################################################ # obtain the weighted scores estimates ################################################################################ # solve the nonlinear system of equations ws<-solvewtsc(start=c(i.est$reg,i.est$gam),WtScMat,xdat,ydat,id, tvec,margmodel,link) cat("ws=parameter estimates\n") print(ws$r) ################################################################################ # Ordinal regression ################################################################################ ################################################################################ # read and set up data set ################################################################################ data(arthritis) nn=nrow(arthritis) bas2<-bas3<-bas4<-bas5<-rep(0,nn) bas2[arthritis$b==2]<-1 bas3[arthritis$b==3]<-1 bas4[arthritis$b==4]<-1 bas5[arthritis$b==5]<-1 t2<-t3<-rep(0,nn) t2[arthritis$ti==3]<-1 t3[arthritis$ti==5]<-1 xdat=cbind(t2,t3,arthritis$trt,bas2,bas3,bas4,bas5,arthritis$age) ydat=arthritis$y id<-arthritis$id #time tvec<-arthritis$time ################################################################################ # select the link ################################################################################ link="probit" ################################################################################ # select the correlation structure ################################################################################ corstr="exch" ################################################################################ # perform CL1 estimation ################################################################################ i.est<-iee.ord(xdat,ydat,link) cat("\niest: IEE estimates\n") print(c(i.est$reg,i.est$gam)) est.rho<-cl1.ord(b=i.est$reg,gam=i.est$gam,xdat,ydat,id,tvec,corstr,link) cat("\nest.rho: CL1 estimates\n") print(est.rho$e) ################################################################################ # obtain the fixed weight matrices ################################################################################ WtScMat<-weightMat.ord(b=i.est$reg,gam=i.est$gam,rh=est.rho$e,xdat,ydat,id, tvec,corstr,link) ################################################################################ # obtain the weighted scores estimates ################################################################################ # solve the nonlinear system of equations ws<-solvewtsc.ord(start=c(i.est$reg,i.est$gam),WtScMat,xdat,ydat,id, tvec,link) cat("ws=parameter estimates\n") print(ws$r)
The data consist of up to seven binary observations on each of 294 subjects who had been randomly assigned to one of two treatment groups. The observations, taken at regularly scheduled time points, are coded as 1 if the subject's infection was severe and 0 otherwise. The interest is to investigate if the two treatments differ and if the percentage of severe infections decreased over time.
data(toenail)
data(toenail)
A data frame with 1568 observations on the following 4 variables.
idnum
The index for individuals.
treatn
The treatment binary covariate.
y
The subject's infection binary response.
time
The time indicator.
Molenberghs, G., Verbeke, G., 2005. Models for Discrete Longitudinal Data. Springer, NY.
Weight matrices for the estimating equations.
weightMat(b,gam,rh,xdat,ydat,id,tvec,margmodel,corstr,link) weightMat.ord(b,gam,rh,xdat,ydat,id,tvec,corstr,link)
weightMat(b,gam,rh,xdat,ydat,id,tvec,margmodel,corstr,link) weightMat.ord(b,gam,rh,xdat,ydat,id,tvec,corstr,link)
b |
The regression coefficients. |
gam |
The uinivariate parameters that are not regression coefficients. That is the parameter |
rh |
The vector of normal copula parameters. |
xdat |
|
ydat |
|
id |
An index for individuals or clusters. |
tvec |
A vector with the time indicator of individuals or clusters. |
margmodel |
Indicates the marginal model. Choices are “poisson” for Poisson, “bernoulli” for Bernoulli, and “nb1” , “nb2” for the NB1 and NB2 parametrization of negative binomial in Cameron and Trivedi (1998). |
corstr |
Indicates the latent correlation structure of normal copula. Choices are “exch”, “ar”, and “unstr” for exchangeable, ar(1) and unstrucutred correlation structure, respectively. |
link |
The link function. Choices are “log” for the log link function, “logit” for the logit link function, and “probit” for the probit link function. |
The fixed weight matrices based on a working
discretized MVN, of the weighted scores equations in Nikoloulopoulos et al. (2011)
where is based on
the covariance matrix of
computed from the
fitted discretized MVN model with estimated parameters
.
Note that weightMat.ord
is a variant of the code for ordinal (probit and logistic) regression.
A list containing the following components:
omega |
The array with the |
delta |
The array with the |
X |
The array with the |
Aristidis K. Nikoloulopoulos [email protected]
Harry Joe [email protected]
Nikoloulopoulos, A.K., Joe, H. and Chaganty, N.R. (2011) Weighted scores method for regression models with dependent data. Biostatistics, 12, 653–665. doi:10.1093/biostatistics/kxr005.
Nikoloulopoulos, A.K. (2016) Correlation structure and variable selection in generalized estimating equations via composite likelihood information criteria. Statistics in Medicine, 35, 2377–2390. doi:10.1002/sim.6871.
Nikoloulopoulos, A.K. (2017) Weighted scores method for longitudinal ordinal data. Arxiv e-prints, <arXiv:1510.07376>. https://arxiv.org/abs/1510.07376.
wtsc
,
solvewtsc
,
godambe
,
wtsc.wrapper
################################################################################ # binary regression ################################################################################ ################################################################################ # read and set up the data set ################################################################################ data(toenail) xdat<-cbind(1,toenail$treat,toenail$time,toenail$treat*toenail$time) # response ydat<-toenail$y #id id<-toenail$id #time tvec<-toenail$time ################################################################################ # select the marginal model ################################################################################ margmodel="bernoulli" link="probit" ################################################################################ # select the correlation structure ################################################################################ corstr="ar" ################################################################################ # perform CL1 estimation ################################################################################ i.est<-iee(xdat,ydat,margmodel,link) cat("\niest: IEE estimates\n") print(c(i.est$reg,i.est$gam)) # est.rho<-cl1(b=i.est$reg,gam=i.est$gam,xdat,ydat,id,tvec,margmodel,corstr,link) # cat("\nest.rho: CL1 estimates\n") # print(est.rho$e) # [1] 0.8941659 ################################################################################ # obtain the fixed weight matrices ################################################################################ WtScMat<-weightMat(b=i.est$reg,gam=i.est$gam,rh=0.8941659, xdat,ydat,id,tvec,margmodel,corstr,link) ################################################################################ # Ordinal regression ################################################################################ ################################################################################ # read and set up data set ################################################################################ data(arthritis) nn=nrow(arthritis) bas2<-bas3<-bas4<-bas5<-rep(0,nn) bas2[arthritis$b==2]<-1 bas3[arthritis$b==3]<-1 bas4[arthritis$b==4]<-1 bas5[arthritis$b==5]<-1 t2<-t3<-rep(0,nn) t2[arthritis$ti==3]<-1 t3[arthritis$ti==5]<-1 xdat=cbind(t2,t3,arthritis$trt,bas2,bas3,bas4,bas5,arthritis$age) ydat=arthritis$y id<-arthritis$id #time tvec<-arthritis$time ################################################################################ # select the link ################################################################################ link="probit" ################################################################################ # select the correlation structure ################################################################################ corstr="exch" ################################################################################ # perform CL1 estimation ################################################################################ i.est<-iee.ord(xdat,ydat,link) cat("\niest: IEE estimates\n") print(c(i.est$reg,i.est$gam)) est.rho<-cl1.ord(b=i.est$reg,gam=i.est$gam,xdat,ydat,id,tvec,corstr,link) WtScMat<-weightMat.ord(b=i.est$reg,gam=i.est$gam,rh=est.rho$e,xdat,ydat,id,tvec,corstr,link)
################################################################################ # binary regression ################################################################################ ################################################################################ # read and set up the data set ################################################################################ data(toenail) xdat<-cbind(1,toenail$treat,toenail$time,toenail$treat*toenail$time) # response ydat<-toenail$y #id id<-toenail$id #time tvec<-toenail$time ################################################################################ # select the marginal model ################################################################################ margmodel="bernoulli" link="probit" ################################################################################ # select the correlation structure ################################################################################ corstr="ar" ################################################################################ # perform CL1 estimation ################################################################################ i.est<-iee(xdat,ydat,margmodel,link) cat("\niest: IEE estimates\n") print(c(i.est$reg,i.est$gam)) # est.rho<-cl1(b=i.est$reg,gam=i.est$gam,xdat,ydat,id,tvec,margmodel,corstr,link) # cat("\nest.rho: CL1 estimates\n") # print(est.rho$e) # [1] 0.8941659 ################################################################################ # obtain the fixed weight matrices ################################################################################ WtScMat<-weightMat(b=i.est$reg,gam=i.est$gam,rh=0.8941659, xdat,ydat,id,tvec,margmodel,corstr,link) ################################################################################ # Ordinal regression ################################################################################ ################################################################################ # read and set up data set ################################################################################ data(arthritis) nn=nrow(arthritis) bas2<-bas3<-bas4<-bas5<-rep(0,nn) bas2[arthritis$b==2]<-1 bas3[arthritis$b==3]<-1 bas4[arthritis$b==4]<-1 bas5[arthritis$b==5]<-1 t2<-t3<-rep(0,nn) t2[arthritis$ti==3]<-1 t3[arthritis$ti==5]<-1 xdat=cbind(t2,t3,arthritis$trt,bas2,bas3,bas4,bas5,arthritis$age) ydat=arthritis$y id<-arthritis$id #time tvec<-arthritis$time ################################################################################ # select the link ################################################################################ link="probit" ################################################################################ # select the correlation structure ################################################################################ corstr="exch" ################################################################################ # perform CL1 estimation ################################################################################ i.est<-iee.ord(xdat,ydat,link) cat("\niest: IEE estimates\n") print(c(i.est$reg,i.est$gam)) est.rho<-cl1.ord(b=i.est$reg,gam=i.est$gam,xdat,ydat,id,tvec,corstr,link) WtScMat<-weightMat.ord(b=i.est$reg,gam=i.est$gam,rh=est.rho$e,xdat,ydat,id,tvec,corstr,link)
The weighted scores equations with inputs of the weight matrices and the data.
wtsc(param,WtScMat,xdat,ydat,id,tvec,margmodel,link) wtsc.ord(param,WtScMat,xdat,ydat,id,tvec,link)
wtsc(param,WtScMat,xdat,ydat,id,tvec,margmodel,link) wtsc.ord(param,WtScMat,xdat,ydat,id,tvec,link)
param |
The vector of regression and not regression parameters. |
WtScMat |
A list containing the following components.
omega: The array with the |
xdat |
|
ydat |
|
id |
An index for individuals or clusters. |
tvec |
A vector with the time indicator of individuals or clusters. |
margmodel |
Indicates the marginal model. Choices are “poisson” for Poisson, “bernoulli” for Bernoulli, and “nb1” , “nb2” for the NB1 and NB2 parametrization of negative binomial in Cameron and Trivedi (1998). |
link |
The link function. Choices are “log” for the log link function, “logit” for the logit link function, and “probit” for the probit link function. |
The weighted scores estimating equations, with
based on a working discretized MVN, have the form:
where is based on
the covariance matrix of
computed from the
fitted discretized MVN model with estimated parameters
.
Note that wtsc.ord
is a variant of the code for ordinal (probit and logistic) regression.
The weighted scores equations.
Nikoloulopoulos, A.K., Joe, H. and Chaganty, N.R. (2011) Weighted scores method for regression models with dependent data. Biostatistics, 12, 653–665. doi:10.1093/biostatistics/kxr005.
Nikoloulopoulos, A.K. (2016) Correlation structure and variable selection in generalized estimating equations via composite likelihood information criteria. Statistics in Medicine, 35, 2377–2390. doi:10.1002/sim.6871.
Nikoloulopoulos, A.K. (2017) Weighted scores method for longitudinal ordinal data. Arxiv e-prints, <arXiv:1510.07376>. https://arxiv.org/abs/1510.07376.
solvewtsc
,
weightMat
,
godambe
,
wtsc.wrapper
The weighted scores method with inputs of the data.
wtsc.wrapper(xdat,ydat,id,tvec,margmodel,corstr,link,iprint=FALSE) wtsc.ord.wrapper(xdat,ydat,id,tvec,corstr,link,iprint=FALSE)
wtsc.wrapper(xdat,ydat,id,tvec,margmodel,corstr,link,iprint=FALSE) wtsc.ord.wrapper(xdat,ydat,id,tvec,corstr,link,iprint=FALSE)
xdat |
|
ydat |
|
id |
An index for individuals or clusters. |
tvec |
A vector with the time indicator of individuals or clusters. |
margmodel |
Indicates the marginal model. Choices are “poisson” for Poisson, “bernoulli” for Bernoulli, and “nb1” , “nb2” for the NB1 and NB2 parametrization of negative binomial in Cameron and Trivedi (1998). |
corstr |
Indicates the latent correlation structure of normal copula. Choices are “exch”, “ar”, and “unstr” for exchangeable, ar(1) and unstructured correlation structure, respectively. |
link |
The link function. Choices are “log” for the log link function, “logit” for the logit link function, and “probit” for the probit link function. |
iprint |
Indicates printing of some intermediate results, default FALSE |
This wrapper functions handles all the steps to obtain the weighted scores estimates and standard errors.
A list containing the following components:
IEEest |
The estimates of the regression and not regression parameters ignoring dependence. |
CL1est |
The vector with the CL1 estimated dependence parameters (latent correlations). |
CL1lik |
The value of the sum of bivariate marginal log-likelihoods at CL1 estimates. |
WSest |
The weighted score estimates of the regression and not regression parameters. |
asympcov |
The estimated weighted scores asymptotic covariance matrix. |
Aristidis K. Nikoloulopoulos [email protected]
Harry Joe [email protected]
Nikoloulopoulos, A.K., Joe, H. and Chaganty, N.R. (2011) Weighted scores method for regression models with dependent data. Biostatistics, 12, 653–665. doi:10.1093/biostatistics/kxr005.
Nikoloulopoulos, A.K. (2016) Correlation structure and variable selection in generalized estimating equations via composite likelihood information criteria. Statistics in Medicine, 35, 2377–2390. doi:10.1002/sim.6871.
Nikoloulopoulos, A.K. (2017) Weighted scores method for longitudinal ordinal data. Arxiv e-prints, <arXiv:1510.07376>. https://arxiv.org/abs/1510.07376.
################################################################################ # read and set up the data set ################################################################################ data(childvisit) # covariates season1<-childvisit$q season1[season1>1]<-0 xdat<-cbind(1,childvisit$sex,childvisit$age,childvisit$m,season1) # response ydat<-childvisit$hosp #id id<-childvisit$id #time tvec<-childvisit$q ################################################################################ out<-wtsc.wrapper(xdat,ydat,id,tvec,margmodel="nb1",corstr="ar",iprint=TRUE) ################################################################################ # transform to binary responses # ################################################################################ y2<-ydat y2[ydat>0]<-1 ################################################################################ out<-wtsc.wrapper(xdat,y2,id,tvec,margmodel="bernoulli",link="probit", corstr="exch",iprint=TRUE) ################################################################################ # via the code for ordinal # ################################################################################ out<-wtsc.ord.wrapper(xdat[,-1],2-y2,id,tvec,link="probit", corstr="exch",iprint=TRUE)
################################################################################ # read and set up the data set ################################################################################ data(childvisit) # covariates season1<-childvisit$q season1[season1>1]<-0 xdat<-cbind(1,childvisit$sex,childvisit$age,childvisit$m,season1) # response ydat<-childvisit$hosp #id id<-childvisit$id #time tvec<-childvisit$q ################################################################################ out<-wtsc.wrapper(xdat,ydat,id,tvec,margmodel="nb1",corstr="ar",iprint=TRUE) ################################################################################ # transform to binary responses # ################################################################################ y2<-ydat y2[ydat>0]<-1 ################################################################################ out<-wtsc.wrapper(xdat,y2,id,tvec,margmodel="bernoulli",link="probit", corstr="exch",iprint=TRUE) ################################################################################ # via the code for ordinal # ################################################################################ out<-wtsc.ord.wrapper(xdat[,-1],2-y2,id,tvec,link="probit", corstr="exch",iprint=TRUE)