Skip to content

Instantly share code, notes, and snippets.

@MJacobs1985
Created November 10, 2022 13:34
Show Gist options
  • Save MJacobs1985/e62e10d2d7ed3619285967e1976e471b to your computer and use it in GitHub Desktop.
Save MJacobs1985/e62e10d2d7ed3619285967e1976e471b to your computer and use it in GitHub Desktop.
## Linearity assumption
resMart<-residuals(fitSURV, type="martingale")
plot(pancreas2$NRS_WorstPain_at_consultation, resMart, main="Martingale residuals for Pain", ylab="Residuals", xlab="Ca4"); lines(loess.smooth(pancreas2$NRS_WorstPain_at_consultation, resMart), lwd=2, col="blue"); abline(h=0, col="red", lty=2, lwd=1.5)
plot(pancreas2$Age_at_consultation, resMart, main="Martingale residuals for Age", ylab="Residuals", xlab="Ca4"); lines(loess.smooth(pancreas2$Age_at_consultation, resMart), lwd=2, col="blue"); abline(h=0, col="red", lty=2, lwd=1.5)
## Influential observations
dfbetas<-residuals(fitSURV, type="dfbetas")
par(mfrow=c(4,3))
plot(dfbetas[,1], type='h', main="dfBETAS for GenderMale", ylab="DfBETAS", lwd=2);abline(h=c(2/sqrt(dim(dfbetas)[1]),-(2/sqrt(dim(dfbetas)[1]))),lty=2, col="red")
plot(dfbetas[,2], type='h', main="dfBETAS for NRS Worst Pain", ylab="DfBETAS", lwd=2);abline(h=c(2/sqrt(dim(dfbetas)[1]),-(2/sqrt(dim(dfbetas)[1]))),lty=2, col="red")
plot(dfbetas[,3], type='h', main="dfBETAS for Disease Stage", ylab="DfBETAS", lwd=2);abline(h=c(2/sqrt(dim(dfbetas)[1]),-(2/sqrt(dim(dfbetas)[1]))),lty=2, col="red")
plot(dfbetas[,1], type='h', main="dfBETAS for Age", ylab="DfBETAS", lwd=2);abline(h=c(2/sqrt(dim(dfbetas)[1]),-(2/sqrt(dim(dfbetas)[1]))),lty=2, col="red")
plot(dfbetas[,5], type='h', main="dfBETAS for Tumor Body", ylab="DfBETAS", lwd=2);abline(h=c(2/sqrt(dim(dfbetas)[1]),-(2/sqrt(dim(dfbetas)[1]))),lty=2, col="red")
plot(dfbetas[,6], type='h', main="dfBETAS for Tumor Tail", ylab="DfBETAS", lwd=2);abline(h=c(2/sqrt(dim(dfbetas)[1]),-(2/sqrt(dim(dfbetas)[1]))),lty=2, col="red")
plot(dfbetas[,7], type='h', main="dfBETAS for Non-Opioid NSAID", ylab="DfBETAS", lwd=2);abline(h=c(2/sqrt(dim(dfbetas)[1]),-(2/sqrt(dim(dfbetas)[1]))),lty=2, col="red")
plot(dfbetas[,8], type='h', main="dfBETAS for Non-Opioid Other", ylab="DfBETAS", lwd=2);abline(h=c(2/sqrt(dim(dfbetas)[1]),-(2/sqrt(dim(dfbetas)[1]))),lty=2, col="red")
plot(dfbetas[,9], type='h', main="dfBETAS for Opioid Oral", ylab="DfBETAS", lwd=2);abline(h=c(2/sqrt(dim(dfbetas)[1]),-(2/sqrt(dim(dfbetas)[1]))),lty=2, col="red")
plot(dfbetas[,10], type='h', main="dfBETAS for Opioid other", ylab="DfBETAS", lwd=2);abline(h=c(2/sqrt(dim(dfbetas)[1]),-(2/sqrt(dim(dfbetas)[1]))),lty=2, col="red")
plot(dfbetas[,11], type='h', main="dfBETAS for Surgery", ylab="DfBETAS", lwd=2);abline(h=c(2/sqrt(dim(dfbetas)[1]),-(2/sqrt(dim(dfbetas)[1]))),lty=2, col="red")
plot(dfbetas[,2], type='h', main="dfBETAS for Total Dose", ylab="DfBETAS", lwd=2);abline(h=c(2/sqrt(dim(dfbetas)[1]),-(2/sqrt(dim(dfbetas)[1]))),lty=2, col="red")
plot(dfbetas[,3], type='h', main="dfBETAS for Opioid_OME", ylab="DfBETAS", lwd=2);abline(h=c(2/sqrt(dim(dfbetas)[1]),-(2/sqrt(dim(dfbetas)[1]))),lty=2, col="red")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment