TABLE OF CONTENTS
estimation/updatedispmarg2 [ Functions ]
NAME
updatedispmarg2 --- Marginal estimators for the dispersion parameters
FUNCTION
Compute dispersion parameter estimates using a marginal method, based on the moments of the event indicators delta under the auxiliary Poisson model.
SYNOPSIS
1134 updatedispmarg2 <- function(m, Ji, datamat, datamatd, alphars, alpharsd, as, asd, 1135 betahat, betadhat, fixzero, univariate = FALSE)
INPUTS
m number of clusters Ji cluster sizes datamat data matrix generated by makedatamat for event 1 datamatd data matrix generated by makedatamat for event 2 alphars matrix of baseline hazard parameters for event 1 alpharsd matrix of baseline hazard parameters for event 2 as matrix of discretization breakpoints for event 1 asd matrix of discretization breakpoints for event 2 betahat regression coefficient estimates for event 1 betadhat regression coefficient estimates for event 2 fixzero list of estimators that should be fixed at zero (testing only) univariate boolean indicator whether a univariate model is being fit
OUTPUTS
sigma2hat cluster-level dispersion for process 1 sigma2dhat cluster-level dispersion for process 2 nu2hat subject-level dispersion for process 1 nu2dhat subject-level dispersion for process 2 thetahat subject-level covariance
SOURCE
1138 { 1139 # The function getdispmarg3 makes the FORTRAN calls that do most of the work 1140 # out1 contains only terms involving event 1 1141 # out2 only the event 2, and out3 contains the cross-terms 1142 out1 <- getdispmarg3(m, Ji, datamat, datamat, alphars, alphars, 1143 as, as, betahat, betahat, TRUE) 1144 out2 <- getdispmarg3(m, Ji, datamatd, datamatd, alpharsd, alpharsd, 1145 asd, asd, betadhat, betadhat, TRUE) 1146 out3 <- getdispmarg3(m, Ji, datamat, datamatd, alphars, alpharsd, 1147 as, asd, betahat, betadhat, FALSE) 1148 1149 # Extract the estimated dispersion parameters, and truncate from below 1150 sigma2hat <- max(out1$sig2, 1e-4) 1151 sigma2dhat <- max(out2$sig2, 1e-4) 1152 # Fix parameters at 0 if desired 1153 if(!is.null(fixzero)){ 1154 if("sigma2hat"%in%fixzero) sigma2hat <- 0 1155 if("sigma2dhat"%in%fixzero) sigma2dhat <- 0 1156 } 1157 nu2hat <- max(out1$sig2nu2 - sigma2hat, 1e-4) 1158 nu2dhat <- max(out2$sig2nu2 - sigma2dhat, 1e-4) 1159 thetahat <- out3$sig2nu2 1160 # Fix parameters at 0 if desired 1161 if(!is.null(fixzero)){ 1162 if("nu2hat"%in%fixzero) nu2hat <- 0 1163 if("nu2dhat"%in%fixzero) nu2dhat <- 0 1164 if("thetahat"%in%fixzero) thetahat <- 0 1165 } 1166 # The marginal estimators do not guarantee that the esimated covariance matrix 1167 # is valid. This code truncates the estimate of thetahat if needed 1168 if(!univariate) 1169 badtheta <- try(thetahat / sqrt(nu2hat * nu2dhat) > 1 | thetahat / 1170 sqrt(nu2hat * nu2dhat)< -1) 1171 else badtheta <- FALSE 1172 if(inherits(badtheta, "try - error") | is.na(badtheta)) {browser(); return(0)} 1173 if(badtheta) thetahat <- try(sign(thetahat) * sqrt(nu2hat * nu2dhat)) 1174 if(inherits(thetahat, "try - error")) return(0) 1175 1176 # Prepare for output 1177 return(list(sigma2hat = sigma2hat, 1178 sigma2dhat = sigma2dhat, 1179 nu2hat = nu2hat, 1180 nu2dhat = nu2dhat, 1181 thetahat = thetahat)) 1182 }