Description Usage Arguments Value Examples
View source: R/functionsAndStuff.R
Performs conditional logistic regression with a robust variance estimator
1 |
formula |
Similar to a formula for glm. |
id.set |
The ID variable for matched sets. |
data |
The dataset |
coef The coefficeints (i.e. betas) and their standard error
cov The covariance matrix of the coefficeints (useful for wald tests)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | ###A simple Example
n <- 10
Y <- rep(c(1,0,1,0),n)
ID <- rep(c(1:n),each=4)
X1 <- rnorm(4*n)
X2 <- rnorm(4*n)
data <- cbind(Y,X1,X2,ID)
clogitRV(Y~X1+X2,~ID,data)
##
##
##
##An example with a time-varying coefficient
##simData is an example dataset included in the package
?simData
###Run the Model (note: z is just a covariate)
simData$x1 <- simData$t * simData$x
simData$x2 <- simData$t^2 * simData$x
model <- clogitRV(Y~x+x1+x2+z,~ID, data=simData)
beta <- model$coef[-4,1]
cov <- model$cov[-4,-4]
##Draw the picture
library(ggplot2)
t2 <- seq(min(simData$t),max(simData$t),length.out=100)
t2M <- cbind(1,t2,t2^2)
beta2 <- t2M %*% beta
se2 <- sqrt(diag(t2M%*%cov%*%t(t2M)))
plotData <- as.data.frame(t2,beta2,se2)
ggplot(data=plotData,aes(t2,beta2)) +
geom_line() +
geom_point()+
geom_errorbar(aes(ymin=beta2-1.96*se2, ymax=beta2+1.96*se2))+
xlab("Time Until Diaganosis")+
ylab("log(RR)")
##Get the p-values
##P-value for overall effect of the biomarker
1-pchisq(t(beta)%*%solve(cov)%*%beta,length(beta))
##P-value for non-linear effect of the biomarker
1-pchisq(t(beta[-1])%*%solve(cov[-1,-1])%*%beta[-1],length(beta[-1]))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.