This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##e.g. data from kmi in LOS_toy_example.R | |
##non-infected only | |
#data <- data[-173,] | |
## (death) count at each event time | |
nDx <- table(data$exit) | |
## event times | |
times <- as.numeric(names(table(data$exit))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library("R2wd") | |
require(R2wd) | |
wdGet(T) # If no word file is open, it will start a new one - can set if to have the file visiable or not | |
wdNewDoc("H:\\This.doc") # this creates a new file with "this.doc" name | |
wdApplyTemplate("H:\\This.dot") # this applies a template |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
charlson2 <- function (Patient, icd) | |
{ | |
## | |
## | |
## | |
## foo <- charlson2(Patient=survData$Spell, icd=survData$Prim.Diag.Code) | |
d <- cbind.data.frame(Patient, icd) | |
nobs <- nrow(d) | |
d$code <- rep(NA, nobs) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################ | |
###GUM2011AllPositivity##### | |
############################ | |
summary(dat$totalPositivity2011GUM) | |
hist(dat$totalPositivity2011GUM) | |
modpos<-glm(totalPositivity2011GUM~ratioWhite2011+ratioBlack2011+ratioAsian2011+ | |
conception.rate.per.1000women.Under18+MarriedCivilCohabitCouples2011+SingleParents2011+ | |
ratioNoQual_2011+ratioMales25to34_2011+RatioFemales16to24_2011, | |
family=binomial,data=dat,weights=sum.NtestsGUM2011All) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##################################### | |
# | |
# Cox regression aggregated functions | |
# | |
# Nathan Green | |
# 11-2012 | |
# | |
##################################### | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tvCox <- function(survData, covariates, type){ | |
## | |
## time-dependent hazard array representation | |
## can specify which time to use: cause specific or subdistributions | |
## | |
## survData: survival data subset of total.data with indicators | |
## covariates: e.g. c("age", "agegr", "cath", "surgical", "gender") | |
## type: type of hazard functions to use | |
## "" - Cause-specific | |
## "death" - subdistribution time-to-death |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
subdistn <- function(survData){ | |
## substitute in later times to change risk sets | |
## time representation appropriate for subdistribution hazards | |
## | |
## Accounts for administrative censoring | |
## note that within a specific organism subset the maximum time | |
## may be from a patient infected by a different organism | |
## default entries |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
multinom_loglik <- function(props, size.melt, cov){ | |
## | |
## multinomial logistic regression likelihood | |
## over ALL groups in one batch | |
## | |
## props: array of covariate by group probabilities | |
## size.melt: e.g. agesize.melt | |
## cov: covariate name (string) e.g. "age" | |
ncol.size.melt <- ncol(size.melt) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
probs.logit <- function(grps.seq, cov, coeff, x){ | |
## | |
## multinomial logistic regression model fit for a given covariate | |
## e.g. probability sums per age =1 | |
## | |
## x: covariate value e.g. age=16 | |
## grps: vector of class labels for NATSAL groups e.g. het5yrs | |
## cov: covariate name to regress against (string) | |
## coeff: coefficients from the mlogit() fit | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
probs.logit_covs <- function(groups, cov, data){ | |
## | |
## given a (set of) covariate values, calculates the class membership probabilities | |
## | |
## groups: response field name of interest in NATSAL e.g. het1yr (string) | |
## cov: explanatory covariate name e.g. age_shift (string) | |
## data: e.g. NATSAL.dat (array) | |
## ordered sequence of covariate levels | |
## copy those covered in data but could include intermediate values too |
OlderNewer