TABLE OF CONTENTS
ZZdebug/makemrs [ Functions ]
NAME
makemrs --- terms for profile likelihood
FUNCTION
Compute terms needed in the profile likelihood and gradient. This is an R implementation of the FORTRAN routine fmkmrs, used for debugging only.
SYNOPSIS
1479 makemrs <- function(m, Ji, datamat, as, betahat, Uijmat)
INPUTS
m number of clusters Ji cluster sizes datamat data matrix generated by makedatamat as matrix of discretization breakpoints betahat regression coefficient estimates Uijmat matrix of frailty estimates
OUTPUTS
mrs matrix of terms needed by the profile likelihood mrsgr array of terms needed by the profile gradient
SOURCE
1482 { 1483 # Initialize matrices 1484 mrs <- matrix(0, dim(as)[1], dim(as)[2] - 1) 1485 mrsgr <- array(0, c(dim(as)[1], dim(as)[2] - 1, length(betahat))) 1486 covs <- as.matrix(datamat[, -c(1:8)], dim(datamat)[1], length(betahat)) 1487 # Loop through the data matrix 1488 for(ind in 1:dim(datamat)[1]) 1489 { 1490 i <- datamat[ind, "i"] 1491 j <- datamat[ind, "j"] 1492 k <- datamat[ind, "k"] 1493 smax <- datamat[ind, "smax"] 1494 smin <- datamat[ind, "smin"] 1495 r <- datamat[ind, "r"] 1496 time <- datamat[ind, "time"] 1497 for(s in smin:smax){ 1498 # At each entry in the data matrix, add the term to the 1499 # appropriate component of the output matrices 1500 pred <- Uijmat[i, j] * exp(as.matrix(betahat)%*%covs[ind, ]) * 1501 A(time, as, r, s) 1502 mrs[r, s] <- mrs[r, s] + pred 1503 mrsgr[r, s, ] <- mrsgr[r, s, ] + covs[ind, ] * pred 1504 } 1505 } 1506 # Format for output 1507 return(list(mrs = mrs, mrsgr = mrsgr)) 1508 }