Title: | Automatic Linear and Logistic Regression and Survival Analysis |
---|---|
Description: | Make summary tables for descriptive statistics and select explanatory variables automatically in various regression models. Support linear models, generalized linear models and cox-proportional hazard models. Generate publication-ready tables summarizing result of regression analysis and plots. The tables and plots can be exported in "HTML", "pdf('LaTex')", "docx('MS Word')" and "pptx('MS Powerpoint')" documents. |
Authors: | Keon-Woong Moon [aut, cre] |
Maintainer: | Keon-Woong Moon <[email protected]> |
License: | GPL-3 |
Version: | 0.3.4 |
Built: | 2025-01-22 03:43:28 UTC |
Source: | https://github.com/cardiomoon/autoreg |
Add model summary to an object of class gaze
addFitSummary(df, fit, statsname = "")
addFitSummary(df, fit, statsname = "")
df |
An object of class "gaze" or "autoReg" |
fit |
An object of class "glm" or "lm" or "crr" |
statsname |
character Name of statistics |
addFitSummary returns an object of gaze
or autoReg
- the same class as df
require(survival) require(dplyr) data(cancer,package="survival") fit=coxph(Surv(time,status)~rx+age+sex+nodes+obstruct+perfor,data=colon) df=autoReg(fit,uni=FALSE) final=fit2final(fit) df %>% addFitSummary(final,statsname="HR (final)") %>% myft()
require(survival) require(dplyr) data(cancer,package="survival") fit=coxph(Surv(time,status)~rx+age+sex+nodes+obstruct+perfor,data=colon) df=autoReg(fit,uni=FALSE) final=fit2final(fit) df %>% addFitSummary(final,statsname="HR (final)") %>% myft()
Add labels to data
addLabelData(data)
addLabelData(data)
data |
A data.frame |
A data.frame
addLabelData(data.frame(ph.ecog=0:3,sex=c(1,2,2,2),age=c(20,30,40,70)))
addLabelData(data.frame(ph.ecog=0:3,sex=c(1,2,2,2),age=c(20,30,40,70)))
Draw an expected plot
adjustedPlot( fit, xnames = NULL, pred.values = list(), newdata = NULL, maxy.lev = 5, median = TRUE, facet = NULL, se = FALSE, mark.time = FALSE, show.median = FALSE, type = "ggplot", ... )
adjustedPlot( fit, xnames = NULL, pred.values = list(), newdata = NULL, maxy.lev = 5, median = TRUE, facet = NULL, se = FALSE, mark.time = FALSE, show.median = FALSE, type = "ggplot", ... )
fit |
An object of class "coxph" or "survreg" |
xnames |
Character Names of explanatory variable to plot |
pred.values |
A list A list of predictor values |
newdata |
A data.frame or NULL |
maxy.lev |
Integer Maximum unique length of a numeric variable to be treated as categorical variables |
median |
Logical |
facet |
Character Name of facet variable |
se |
logical Whether or not show se |
mark.time |
logical Whether or not mark time |
show.median |
logical |
type |
Character plot type |
... |
further arguments to be passed to plot.survfit |
A ggplot or no return value(called for side effects)
library(survival) fit=coxph(Surv(time,status)~rx+logWBC,data=anderson) adjustedPlot(fit) adjustedPlot(fit,xnames="rx",se=TRUE,type="plot") adjustedPlot(fit,xnames="rx",se=TRUE) ## Not run: anderson$WBCgroup=ifelse(anderson$logWBC<=2.73,0,1) anderson$WBCgroup=factor(anderson$WBCgroup,labels=c("low","high")) anderson$rx=factor(anderson$rx,labels=c("treatment","control")) fit=coxph(Surv(time,status)~rx,data=anderson) adjustedPlot(fit,xnames=c("rx"),show.median=TRUE) fit=coxph(Surv(time,status)~rx*WBCgroup,data=anderson) adjustedPlot(fit,xnames=c("rx","WBCgroup"),show.median=TRUE) adjustedPlot(fit,xnames=c("rx","WBCgroup"),facet="WBCgroup",show.median=TRUE) data(cancer,package="survival") fit=coxph(Surv(time,status)~rx+strata(sex)+age+differ,data =colon) adjustedPlot(fit,xnames=c("sex")) adjustedPlot(fit,xnames=c("sex"),pred.values=list(age=58,differ=3)) adjustedPlot(fit,xnames=c("sex","rx"),facet="sex") adjustedPlot(fit,xnames=c("rx","sex","differ"),facet=c("sex","rx"),se=TRUE) fit <- coxph(Surv(start, stop, event) ~ rx + number + size+ cluster(id), data = bladder2) adjustedPlot(fit,xnames=c("rx","number","size"),facet=c("rx","size"),maxy.lev=8) ## End(Not run)
library(survival) fit=coxph(Surv(time,status)~rx+logWBC,data=anderson) adjustedPlot(fit) adjustedPlot(fit,xnames="rx",se=TRUE,type="plot") adjustedPlot(fit,xnames="rx",se=TRUE) ## Not run: anderson$WBCgroup=ifelse(anderson$logWBC<=2.73,0,1) anderson$WBCgroup=factor(anderson$WBCgroup,labels=c("low","high")) anderson$rx=factor(anderson$rx,labels=c("treatment","control")) fit=coxph(Surv(time,status)~rx,data=anderson) adjustedPlot(fit,xnames=c("rx"),show.median=TRUE) fit=coxph(Surv(time,status)~rx*WBCgroup,data=anderson) adjustedPlot(fit,xnames=c("rx","WBCgroup"),show.median=TRUE) adjustedPlot(fit,xnames=c("rx","WBCgroup"),facet="WBCgroup",show.median=TRUE) data(cancer,package="survival") fit=coxph(Surv(time,status)~rx+strata(sex)+age+differ,data =colon) adjustedPlot(fit,xnames=c("sex")) adjustedPlot(fit,xnames=c("sex"),pred.values=list(age=58,differ=3)) adjustedPlot(fit,xnames=c("sex","rx"),facet="sex") adjustedPlot(fit,xnames=c("rx","sex","differ"),facet=c("sex","rx"),se=TRUE) fit <- coxph(Surv(start, stop, event) ~ rx + number + size+ cluster(id), data = bladder2) adjustedPlot(fit,xnames=c("rx","number","size"),facet=c("rx","size"),maxy.lev=8) ## End(Not run)
Draw predicted survival curve with an object survreg
adjustedPlot.survreg( x, xnames = NULL, pred.values = list(), maxy.lev = 5, median = TRUE, newdata = NULL, addCox = FALSE, legend.position = "topright", xlim = NULL, ylim = NULL )
adjustedPlot.survreg( x, xnames = NULL, pred.values = list(), maxy.lev = 5, median = TRUE, newdata = NULL, addCox = FALSE, legend.position = "topright", xlim = NULL, ylim = NULL )
x |
An object of class survreg |
xnames |
Character Names of explanatory variable to plot |
pred.values |
A list A list of predictor values |
maxy.lev |
Integer Maximum unique length of a numeric variable to be treated as categorical variables |
median |
Logical |
newdata |
A data.frame or NULL |
addCox |
logical Whether or not add KM |
legend.position |
Character Default value is "topright" |
xlim |
numeric |
ylim |
numeric |
No return value, called for side effects
library(survival) x=survreg(Surv(time, status) ~ rx, data=anderson,dist="exponential") adjustedPlot(x) adjustedPlot(x,addCox=TRUE) ## Not run: x=survreg(Surv(time, status) ~ sex, data=lung,dist="weibull") adjustedPlot(x,addCox=TRUE) x=survreg(Surv(time, status) ~ rx, data=anderson,dist="exponential") adjustedPlot(x) x=survreg(Surv(time, status) ~ ph.ecog + age + sex, data=lung, dist="weibull") adjustedPlot(x) adjustedPlot(x,addCox=TRUE) adjustedPlot(x,pred.values=list(age=c(20,40,60,80),sex=2,ph.ecog=3),addCox=TRUE) newdata=data.frame(ph.ecog=0:3,sex=c(1,2,2,2),age=c(20,40,60,80)) adjustedPlot(x,newdata=newdata,addCox=TRUE) ## End(Not run)
library(survival) x=survreg(Surv(time, status) ~ rx, data=anderson,dist="exponential") adjustedPlot(x) adjustedPlot(x,addCox=TRUE) ## Not run: x=survreg(Surv(time, status) ~ sex, data=lung,dist="weibull") adjustedPlot(x,addCox=TRUE) x=survreg(Surv(time, status) ~ rx, data=anderson,dist="exponential") adjustedPlot(x) x=survreg(Surv(time, status) ~ ph.ecog + age + sex, data=lung, dist="weibull") adjustedPlot(x) adjustedPlot(x,addCox=TRUE) adjustedPlot(x,pred.values=list(age=c(20,40,60,80),sex=2,ph.ecog=3),addCox=TRUE) newdata=data.frame(ph.ecog=0:3,sex=c(1,2,2,2),age=c(20,40,60,80)) adjustedPlot(x,newdata=newdata,addCox=TRUE) ## End(Not run)
Draw a survfitted plot
adjustedPlot2(fit, se = FALSE, mark.time = FALSE)
adjustedPlot2(fit, se = FALSE, mark.time = FALSE)
fit |
An object of class coxph or survfit |
se |
logical Whether or not show se |
mark.time |
logical Whether or not mark time |
a ggplot
library(survival) fit=coxph(Surv(time,status)~rx+logWBC,data=anderson) plot(survfit(fit),conf.int=TRUE) adjustedPlot2(fit,se=TRUE)
library(survival) fit=coxph(Surv(time,status)~rx+logWBC,data=anderson) plot(survfit(fit),conf.int=TRUE) adjustedPlot2(fit,se=TRUE)
Draw predicted survival curve as a ggplot with an object survreg
adjustedPlot2.survreg( x, xnames = NULL, pred.values = list(), maxy.lev = 5, newdata = NULL, addCox = FALSE, autovar = TRUE, legend.position = NULL, facet = NULL )
adjustedPlot2.survreg( x, xnames = NULL, pred.values = list(), maxy.lev = 5, newdata = NULL, addCox = FALSE, autovar = TRUE, legend.position = NULL, facet = NULL )
x |
An object of class survreg |
xnames |
Character Names of explanatory variable to plot |
pred.values |
A list A list of predictor values |
maxy.lev |
Integer Maximum unique length of a numeric variable to be treated as categorical variables |
newdata |
A data.frame or NULL |
addCox |
logical Whether or not add KM |
autovar |
logical |
legend.position |
Character Default value is "topright" |
facet |
Character name(s) of facet variable(s) |
A ggplot
library(survival) x=survreg(Surv(time, status) ~ rx, data=anderson,dist="exponential") adjustedPlot(x,type="plot") adjustedPlot(x) adjustedPlot(x,addCox=TRUE) ## Not run: x=survreg(Surv(time, status) ~ sex, data=lung,dist="weibull") adjustedPlot(x,addCox=TRUE) x=survreg(Surv(time, status) ~ rx, data=anderson,dist="exponential") adjustedPlot(x,addCox=TRUE) x=survreg(Surv(time, status) ~ ph.ecog + age + sex, data=lung, dist="weibull") pred.values=list(ph.ecog=0:3,sex=1:2,age=c(20,40,60,80)) adjustedPlot(x) adjustedPlot(x,addCox=TRUE) adjustedPlot(x,addCox=TRUE,xnames=c("ph.ecog","sex"),facet="sex") adjustedPlot(x,pred.values=pred.values,addCox=TRUE,legend.position="top")+xlim(c(1,1000)) adjustedPlot(x,pred.values=pred.values,xnames=c("ph.ecog","sex","age"),facet=c("ph.ecog","sex")) adjustedPlot(x,pred.values=pred.values,xnames=c("ph.ecog","sex","age"),facet=c("age","sex")) adjustedPlot(x,pred.values=pred.values,addCox=TRUE) adjustedPlot(x,addCox=TRUE) adjustedPlot(x,pred.values=list(age=c(20,40,60,80),sex=1,ph.ecog=3),addCox=TRUE) ## End(Not run)
library(survival) x=survreg(Surv(time, status) ~ rx, data=anderson,dist="exponential") adjustedPlot(x,type="plot") adjustedPlot(x) adjustedPlot(x,addCox=TRUE) ## Not run: x=survreg(Surv(time, status) ~ sex, data=lung,dist="weibull") adjustedPlot(x,addCox=TRUE) x=survreg(Surv(time, status) ~ rx, data=anderson,dist="exponential") adjustedPlot(x,addCox=TRUE) x=survreg(Surv(time, status) ~ ph.ecog + age + sex, data=lung, dist="weibull") pred.values=list(ph.ecog=0:3,sex=1:2,age=c(20,40,60,80)) adjustedPlot(x) adjustedPlot(x,addCox=TRUE) adjustedPlot(x,addCox=TRUE,xnames=c("ph.ecog","sex"),facet="sex") adjustedPlot(x,pred.values=pred.values,addCox=TRUE,legend.position="top")+xlim(c(1,1000)) adjustedPlot(x,pred.values=pred.values,xnames=c("ph.ecog","sex","age"),facet=c("ph.ecog","sex")) adjustedPlot(x,pred.values=pred.values,xnames=c("ph.ecog","sex","age"),facet=c("age","sex")) adjustedPlot(x,pred.values=pred.values,addCox=TRUE) adjustedPlot(x,addCox=TRUE) adjustedPlot(x,pred.values=list(age=c(20,40,60,80),sex=1,ph.ecog=3),addCox=TRUE) ## End(Not run)
A dataset containing survival time of 42 leukemia patients
anderson
anderson
A data.frame with 42 rows and 5 variables
survival time in weeks
censoring status 1=failure 0=censored
sex 0=Female 1=Male
log white blood cell count
treatment status 1=control 0 =treatment
David G. Kleinbaum and Mitchel Klein. Survival Analysis. A Self-Learning Text(3rd ed)(Springer,2012) ISBN: 978-1441966452
A dataset containing survival time of 42 leukemia patients This data is the same data with anderson, but sex and rx variable are factors not numeric
anderson1
anderson1
A data.frame with 42 rows and 5 variables
survival time in weeks
censoring status 1=failure 0=censored
sex "Female" or "Male
log white blood cell count
treatment status "treatment" or "control"
David G. Kleinbaum and Mitchel Klein. Survival Analysis. A Self-Learning Text(3rd ed)(Springer,2012) ISBN: 978-1441966452
This data is subdata of anderson with medium(2.3 < logWBC <= 2.96) and high WBC count(logWBC > 2.96)
anderson2
anderson2
A data.frame with 31 rows and 6 variables
survival time in weeks
censoring status 1=failure 0=censored
sex 0=Female 1=Male
log white blood cell count
treatment status 1=control 0 =treatment
WBC count group 1=medium 2=high
A dataset containing survival time of 31 leukemia patients
David G. Kleinbaum and Mitchel Klein. Survival Analysis. A Self-Learning Text(3rd ed)(Springer,2012) ISBN: 978-1441966452
Calculate character length and apply all data
as_printable( data, align.first = "left", align.chr = "right", align.num = "right" )
as_printable( data, align.first = "left", align.chr = "right", align.num = "right" )
data |
A data.frame |
align.first |
character Alignment of first variable |
align.chr |
character Alignment of character variable |
align.num |
character Alignment of numeric variable |
A data.frame
as_printable(mtcars) as_printable(iris)
as_printable(mtcars) as_printable(iris)
Perform univariable and multivariable regression and stepwise backward regression automatically
autoReg(x, ...) ## S3 method for class 'lm' autoReg(x, ...) ## S3 method for class 'glm' autoReg(x, ...) ## S3 method for class 'coxph' autoReg(x, ...) ## S3 method for class 'survreg' autoReg(x, ...)
autoReg(x, ...) ## S3 method for class 'lm' autoReg(x, ...) ## S3 method for class 'glm' autoReg(x, ...) ## S3 method for class 'coxph' autoReg(x, ...) ## S3 method for class 'survreg' autoReg(x, ...)
x |
An object of class lm, glm or coxph |
... |
Further arguments |
autoReg returns an object of class "autoReg" which inherits from the class "data.frame" with at least the following attributes:
character. name of dependent variable
name of model. One of "lm","glm" or "coxph"
autoReg(lm)
: S3 method for a class lm
autoReg(glm)
: S3 method for a class glm
autoReg(coxph)
: S3 method for a class coxph
autoReg(survreg)
: S3 method for a class survreg
data(cancer,package="survival") fit=glm(status~rx+sex+age+obstruct+nodes,data=colon,family="binomial") autoReg(fit) autoReg(fit,uni=FALSE,final=TRUE) autoReg(fit,uni=FALSE,imputed=TRUE) fit=lm(mpg~wt*hp+am+I(wt^2),data=mtcars) autoReg(fit,final=TRUE) autoReg(fit,imputed=TRUE)
data(cancer,package="survival") fit=glm(status~rx+sex+age+obstruct+nodes,data=colon,family="binomial") autoReg(fit) autoReg(fit,uni=FALSE,final=TRUE) autoReg(fit,uni=FALSE,imputed=TRUE) fit=lm(mpg~wt*hp+am+I(wt^2),data=mtcars) autoReg(fit,final=TRUE) autoReg(fit,imputed=TRUE)
Perform univariable and multivariable regression and stepwise backward regression automatically
autoReg_sub( fit, threshold = 0.2, uni = FALSE, multi = TRUE, final = FALSE, imputed = FALSE, keepstats = FALSE, showstats = TRUE, ... )
autoReg_sub( fit, threshold = 0.2, uni = FALSE, multi = TRUE, final = FALSE, imputed = FALSE, keepstats = FALSE, showstats = TRUE, ... )
fit |
An object of class lm or glm |
threshold |
numeric |
uni |
logical whether or not perform univariate regression |
multi |
logical whether or not perform multivariate regression |
final |
logical whether or not perform stepwise backward elimination |
imputed |
logical whether or not include imputed model |
keepstats |
logical whether or not keep statistics |
showstats |
logical whether or not show descriptive statistics |
... |
Further arguments to be passed to imputedReg() |
An object of class "autoReg" which inherits from the class "data.frame" with at least the following attributes:
character. name of dependent variable
name of model. One of "lm","glm" or "coxph"
perform automatic regression for a class of coxph
autoRegCox( x, threshold = 0.2, uni = FALSE, multi = TRUE, final = FALSE, imputed = FALSE, keepstats = FALSE, ... )
autoRegCox( x, threshold = 0.2, uni = FALSE, multi = TRUE, final = FALSE, imputed = FALSE, keepstats = FALSE, ... )
x |
An object of class coxph |
threshold |
numeric |
uni |
logical whether or not perform univariable regression |
multi |
logical whether or not perform multivariable regression |
final |
logical whether or not perform stepwise backward elimination |
imputed |
logical whether or not perform multiple imputation |
keepstats |
logical whether or not keep statistic |
... |
Further arguments to be passed to gaze() |
autoRegCox returns an object of class "autoReg" which inherits from the class "data.frame" with at least the following attributes:
character. name of dependent variable
name of model. One of "lm","glm" or "coxph"
require(survival) require(dplyr) data(cancer) fit=coxph(Surv(time,status==2)~log(bili)+age+cluster(edema),data=pbc) autoReg(fit) fit=coxph(Surv(time,status)~rx+age+sex+nodes+obstruct+perfor,data=colon) autoReg(fit) autoReg(fit,uni=TRUE,threshold=1) autoReg(fit,uni=TRUE,final=TRUE) %>% myft() data(colon_s,package="finalfit") fit=coxph(Surv(time,status)~age.factor+sex.factor+obstruct.factor+perfor.factor,data=colon_s) autoReg(fit,uni=TRUE,threshold=1) autoReg(fit,uni=TRUE,imputed=TRUE)
require(survival) require(dplyr) data(cancer) fit=coxph(Surv(time,status==2)~log(bili)+age+cluster(edema),data=pbc) autoReg(fit) fit=coxph(Surv(time,status)~rx+age+sex+nodes+obstruct+perfor,data=colon) autoReg(fit) autoReg(fit,uni=TRUE,threshold=1) autoReg(fit,uni=TRUE,final=TRUE) %>% myft() data(colon_s,package="finalfit") fit=coxph(Surv(time,status)~age.factor+sex.factor+obstruct.factor+perfor.factor,data=colon_s) autoReg(fit,uni=TRUE,threshold=1) autoReg(fit,uni=TRUE,imputed=TRUE)
perform automatic regression for a class of survreg
autoRegsurvreg( x, threshold = 0.2, uni = FALSE, multi = TRUE, final = FALSE, imputed = FALSE, keepstats = FALSE, mode = 1, ... )
autoRegsurvreg( x, threshold = 0.2, uni = FALSE, multi = TRUE, final = FALSE, imputed = FALSE, keepstats = FALSE, mode = 1, ... )
x |
An object of class survreg |
threshold |
numeric |
uni |
logical whether or not perform univariable regression |
multi |
logical whether or not perform multivariable regression |
final |
logical whether or not perform stepwise backward elimination |
imputed |
logical whether or not perform multiple imputation |
keepstats |
logical whether or not keep statistic |
mode |
integer |
... |
Further arguments to be passed to gaze() |
autoRegsurvreg returns an object of class "autoReg" which inherits from the class "data.frame" with at least the following attributes:
character. name of dependent variable
name of model. One of "lm","glm","coxph" or "survreg"
require(survival) require(dplyr) data(cancer) fit=survreg(Surv(time,status)~rx+age+sex+nodes+obstruct+perfor,data=colon) autoReg(fit) autoReg(fit,uni=TRUE,threshold=1) autoReg(fit,uni=TRUE,final=TRUE) autoReg(fit,uni=TRUE,final=TRUE) %>% myft() ## Not run: autoReg(fit,mode=2) autoReg(fit,uni=TRUE,threshold=1,,mode=2) autoReg(fit,uni=TRUE,final=TRUE,mode=2) autoReg(fit,uni=TRUE,final=TRUE,mode=2) %>% myft() autoReg(fit,final=TRUE,imputed=TRUE) %>% myft() autoReg(fit,final=TRUE,imputed=TRUE,mode=2) %>% myft() ## End(Not run)
require(survival) require(dplyr) data(cancer) fit=survreg(Surv(time,status)~rx+age+sex+nodes+obstruct+perfor,data=colon) autoReg(fit) autoReg(fit,uni=TRUE,threshold=1) autoReg(fit,uni=TRUE,final=TRUE) autoReg(fit,uni=TRUE,final=TRUE) %>% myft() ## Not run: autoReg(fit,mode=2) autoReg(fit,uni=TRUE,threshold=1,,mode=2) autoReg(fit,uni=TRUE,final=TRUE,mode=2) autoReg(fit,uni=TRUE,final=TRUE,mode=2) %>% myft() autoReg(fit,final=TRUE,imputed=TRUE) %>% myft() autoReg(fit,final=TRUE,imputed=TRUE,mode=2) %>% myft() ## End(Not run)
Whether a string vector can be converted to numeric
beNumeric(x)
beNumeric(x)
x |
A string vector |
A logical vector
Generate model predictions against a specified set of explanatory levels with bootstrapped confidence intervals.
bootPredict(fit, newdata, R = 100, type = "response", ...)
bootPredict(fit, newdata, R = 100, type = "response", ...)
fit |
An object of class lm or glm |
newdata |
A data.frame |
R |
Number of simulations. Note default R=100 is very low. |
type |
he type of prediction required, see predict.glm. The default for glm models is on the scale of the response variable. Thus for a binomial model the default predictions are predicted probabilities. |
... |
Further arguments to be passed to boot::boot |
An object of class "data.frame"
data(GBSG2,package="TH.data") fit=glm(cens~horTh+pnodes,data=GBSG2,family="binomial") newdata=expand.grid(horTh=factor(c(1,2),labels=c("no","yes")),pnodes=1:51) bootPredict(fit,newdata) library(survival) fit=coxph(Surv(time,cens)~age+horTh+progrec+pnodes,data=GBSG2)
data(GBSG2,package="TH.data") fit=glm(cens~horTh+pnodes,data=GBSG2,family="binomial") newdata=expand.grid(horTh=factor(c(1,2),labels=c("no","yes")),pnodes=1:51) bootPredict(fit,newdata) library(survival) fit=coxph(Surv(time,cens)~age+horTh+progrec+pnodes,data=GBSG2)
Count groups
countGroups(data, yvars)
countGroups(data, yvars)
data |
A data.frame |
yvars |
variable names |
An object of class "tibble"
library(moonBook) countGroups(acs,"sex") countGroups(acs,c("sex","Dx"))
library(moonBook) countGroups(acs,"sex") countGroups(acs,c("sex","Dx"))
Tis is a ggplot version of plot.cox.zph. Displays a graph of the scaled Schoenfeld residuals, along with a smooth curve.
coxzphplot(x, resid = TRUE, se = TRUE, var = NULL, hr = FALSE, add.lm = FALSE)
coxzphplot(x, resid = TRUE, se = TRUE, var = NULL, hr = FALSE, add.lm = FALSE)
x |
result of the cox.zph function. |
resid |
a logical value, if TRUE the residuals are included on the plot, as well as the smooth fit. |
se |
a logical value, if TRUE, confidence bands at two standard errors will be added. |
var |
The set of variables for which plots are desired. It can be integer or variable names |
hr |
logical If true, plot for hazard ratio, If false, plot for coefficients |
add.lm |
logical If true, add linear regression line |
A facetted ggplot
library(survival) vfit <- coxph(Surv(time,status) ~ trt + factor(celltype) + karno + age, data=veteran, x=TRUE) x <- cox.zph(vfit) coxzphplot(x) coxzphplot(x,var="karno",add.lm=TRUE)
library(survival) vfit <- coxph(Surv(time,status) ~ trt + factor(celltype) + karno + age, data=veteran, x=TRUE) x <- cox.zph(vfit) coxzphplot(x) coxzphplot(x,var="karno",add.lm=TRUE)
Extract statistics from an object of class crr
crr2stats(x, digits = 2)
crr2stats(x, digits = 2)
x |
an object of class crr |
digits |
integer indication the position of decimal place |
An object of class "data.frame"
data(melanoma,package="boot") melanoma$status_crr=ifelse(melanoma$status==1,1,ifelse(melanoma$status==2,0,2)) x=crrFormula(time+status_crr~age+sex+thickness+ulcer,data=melanoma) crr2stats(x)
data(melanoma,package="boot") melanoma$status_crr=ifelse(melanoma$status==1,1,ifelse(melanoma$status==2,0,2)) x=crrFormula(time+status_crr~age+sex+thickness+ulcer,data=melanoma) crr2stats(x)
Competing Risk Regression with Formula
crrFormula(x, data, ...)
crrFormula(x, data, ...)
x |
formula time+status~explanatory variables |
data |
data a data.frame |
... |
Further arguments to be passed to |
An object of class "tidycrr" which is described in crr
data(melanoma,package="boot") melanoma$status_crr=ifelse(melanoma$status==1,1,ifelse(melanoma$status==2,0,2)) crrFormula(time+status_crr~age+sex+thickness+ulcer,data=melanoma)
data(melanoma,package="boot") melanoma$status_crr=ifelse(melanoma$status==1,1,ifelse(melanoma$status==2,0,2)) crrFormula(time+status_crr~age+sex+thickness+ulcer,data=melanoma)
Make description for numeric summary
descNum(method = 1, p = NULL)
descNum(method = 1, p = NULL)
method |
numeric |
p |
A numeric or NULL |
A character vector of length 1
Convert data.frame to flextable
df2flextable( df, vanilla = FALSE, fontname = NULL, fontsize = 12, add.rownames = FALSE, even_header = "transparent", odd_header = "#5B7778", even_body = "#EFEFEF", odd_body = "transparent", vlines = TRUE, colorheader = FALSE, digits = 2, digitp = 3, align_header = "center", align_body = "right", align_rownames = "left", NA2space = TRUE, pcol = NULL, ... )
df2flextable( df, vanilla = FALSE, fontname = NULL, fontsize = 12, add.rownames = FALSE, even_header = "transparent", odd_header = "#5B7778", even_body = "#EFEFEF", odd_body = "transparent", vlines = TRUE, colorheader = FALSE, digits = 2, digitp = 3, align_header = "center", align_body = "right", align_rownames = "left", NA2space = TRUE, pcol = NULL, ... )
df |
A data.frame |
vanilla |
A Logical |
fontname |
Font name |
fontsize |
font size |
add.rownames |
logical. Whether or not include rownames |
even_header |
background color of even_header |
odd_header |
background color of even_header |
even_body |
background color of even_body |
odd_body |
background color of even_body |
vlines |
Logical. Whether or not draw vertical lines |
colorheader |
Logical. Whether or not use color in header |
digits |
integer indicating the number of decimal places |
digitp |
integer indicating the number of decimal places of p values |
align_header |
alignment of header. Expected value is one of 'left', 'right', 'center', 'justify'. |
align_body |
alignment of body. Expected value is one of 'left', 'right', 'center', 'justify'. |
align_rownames |
alignment of rownames. Expected value is one of 'left', 'right', 'center', 'justify'. |
NA2space |
A logical. If true, convert NA value to space |
pcol |
An integer indicating p value. If specified, convert value less than 0.01 to "< 0.001" in given column. |
... |
further arguments to be passed to |
An object of class "flextable" which is described in flextable
draw line character
drawline(n)
drawline(n)
n |
Numeric |
No return value, called for side effects
drawline(10)
drawline(10)
Select cutpoint for a numeric predictor with maxstat.test() and draw survival plot with this cutpoint
expectedPlot( fit, xname = NULL, no = 2, maxy.lev = 5, median = TRUE, mark.time = FALSE, se = FALSE, type = "ggplot", ... )
expectedPlot( fit, xname = NULL, no = 2, maxy.lev = 5, median = TRUE, mark.time = FALSE, se = FALSE, type = "ggplot", ... )
fit |
An object of class "coxph" |
xname |
Character Name of explanatory variable to plot |
no |
integer Number of groups to be made |
maxy.lev |
Integer Maximum unique length of a numeric variable to be treated as categorical variables |
median |
Logical |
mark.time |
logical Whether or not mark time |
se |
logical Whether or not show se |
type |
Character "plot" or "ggplot" |
... |
further arguments to be passed to plot.survfit |
No return value, called for side effects
library(survival) data(cancer,package="survival") fit=coxph(Surv(time,status)~age+sex,data =colon) expectedPlot(fit,xname="age") fit=coxph(Surv(time,status)~rx+logWBC,data=anderson) expectedPlot(fit,xname="logWBC",no=3)
library(survival) data(cancer,package="survival") fit=coxph(Surv(time,status)~age+sex,data =colon) expectedPlot(fit,xname="age") fit=coxph(Surv(time,status)~rx+logWBC,data=anderson) expectedPlot(fit,xname="logWBC",no=3)
filldown vector with lead value
filldown(x, what = c("", NA))
filldown(x, what = c("", NA))
x |
a vector |
what |
Values to be filled |
A vector with the same class as x
x=rep(1:5,each=3) x=removeDup(x,NA) filldown(x)
x=rep(1:5,each=3) x=removeDup(x,NA) filldown(x)
Find first duplicated position
find1stDup(x)
find1stDup(x)
x |
a vector |
A logical vector
x=rep(1:5,each=3) which(find1stDup(x))
x=rep(1:5,each=3) which(find1stDup(x))
Find duplicated term
findDup(x)
findDup(x)
x |
A vector |
A logical vector
x=rep(1:5,each=3) findDup(x) x=c(6,x) findDup(x) which(!findDup(x))
x=rep(1:5,each=3) findDup(x) x=c(6,x) findDup(x) which(!findDup(x))
Make final model using stepwise backward elimination
fit2final(fit, threshold = 0.2)
fit2final(fit, threshold = 0.2)
fit |
An object of class "coxph" |
threshold |
Numeric |
An object of class "coxph" which is described in coxph
require(survival) data(cancer) fit=coxph(Surv(time,status)~age+sex+obstruct+perfor,data=colon) final=fit2final(fit) fit2summary(final)
require(survival) data(cancer) fit=coxph(Surv(time,status)~age+sex+obstruct+perfor,data=colon) final=fit2final(fit) fit2summary(final)
extract likelihood information with a coxph object
fit2lik(x)
fit2lik(x)
x |
An object of class "coxph" or "survreg" |
A string
library(survival) fit=coxph(Surv(time,status) ~rx,data=anderson) fit2lik(fit)
library(survival) fit=coxph(Surv(time,status) ~rx,data=anderson) fit2lik(fit)
Make a list of univariable model with multivariable regression model
fit2list(fit)
fit2list(fit)
fit |
An object of class "lm" or "glm" |
An object of class "fitlist" which is a list of objects of class "lm" or "glm"
library(survival) data(cancer) fit=glm(status~rx+sex+age+obstruct+nodes,data=colon,family="binomial") fit2list(fit) fit=lm(mpg~wt*hp+am,data=mtcars) fit2list(fit)
library(survival) data(cancer) fit=glm(status~rx+sex+age+obstruct+nodes,data=colon,family="binomial") fit2list(fit) fit=lm(mpg~wt*hp+am,data=mtcars) fit2list(fit)
Restore fit model data containing AsIs expressions
fit2model(fit)
fit2model(fit)
fit |
An object of class "lm", "glm" or "coxph" |
An object of class "data.frame"
require(survival) pbc$status2=ifelse(pbc$status==2,1,0) fit=coxph(Surv(time,status2)~age+log(bili),data=pbc) fit2model(fit)
require(survival) pbc$status2=ifelse(pbc$status==2,1,0) fit=coxph(Surv(time,status2)~age+log(bili),data=pbc) fit2model(fit)
Make multivariable regression model by selecting univariable models with p.value below threshold
fit2multi(fit, threshold = 0.2)
fit2multi(fit, threshold = 0.2)
fit |
An object of class "coxph" |
threshold |
Numeric |
An object of class "coxph"
require(survival) data(cancer) fit=coxph(Surv(time,status)~age+sex+obstruct+perfor,data=colon) fit2multi(fit)
require(survival) data(cancer) fit=coxph(Surv(time,status)~age+sex+obstruct+perfor,data=colon) fit2multi(fit)
Make a new data of mean value or most frequent value
fit2newdata( fit, xnames = NULL, pred.values = list(), maxy.lev = 5, median = TRUE, digits = 1 )
fit2newdata( fit, xnames = NULL, pred.values = list(), maxy.lev = 5, median = TRUE, digits = 1 )
fit |
An object of class "coxph" |
xnames |
character Names of explanatory variable to plot |
pred.values |
A list A list of predictor values |
maxy.lev |
Integer Maximum unique length of a numeric variable to be treated as categorical variables |
median |
logical If TRUE, select median value for numerical variable. Otherwise select most frequent value |
digits |
integer indicating the number of decimal places |
A data.frame
require(survival) data(cancer,package="survival") fit=coxph(Surv(time,status)~rx+sex+age,data=colon) fit=coxph(Surv(time,status)~rx+age+strata(sex),data=colon) fit=survreg(Surv(time, status) ~ ph.ecog + age + sex, data=lung, dist="weibull") fit2newdata(fit) fit2newdata(fit,pred.values=list(sex=0,age=58)) fit2newdata(fit,pred.values=list(age=c(20,40,60,80),sex=2,ph.ecog=3))
require(survival) data(cancer,package="survival") fit=coxph(Surv(time,status)~rx+sex+age,data=colon) fit=coxph(Surv(time,status)~rx+age+strata(sex),data=colon) fit=survreg(Surv(time, status) ~ ph.ecog + age + sex, data=lung, dist="weibull") fit2newdata(fit) fit2newdata(fit,pred.values=list(sex=0,age=58)) fit2newdata(fit,pred.values=list(age=c(20,40,60,80),sex=2,ph.ecog=3))
Summarize statistics with a model
fit2stats(fit, method = "default", digits = 2, mode = 1)
fit2stats(fit, method = "default", digits = 2, mode = 1)
fit |
An object of class lm or glm or coxph or survreg |
method |
character choices are one of the c("likelihood","wald") |
digits |
integer indicating the number of decimal places |
mode |
integer |
An object of class "data.frame"
library(survival) data(cancer) fit=glm(status~rx+sex+age+obstruct+nodes,data=colon,family="binomial") fit2stats(fit) fit=lm(mpg~wt*hp+am,data=mtcars) fit2stats(fit) fit=survreg(Surv(time,status)~rx+sex+age+obstruct+nodes,data=colon) fit2stats(fit)
library(survival) data(cancer) fit=glm(status~rx+sex+age+obstruct+nodes,data=colon,family="binomial") fit2stats(fit) fit=lm(mpg~wt*hp+am,data=mtcars) fit2stats(fit) fit=survreg(Surv(time,status)~rx+sex+age+obstruct+nodes,data=colon) fit2stats(fit)
Summarize statistics with a model or model list
fit2summary(fit, mode = 1, ...)
fit2summary(fit, mode = 1, ...)
fit |
An object of class "lm" or "glm" or "fitlist" which is a result of |
mode |
integer |
... |
Further argument to be passed to fit2stats |
An object of class "data.frame"
library(survival) data(cancer) fit=glm(status~rx+sex+age+obstruct+nodes,data=colon,family="binomial") fit2summary(fit) fitlist=fit2list(fit) fit2summary(fitlist) fit=survreg(Surv(time,status)~rx+sex+age+obstruct+nodes,data=colon) fit2summary(fit)
library(survival) data(cancer) fit=glm(status~rx+sex+age+obstruct+nodes,data=colon,family="binomial") fit2summary(fit) fitlist=fit2list(fit) fit2summary(fitlist) fit=survreg(Surv(time,status)~rx+sex+age+obstruct+nodes,data=colon) fit2summary(fit)
Produce table for descriptive statistics by groups for several variables easily. Depending on the nature of these variables, different descriptive statistical methods were used(t-test, ANOVA, Kruskal-Wallis, chi-squared, Fisher's,...)
gaze(x, ...) ## S3 method for class 'formula' gaze(x, ...) ## S3 method for class 'data.frame' gaze(x, ...) ## S3 method for class 'coxph' gaze(x, ...) ## S3 method for class 'survreg' gaze(x, ...) ## S3 method for class 'glm' gaze(x, ...) ## S3 method for class 'lm' gaze(x, ...) ## S3 method for class 'tidycrr' gaze(x, ...)
gaze(x, ...) ## S3 method for class 'formula' gaze(x, ...) ## S3 method for class 'data.frame' gaze(x, ...) ## S3 method for class 'coxph' gaze(x, ...) ## S3 method for class 'survreg' gaze(x, ...) ## S3 method for class 'glm' gaze(x, ...) ## S3 method for class 'lm' gaze(x, ...) ## S3 method for class 'tidycrr' gaze(x, ...)
x |
An R object, formula or data.frame |
... |
arguments to be passed to gaze.data.frame or gaze.formula |
An object of class "gaze" which inherits from the class "data.frame" with at least the following attributes:
character. name of dependent variable
gaze(formula)
: S3 method for formula
gaze(data.frame)
: default S3 method
gaze(coxph)
: default S3 method
gaze(survreg)
: default S3 method
gaze(glm)
: default S3 method
gaze(lm)
: default S3 method
gaze(tidycrr)
: default S3 method
library(moonBook) library(dplyr) gaze(acs) gaze(~age+sex,data=acs) gaze(sex~.,data=acs,digits=1,method=1,show.p=TRUE) %>% myft() gaze(sex~age+Dx,data=acs) gaze(EF~.,data=acs) %>% myft() gaze(sex+Dx~.,data=acs,show.p=TRUE) %>% myft() gaze(sex+Dx~.,data=acs) gaze(Dx+sex~cardiogenicShock,data=acs,show.p=TRUE) %>% myft() gaze(Dx+sex+HBP~cardiogenicShock,data=acs,show.p=TRUE) gaze(~mpg+cyl,data=mtcars) gaze(~.,data=mtcars) gaze(cyl~.,data=mtcars,show.p=TRUE) gaze(hp~.,data=mtcars) gaze(cyl+am~.,data=mtcars) library(survival) x=coxph(Surv(time,status) ~rx,data=anderson1) gaze(x) x=coxph(Surv(time,status) ~rx*logWBC,data=anderson1) gaze(x) library(survival) x=survreg(Surv(time, status) ~ rx, data=anderson,dist="exponential") gaze(x) x=survreg(Surv(time, status) ~ ph.ecog + age + sex, lung) gaze(x) data(cancer,package="survival") fit=glm(status~rx+sex+age+obstruct+nodes,data=colon,family="binomial") gaze(fit) fit=lm(mpg~wt*hp+am+I(wt^2),data=mtcars) gaze(fit) data(melanoma,package="boot") melanoma$status_crr=ifelse(melanoma$status==1,1,ifelse(melanoma$status==2,0,2)) fit=crrFormula(time+status_crr~age+sex+thickness+ulcer,data=melanoma) gaze(fit)
library(moonBook) library(dplyr) gaze(acs) gaze(~age+sex,data=acs) gaze(sex~.,data=acs,digits=1,method=1,show.p=TRUE) %>% myft() gaze(sex~age+Dx,data=acs) gaze(EF~.,data=acs) %>% myft() gaze(sex+Dx~.,data=acs,show.p=TRUE) %>% myft() gaze(sex+Dx~.,data=acs) gaze(Dx+sex~cardiogenicShock,data=acs,show.p=TRUE) %>% myft() gaze(Dx+sex+HBP~cardiogenicShock,data=acs,show.p=TRUE) gaze(~mpg+cyl,data=mtcars) gaze(~.,data=mtcars) gaze(cyl~.,data=mtcars,show.p=TRUE) gaze(hp~.,data=mtcars) gaze(cyl+am~.,data=mtcars) library(survival) x=coxph(Surv(time,status) ~rx,data=anderson1) gaze(x) x=coxph(Surv(time,status) ~rx*logWBC,data=anderson1) gaze(x) library(survival) x=survreg(Surv(time, status) ~ rx, data=anderson,dist="exponential") gaze(x) x=survreg(Surv(time, status) ~ ph.ecog + age + sex, lung) gaze(x) data(cancer,package="survival") fit=glm(status~rx+sex+age+obstruct+nodes,data=colon,family="binomial") gaze(fit) fit=lm(mpg~wt*hp+am+I(wt^2),data=mtcars) gaze(fit) data(melanoma,package="boot") melanoma$status_crr=ifelse(melanoma$status==1,1,ifelse(melanoma$status==2,0,2)) fit=crrFormula(time+status_crr~age+sex+thickness+ulcer,data=melanoma) gaze(fit)
Summary function for categorical/continuous variable
gaze_sub(data, xname, y = NULL, max.ylev = 5, autoCat = FALSE, ...)
gaze_sub(data, xname, y = NULL, max.ylev = 5, autoCat = FALSE, ...)
data |
A data.frame |
xname |
A name of categorical/continuous vector |
y |
A name of vector, either continuous or categorical |
max.ylev |
max.ylev An integer indicating the maximum number of levels of grouping variable ('y'). If a column have unique values less than max.ylev it is treated as a categorical variable. Default value is 5. |
autoCat |
logical Whether or not use is.mynumeric() to determine whether a variable is numeric or not |
... |
Further arguments to be passed to gazeCont() or gazeCat() |
An object of class "data.frame" or "tibble"
require(moonBook) gaze_sub(acs,"age") gaze_sub(acs,"log(age)") gaze_sub(acs,"I(age^2)") gaze_sub(acs,"sex") gaze_sub(acs,"age","EF") gaze_sub(acs,"sex","EF") gaze_sub(acs,"age","Dx") gaze_sub(acs,"sex","Dx") gaze_sub(iris,"Species","Sepal.Length") gaze_sub(mtcars,"am") gaze_sub(mtcars,"am",autoCat=TRUE)
require(moonBook) gaze_sub(acs,"age") gaze_sub(acs,"log(age)") gaze_sub(acs,"I(age^2)") gaze_sub(acs,"sex") gaze_sub(acs,"age","EF") gaze_sub(acs,"sex","EF") gaze_sub(acs,"age","Dx") gaze_sub(acs,"sex","Dx") gaze_sub(iris,"Species","Sepal.Length") gaze_sub(mtcars,"am") gaze_sub(mtcars,"am",autoCat=TRUE)
Produce table for descriptive statistics by groups for several variables easily. Depending on the nature of these variables, different descriptive statistical methods were used(t-test, ANOVA, Kruskal-Wallis, chi-squared, Fisher's,...)
## S3 method for class 'formula_sub' gaze(x, data, missing = FALSE, ...)
## S3 method for class 'formula_sub' gaze(x, data, missing = FALSE, ...)
x |
An object of class "formula". Left side of ~ must contain the name of one grouping variable or two grouping variables in an additive way(e.g. sex+group~), and the right side of ~ must have variables in an additive way. |
data |
A data.frame |
missing |
logical If true, missing value analysis performed |
... |
Further arguments to be passed to gaze() |
An object of class "gaze" which inherits from the class "data.frame" with at least the following attributes:
character. name of dependent variable
Summary function for categorical variable
gazeCat( data, x, y = NULL, max.ylev = 5, digits = 1, show.total = FALSE, show.n = FALSE, show.missing = FALSE, show.stats = TRUE, origData = NULL, show.p = TRUE, method = 1, catMethod = 2, maxCatLevel = 20, ... )
gazeCat( data, x, y = NULL, max.ylev = 5, digits = 1, show.total = FALSE, show.n = FALSE, show.missing = FALSE, show.stats = TRUE, origData = NULL, show.p = TRUE, method = 1, catMethod = 2, maxCatLevel = 20, ... )
data |
A data frame |
x |
Name of a categorical variable |
y |
Name of a variable, either continuous or categorical |
max.ylev |
max.ylev An integer indicating the maximum number of levels of grouping variable ('y'). If a column have unique values less than max.ylev it is treated as a categorical variable. Default value is 5. |
digits |
Numeric |
show.total |
logical. Whether or not show total column |
show.n |
logical. Whether or not show N column |
show.missing |
logical. Whether or not show missing column |
show.stats |
logical. Whether or not show stats column |
origData |
A data.frame containing original data |
show.p |
logical. Whether or not show p column |
method |
method An integer indicating methods for continuous variables. Possible values in methods are 1 forces analysis as normal-distributed 2 forces analysis as continuous non-normal 3 performs a Shapiro-Wilk test or nortest::ad.test to decide between normal or non-normal Default value is 1. |
catMethod |
An integer indicating methods for categorical variables. Possible values in methods are
Default value is 2. |
maxCatLevel |
An integer indicating the maximum number of unique levels of categorical variable. If a column have unique values more than maxCatLevel, categorical summarization will not be performed. |
... |
Further arguments |
An object of class "data.frame" or "tibble"
require(moonBook) gazeCat(acs,"Dx") gazeCat(acs,"Dx","smoking") gazeCat(acs,"sex","Dx",show.p=TRUE) gazeCat(acs,"Dx","sex",show.p=TRUE) gazeCat(acs,"Dx","EF") gazeCat(acs,"sex","EF",method=2) gazeCat(mtcars,"cyl","hp")
require(moonBook) gazeCat(acs,"Dx") gazeCat(acs,"Dx","smoking") gazeCat(acs,"sex","Dx",show.p=TRUE) gazeCat(acs,"Dx","sex",show.p=TRUE) gazeCat(acs,"Dx","EF") gazeCat(acs,"sex","EF",method=2) gazeCat(mtcars,"cyl","hp")
Summary function for continuous variable
gazeCont( data, x, y = NULL, max.ylev = 5, digits = 1, show.total = FALSE, show.n = FALSE, show.missing = FALSE, show.stats = TRUE, show.p = TRUE, method = 1, origData, ... )
gazeCont( data, x, y = NULL, max.ylev = 5, digits = 1, show.total = FALSE, show.n = FALSE, show.missing = FALSE, show.stats = TRUE, show.p = TRUE, method = 1, origData, ... )
data |
A data.frame |
x |
A name of variable |
y |
A name of variable, either continuous or categorical |
max.ylev |
max.ylev An integer indicating the maximum number of levels of grouping variable ('y'). If a column have unique values less than max.ylev it is treated as a categorical variable. Default value is 5. |
digits |
integer indicating the number of decimal places |
show.total |
logical. Whether or not show total column |
show.n |
logical. Whether or not show N column |
show.missing |
logical. Whether or not show missing column |
show.stats |
logical. Whether or not show stats column |
show.p |
logical. Whether or not show p column |
method |
method An integer indicating methods for continuous variables. Possible values in methods are 1 forces analysis as normal-distributed 2 forces analysis as continuous non-normal 3 performs a Shapiro-Wilk test or nortest::ad.test to decide between normal or non-normal Default value is 1. |
origData |
A data.frame containing original data |
... |
Further arguments |
An object of class "data.frame" or "tibble"
gazeCont(mtcars,"hp") gazeCont(mtcars,"hp","mpg") require(moonBook) gazeCont(acs,"log(age)") gazeCont(acs,"age",method=2) gazeCont(acs,"age","EF",method=2) gazeCont(acs,"age","Dx",method=1) gazeCont(acs,"age","Dx",show.p=TRUE,method=3)
gazeCont(mtcars,"hp") gazeCont(mtcars,"hp","mpg") require(moonBook) gazeCont(acs,"log(age)") gazeCont(acs,"age",method=2) gazeCont(acs,"age","EF",method=2) gazeCont(acs,"age","Dx",method=1) gazeCont(acs,"age","Dx",show.p=TRUE,method=3)
Get interaction data from data
getInteraction(name, data)
getInteraction(name, data)
name |
a string with interaction term |
data |
a data.frame |
An object of class "data.frame"
data(acs,package="moonBook") getInteraction("TC:Dx:sex",data=acs)
data(acs,package="moonBook") getInteraction("TC:Dx:sex",data=acs)
Get number of data specified by 'name' and 'desc'
getN(name, desc, data)
getN(name, desc, data)
name |
a string with interaction term |
desc |
character |
data |
a data.frame |
A numeric vector
data(acs,package="moonBook") df=getInteraction("TC:Dx:sex",data=acs) getN(name=df$name,desc=df$desc,data=acs)
data(acs,package="moonBook") df=getInteraction("TC:Dx:sex",data=acs) getN(name=df$name,desc=df$desc,data=acs)
Get explanatory variables of a model with significance level below the threshold
getSigVars(fit, threshold = 0.2, final = TRUE)
getSigVars(fit, threshold = 0.2, final = TRUE)
fit |
An object of class lm or glm |
threshold |
Numeric |
final |
logical if true, perform stepwise regression using step() |
A list containing the following components:
names of explanatory variables which have significant levels below the threshold in univariable model
names of explanatory variables included in final model as a result of step
library(survival) data(cancer,package="survival") fit=glm(status~rx+sex+age+obstruct+nodes,data=colon,family="binomial") getSigVars(fit) fit=lm(mpg~hp*wt+am,data=mtcars) getSigVars(fit)
library(survival) data(cancer,package="survival") fit=glm(status~rx+sex+age+obstruct+nodes,data=colon,family="binomial") getSigVars(fit) fit=lm(mpg~hp*wt+am,data=mtcars) getSigVars(fit)
Draw Cumulative Incidence Curves for Competing Risks
ggcmprsk(x, data, id = NULL, se = FALSE, strata = NULL, facet = NULL, ...)
ggcmprsk(x, data, id = NULL, se = FALSE, strata = NULL, facet = NULL, ...)
x |
A formula as time+status~1 |
data |
A data.frame |
id |
character vector label for status |
se |
logical whether or not show confidence interval |
strata |
character vector label for strata |
facet |
numeric if facet is not NULL, draw plot with selected facets |
... |
Further arguments to be passed to tidycmprsk::cuminc |
An object of class "ggplot"
data(melanoma,package="boot") melanoma$status1 = ifelse(melanoma$status==1,1,ifelse(melanoma$status==2,0,2)) melanoma$years=melanoma$time/365 ggcmprsk(years+status1~1,data=melanoma) ggcmprsk(years+status1~1,data=melanoma,id=c("alive","melanoma","other"),se=TRUE) ggcmprsk(years+status1~sex,data=melanoma) ggcmprsk(years+status1~sex,data=melanoma,facet=1) ggcmprsk(years+status1~sex,data=melanoma, id=c("alive","melanoma","other"),strata=c("female","male")) ggcmprsk(years+status1~sex,data=melanoma, id=c("alive","melanoma","other"),strata=c("female","male"),facet=1)
data(melanoma,package="boot") melanoma$status1 = ifelse(melanoma$status==1,1,ifelse(melanoma$status==2,0,2)) melanoma$years=melanoma$time/365 ggcmprsk(years+status1~1,data=melanoma) ggcmprsk(years+status1~1,data=melanoma,id=c("alive","melanoma","other"),se=TRUE) ggcmprsk(years+status1~sex,data=melanoma) ggcmprsk(years+status1~sex,data=melanoma,facet=1) ggcmprsk(years+status1~sex,data=melanoma, id=c("alive","melanoma","other"),strata=c("female","male")) ggcmprsk(years+status1~sex,data=melanoma, id=c("alive","melanoma","other"),strata=c("female","male"),facet=1)
Compare cumulative incidence to th Kaplan-Meier estimate
ggcmprsk2( x, data, id = c("disease", "other"), se = FALSE, xpos = c(2, 2), ypos = c(0.25, 0.7), ylabs = NULL, xlab = NULL, label = NULL, plot = TRUE )
ggcmprsk2( x, data, id = c("disease", "other"), se = FALSE, xpos = c(2, 2), ypos = c(0.25, 0.7), ylabs = NULL, xlab = NULL, label = NULL, plot = TRUE )
x |
A formula as time+status~1 |
data |
A data.frame |
id |
Character vector of length2 |
se |
logical whether or not show confidence interval |
xpos |
numeric x-axis position of label |
ypos |
numeric y-axis position of label |
ylabs |
string vector of length 2. y axis labels |
xlab |
A character. The x-axis label |
label |
string vector of length 2. Label names |
plot |
logical Whether or not print plot |
A list containing the following components:
A long-form data.frame consist of time, est, upper,lower, id, method
A data.frame for label consist of x, y, label, id
A ggplot object
require(dplyr) data(prostateSurvival,package="asaur") prostateHighRisk <- prostateSurvival %>% filter(grade=="poor" & stage=="T2",ageGroup=="80+") prostateHighRisk$years=prostateHighRisk$survTime/12 ggcmprsk2(years+status~1,data=prostateHighRisk, id=c("prostate cancer","other causes"))
require(dplyr) data(prostateSurvival,package="asaur") prostateHighRisk <- prostateSurvival %>% filter(grade=="poor" & stage=="T2",ageGroup=="80+") prostateHighRisk$years=prostateHighRisk$survTime/12 ggcmprsk2(years+status~1,data=prostateHighRisk, id=c("prostate cancer","other causes"))
Highlight a data.frame
highlight2(x, i = NULL, j = NULL, style = NULL, include.colname = FALSE)
highlight2(x, i = NULL, j = NULL, style = NULL, include.colname = FALSE)
x |
A data.frame |
i |
numeric rows to highlight |
j |
numeric columns to hightlight |
style |
A style function or NULL |
include.colname |
logical Whether or not include colname |
a data.frame
head(mtcars) %>% highlight2(i=3) %>% printdf() library(crayon) head(mtcars) %>% highlight2(i=2) %>% highlight2(j=3,style=blue$bold) %>% printdf() fit=lm(mpg~wt*hp,data=mtcars) gaze(fit) gaze(fit) %>% highlight2(j=4,include.colname=TRUE) gaze(fit) %>% highlight2(i=2,j=4) %>% highlight2(i=2,j=2:3,style=blue$bold) gaze(fit) %>% highlight2(i=2) %>% highlight2(j=3,style=blue$bold)
head(mtcars) %>% highlight2(i=3) %>% printdf() library(crayon) head(mtcars) %>% highlight2(i=2) %>% highlight2(j=3,style=blue$bold) %>% printdf() fit=lm(mpg~wt*hp,data=mtcars) gaze(fit) gaze(fit) %>% highlight2(j=4,include.colname=TRUE) gaze(fit) %>% highlight2(i=2,j=4) %>% highlight2(i=2,j=2:3,style=blue$bold) gaze(fit) %>% highlight2(i=2) %>% highlight2(j=3,style=blue$bold)
Make a multiple imputed model
imputedReg(fit, data = NULL, m = 20, seed = 1234, digits = 2, mode = 1, ...)
imputedReg(fit, data = NULL, m = 20, seed = 1234, digits = 2, mode = 1, ...)
fit |
An object of class lm, glm, coxph or survreg |
data |
a data.frame |
m |
Number of multiple imputations. The default is m=20. |
seed |
An integer that is used as argument by the set.seed() for offsetting the random number generator. |
digits |
Integer indicating the number of decimal place |
mode |
integer indicating summary mode of class survreg |
... |
Further argument to be passed to mice |
An object of class "imputedReg" which inherits from the class "data.frame"
data(cancer,package="survival") fit=glm(status~rx+sex+age+obstruct+nodes,data=colon,family="binomial") imputedReg(fit) library(survival) fit=coxph(Surv(time,status)~rx+age+sex+nodes+obstruct+perfor,data=colon) imputedReg(fit) fit=survreg(Surv(time,status)~rx+age+sex+nodes+obstruct+perfor,data=colon) imputedReg(fit) imputedReg(fit,mode=2)
data(cancer,package="survival") fit=glm(status~rx+sex+age+obstruct+nodes,data=colon,family="binomial") imputedReg(fit) library(survival) fit=coxph(Surv(time,status)~rx+age+sex+nodes+obstruct+perfor,data=colon) imputedReg(fit) fit=survreg(Surv(time,status)~rx+age+sex+nodes+obstruct+perfor,data=colon) imputedReg(fit) imputedReg(fit,mode=2)
Decide whether a vector can be treated as a numeric variable
is.mynumeric(x, maxy.lev = 5)
is.mynumeric(x, maxy.lev = 5)
x |
A vector |
maxy.lev |
An integer indicating the maximum number of unique values of a numeric variable be treated as a categorical variable |
A logical value
x=1:5 is.mynumeric(x) x=1:13 is.mynumeric(x)
x=1:5 is.mynumeric(x) x=1:13 is.mynumeric(x)
takes the breaks as input and returns labels as output
label_parse(breaks)
label_parse(breaks)
breaks |
character |
a character vector
Draw log-log plot
loglogplot( fit, xnames = NULL, main = NULL, labels = NULL, no = 3, add.loess = FALSE, add.lm = TRUE, type = "l", se = TRUE, what = "surv", legend.position = NULL, ... )
loglogplot( fit, xnames = NULL, main = NULL, labels = NULL, no = 3, add.loess = FALSE, add.lm = TRUE, type = "l", se = TRUE, what = "surv", legend.position = NULL, ... )
fit |
An object of class "coxph" or "survfit" |
xnames |
character Names of explanatory variable to plot |
main |
String Title of plot |
labels |
String vector Used as legend in legend |
no |
Numeric The number of groups to be converted |
add.loess |
logical If true, add loess regression line |
add.lm |
logical If true, add linear regression line |
type |
character "l" or "p" |
se |
logical If true, add se |
what |
character One of c("surv","survOdds","failureOdds") |
legend.position |
legend position. One of c("left","top","bottom","right") or numeric vector of length 2. |
... |
Furhter arguments to be passed to plot() |
A ggplot or no return value, called for side effects
require(survival) data(cancer,package="survival") fit=coxph(Surv(time,status)~x,data=leukemia) loglogplot(fit) fit=survfit(Surv(time,status)~1,data=anderson) loglogplot(fit) fit=survfit(Surv(time,status)~sex,data=anderson) loglogplot(fit) fit=survfit(Surv(time,status)~logWBC,data=anderson) loglogplot(fit) loglogplot(fit,no=2) fit=survfit(Surv(time,status)~logWBC+rx,data=anderson) loglogplot(fit,no=2) fit=survfit(Surv(time,status)~rx,data=anderson) loglogplot(fit,type="p") fit=survfit(Surv(time,status)~WBCCAT,data=anderson2) loglogplot(fit,type="p",what="survOdds") loglogplot(fit,type="p",what="failureOdds")
require(survival) data(cancer,package="survival") fit=coxph(Surv(time,status)~x,data=leukemia) loglogplot(fit) fit=survfit(Surv(time,status)~1,data=anderson) loglogplot(fit) fit=survfit(Surv(time,status)~sex,data=anderson) loglogplot(fit) fit=survfit(Surv(time,status)~logWBC,data=anderson) loglogplot(fit) loglogplot(fit,no=2) fit=survfit(Surv(time,status)~logWBC+rx,data=anderson) loglogplot(fit,no=2) fit=survfit(Surv(time,status)~rx,data=anderson) loglogplot(fit,type="p") fit=survfit(Surv(time,status)~WBCCAT,data=anderson2) loglogplot(fit,type="p",what="survOdds") loglogplot(fit,type="p",what="failureOdds")
Return maximum character number except NA
maxnchar(x)
maxnchar(x)
x |
a vector |
A numeric vector of length 1
x=c(1,2,"sadf",NA) maxnchar(x) data(acs,package="moonBook") lapply(acs,maxnchar)
x=c(1,2,"sadf",NA) maxnchar(x) data(acs,package="moonBook") lapply(acs,maxnchar)
Draw coefficients/odds ratio/hazard ratio plot
modelPlot( fit, widths = NULL, change.pointsize = TRUE, show.OR = TRUE, show.ref = TRUE, bw = TRUE, legend.position = "top", ... )
modelPlot( fit, widths = NULL, change.pointsize = TRUE, show.OR = TRUE, show.ref = TRUE, bw = TRUE, legend.position = "top", ... )
fit |
An object of class glm |
widths |
Numeric vector |
change.pointsize |
logical Whether or not change point size |
show.OR |
logical Whether or not show odds ratio |
show.ref |
logical Whether or not show reference |
bw |
logical If true, use grey scale |
legend.position |
legend position default value is 'top' |
... |
Further arguments to be passed to autoReg() |
modelPlot returns an object of class "modelPlot" An object of class modelPlot is a list containing at least of the following components:
The first table containing names
The 2nd table containing levels
The 3rd table containing coefficients or odds ratio or hazards ratio
A ggplot
the widths of the tables and the ggplot
fit=lm(mpg~wt*hp+am,data=mtcars) modelPlot(fit,widths=c(1,0,2,3)) modelPlot(fit,uni=TRUE,threshold=1,widths=c(1,0,2,3)) fit=lm(Sepal.Width~Sepal.Length*Species,data=iris) modelPlot(fit) modelPlot(fit,uni=TRUE,change.pointsize=FALSE) data(cancer,package="survival") fit=glm(status~rx+age+sex+nodes+obstruct+perfor,data=colon,family="binomial") modelPlot(fit) modelPlot(fit,uni=TRUE,multi=TRUE,threshold=1) modelPlot(fit,multi=TRUE,imputed=TRUE,change.pointsize=FALSE) data(colon_s,package="finalfit") fit=glm(mort_5yr~age.factor+sex.factor+obstruct.factor+perfor.factor,data=colon_s,family="binomial") modelPlot(fit) modelPlot(fit,uni=TRUE,multi=TRUE,threshold=1) modelPlot(fit,uni=TRUE,multi=TRUE) modelPlot(fit,uni=TRUE,multi=TRUE,threshold=1,show.ref=FALSE) library(survival) fit=coxph(Surv(time,status)~rx+age+sex+obstruct+perfor,data=colon) modelPlot(fit) modelPlot(fit,uni=TRUE,threshold=1) modelPlot(fit,multi=FALSE,final=TRUE,threshold=1) fit=coxph(Surv(time,status)~age.factor+sex.factor+obstruct.factor+perfor.factor,data=colon_s) modelPlot(fit) modelPlot(fit,uni=TRUE,threshold=1) modelPlot(fit,uni=TRUE,threshold=1,show.ref=FALSE) modelPlot(fit,imputed=TRUE)
fit=lm(mpg~wt*hp+am,data=mtcars) modelPlot(fit,widths=c(1,0,2,3)) modelPlot(fit,uni=TRUE,threshold=1,widths=c(1,0,2,3)) fit=lm(Sepal.Width~Sepal.Length*Species,data=iris) modelPlot(fit) modelPlot(fit,uni=TRUE,change.pointsize=FALSE) data(cancer,package="survival") fit=glm(status~rx+age+sex+nodes+obstruct+perfor,data=colon,family="binomial") modelPlot(fit) modelPlot(fit,uni=TRUE,multi=TRUE,threshold=1) modelPlot(fit,multi=TRUE,imputed=TRUE,change.pointsize=FALSE) data(colon_s,package="finalfit") fit=glm(mort_5yr~age.factor+sex.factor+obstruct.factor+perfor.factor,data=colon_s,family="binomial") modelPlot(fit) modelPlot(fit,uni=TRUE,multi=TRUE,threshold=1) modelPlot(fit,uni=TRUE,multi=TRUE) modelPlot(fit,uni=TRUE,multi=TRUE,threshold=1,show.ref=FALSE) library(survival) fit=coxph(Surv(time,status)~rx+age+sex+obstruct+perfor,data=colon) modelPlot(fit) modelPlot(fit,uni=TRUE,threshold=1) modelPlot(fit,multi=FALSE,final=TRUE,threshold=1) fit=coxph(Surv(time,status)~age.factor+sex.factor+obstruct.factor+perfor.factor,data=colon_s) modelPlot(fit) modelPlot(fit,uni=TRUE,threshold=1) modelPlot(fit,uni=TRUE,threshold=1,show.ref=FALSE) modelPlot(fit,imputed=TRUE)
Makes table summarizing list of models
modelsSummary(fitlist, show.lik = FALSE)
modelsSummary(fitlist, show.lik = FALSE)
fitlist |
A list of objects of class "coxph" |
show.lik |
logical Whether or not show likelihood test results |
No return value, called for side effects
library(survival) fit1=coxph(Surv(time,status) ~rx,data=anderson) fit2=coxph(Surv(time,status) ~rx+logWBC,data=anderson) fit3=coxph(Surv(time,status) ~rx*logWBC,data=anderson) fitlist=list(fit1,fit2,fit3) modelsSummary(fitlist)
library(survival) fit1=coxph(Surv(time,status) ~rx,data=anderson) fit2=coxph(Surv(time,status) ~rx+logWBC,data=anderson) fit3=coxph(Surv(time,status) ~rx*logWBC,data=anderson) fitlist=list(fit1,fit2,fit3) modelsSummary(fitlist)
Makes flextable summarizing list of models
modelsSummaryTable(fitlist, labels = NULL, show.lik = FALSE)
modelsSummaryTable(fitlist, labels = NULL, show.lik = FALSE)
fitlist |
A list of objects of class "coxph" |
labels |
character labels of models |
show.lik |
logical Whether or not show likelihood test results |
A flextable
library(survival) fit1=coxph(Surv(time,status) ~rx,data=anderson) fit2=coxph(Surv(time,status) ~rx+logWBC,data=anderson) fit3=coxph(Surv(time,status) ~rx*logWBC,data=anderson) fitlist=list(fit1,fit2,fit3) modelsSummaryTable(fitlist)
library(survival) fit1=coxph(Surv(time,status) ~rx,data=anderson) fit2=coxph(Surv(time,status) ~rx+logWBC,data=anderson) fit3=coxph(Surv(time,status) ~rx*logWBC,data=anderson) fitlist=list(fit1,fit2,fit3) modelsSummaryTable(fitlist)
Statistical test for categorical variables Statistical test for categorical variables
my.chisq.test2(x, y, catMethod = 2, all = FALSE)
my.chisq.test2(x, y, catMethod = 2, all = FALSE)
x |
a vector |
y |
a vector |
catMethod |
An integer indicating methods for categorical variables. Possible values in methods are
Default value is 2. |
all |
A logical |
A numeric vector of length 1
library(moonBook) x=acs$sex y=acs$Dx my.chisq.test2(x,y)
library(moonBook) x=acs$sex y=acs$Dx my.chisq.test2(x,y)
Statistical test for continuous variables
my.t.test2(y, x, method = 1, all = FALSE)
my.t.test2(y, x, method = 1, all = FALSE)
y |
a categorical vector |
x |
a numeric vector |
method |
method An integer indicating methods for continuous variables. Possible values in methods are 1 forces analysis as normal-distributed 2 forces analysis as continuous non-normal 3 performs a Shapiro-Wilk test or nortest::ad.test to decide between normal or non-normal Default value is 1. |
all |
A logical |
A numeric vector of length 1
library(moonBook) y=acs$sex x=acs$height my.t.test2(y,x)
library(moonBook) y=acs$sex x=acs$height my.t.test2(y,x)
Fit Simple Proportional Hazards Regression Model
mycphSimple(fit, threshold = 0.2, digits = 2)
mycphSimple(fit, threshold = 0.2, digits = 2)
fit |
An object of class coxph |
threshold |
numeric p-value threshold to enter multiple model |
digits |
integer indicating the position decimal place |
An object of class "data.frame"
require(survival) data(cancer) fit=coxph(Surv(time,status)~age+sex+obstruct+perfor,data=colon) mycphSimple(fit)
require(survival) data(cancer) fit=coxph(Surv(time,status)~age+sex+obstruct+perfor,data=colon) mycphSimple(fit)
Convert data.frame to printable format
myformat(x, showid = FALSE, digits = 3)
myformat(x, showid = FALSE, digits = 3)
x |
A data.frame |
showid |
logical if TRUE, show id |
digits |
Integer indicating the number of decimal places |
A data.frame
fit=lm(mpg~wt*hp,data=mtcars) gaze(fit) %>% myformat()
fit=lm(mpg~wt*hp,data=mtcars) gaze(fit) %>% myformat()
Convert data.frame into flextable
myft(x, vanilla = TRUE, fontsize = 10, digits, showid = FALSE, ...)
myft(x, vanilla = TRUE, fontsize = 10, digits, showid = FALSE, ...)
x |
A data.frame |
vanilla |
logical |
fontsize |
Numeric |
digits |
integer indicating the position of decimal place |
showid |
logical if TRUE, show id |
... |
Further arguments to be passed to df2flextable() |
An object of class flextable
data(acs,package="moonBook") library(dplyr) gaze(acs) %>% myft() gaze(sex~.,acs) %>% myft() fit=lm(mpg~hp*wt,data=mtcars) gaze(fit) %>% myft() library(survival) fit=coxph(Surv(time,status) ~rx,data=anderson1) gaze(fit) %>% myft() gaze(sex+Dx~.,data=acs,show.p=TRUE,show.total=TRUE,show.n=TRUE,shiw.missing=TRUE) %>% myft() gaze(Dx+sex~cardiogenicShock,data=acs,show.p=TRUE) %>% myft() gaze(Dx+sex+HBP~cardiogenicShock,data=acs,show.p=TRUE) %>% myft()
data(acs,package="moonBook") library(dplyr) gaze(acs) %>% myft() gaze(sex~.,acs) %>% myft() fit=lm(mpg~hp*wt,data=mtcars) gaze(fit) %>% myft() library(survival) fit=coxph(Surv(time,status) ~rx,data=anderson1) gaze(fit) %>% myft() gaze(sex+Dx~.,data=acs,show.p=TRUE,show.total=TRUE,show.n=TRUE,shiw.missing=TRUE) %>% myft() gaze(Dx+sex~cardiogenicShock,data=acs,show.p=TRUE) %>% myft() gaze(Dx+sex+HBP~cardiogenicShock,data=acs,show.p=TRUE) %>% myft()
Fit Simple AFT Model
mysurvregSimple(fit, threshold = 0.2, digits = 2, mode = 1)
mysurvregSimple(fit, threshold = 0.2, digits = 2, mode = 1)
fit |
An object of class survreg |
threshold |
numeric p-value threshold to enter multiple model |
digits |
integer indicating the position decimal place |
mode |
integer |
An object of class "data.frame"
require(survival) data(cancer) fit=survreg(Surv(time,status)~rx+age+strata(sex)+obstruct+perfor,data=colon) mysurvregSimple(fit)
require(survival) data(cancer) fit=survreg(Surv(time,status)~rx+age+strata(sex)+obstruct+perfor,data=colon) mysurvregSimple(fit)
Convert a numeric column in a data.frame to a factor
num2factor(data, call, name, no = 3)
num2factor(data, call, name, no = 3)
data |
A data.frame |
call |
a function call |
name |
character Name of numeric column |
no |
numeric |
A data.frame
num2factor(anderson,name="logWBC") library(survival) fit=coxph(Surv(time,status)~logWBC+rx,data=anderson) num2factor(anderson,call=fit$call,name="logWBC",no=2)
num2factor(anderson,name="logWBC") library(survival) fit=coxph(Surv(time,status)~logWBC+rx,data=anderson) num2factor(anderson,call=fit$call,name="logWBC",no=2)
Summarize numeric vector to statistical summary
num2stat(x, digits = 1, method = 1, p = NULL)
num2stat(x, digits = 1, method = 1, p = NULL)
x |
A numeric vector |
digits |
integer indicating the number of decimal places |
method |
An integer indicating methods for continuous variables. Possible values in methods are 1 forces analysis as normal-distributed 2 forces analysis as continuous non-normal 3 performs a Shapiro-Wilk test or nortest::ad.test to decide between normal or non-normal Default value is 1. |
p |
A numeric |
A character vector of length 1
library(moonBook) num2stat(acs$age) num2stat(acs$age,method=2)
library(moonBook) num2stat(acs$age) num2stat(acs$age,method=2)
Draw an Observed vs Expected plot
OEplot(fit, xnames = NULL, no = 3, maxy.lev = 5, median = TRUE)
OEplot(fit, xnames = NULL, no = 3, maxy.lev = 5, median = TRUE)
fit |
An object of class "coxph" |
xnames |
Character Names of explanatory variable to plot |
no |
integer Number of groups to be made |
maxy.lev |
Integer Maximum unique length of a numeric variable to be treated as categorical variables |
median |
logical |
No return value, called for side effects
library(survival) data(cancer,package="survival") fit=coxph(Surv(time,status)~rx+age+sex,data=colon) OEplot(fit) OEplot(fit,xnames="sex") ## Not run: fit=coxph(Surv(time,status)~age,data=colon) OEplot(fit) fit=coxph(Surv(time,status)~logWBC,data=anderson) OEplot(fit) ## End(Not run)
library(survival) data(cancer,package="survival") fit=coxph(Surv(time,status)~rx+age+sex,data=colon) OEplot(fit) OEplot(fit,xnames="sex") ## Not run: fit=coxph(Surv(time,status)~age,data=colon) OEplot(fit) fit=coxph(Surv(time,status)~logWBC,data=anderson) OEplot(fit) ## End(Not run)
Change p value to string
p2character2(x, digits = 3, add.p = TRUE)
p2character2(x, digits = 3, add.p = TRUE)
x |
a numeric |
digits |
integer indicating decimal place |
add.p |
logical |
A character vector
S3 method print for an object of class autoReg
## S3 method for class 'autoReg' print(x, ...)
## S3 method for class 'autoReg' print(x, ...)
x |
An object of class autoReg |
... |
Further arguments |
No return value, called for side effects
data(cancer,package="survival") fit=glm(status~rx+sex+age+obstruct+nodes,data=colon,family="binomial") autoReg(fit)
data(cancer,package="survival") fit=glm(status~rx+sex+age+obstruct+nodes,data=colon,family="binomial") autoReg(fit)
S3 method print for an object of class gaze
## S3 method for class 'gaze' print(x, ...)
## S3 method for class 'gaze' print(x, ...)
x |
An object of class gaze |
... |
Further arguments |
No return value, called for side effects
data(acs,package="moonBook") x=gaze(acs,show.n=TRUE,show.missing=TRUE) gaze(sex~.,acs,show.p=TRUE,show.n=TRUE,show.missing=TRUE,show.total=TRUE) gaze(Dx+sex~.,acs,show.p=TRUE) gaze(sex+Dx+HBP~.,acs,show.p=TRUE)
data(acs,package="moonBook") x=gaze(acs,show.n=TRUE,show.missing=TRUE) gaze(sex~.,acs,show.p=TRUE,show.n=TRUE,show.missing=TRUE,show.total=TRUE) gaze(Dx+sex~.,acs,show.p=TRUE) gaze(sex+Dx+HBP~.,acs,show.p=TRUE)
S3 method for an class modelPlot
## S3 method for class 'modelPlot' print(x, ...)
## S3 method for class 'modelPlot' print(x, ...)
x |
An object of class modelPlot |
... |
Further arguments to be passed to plot() |
Print function for data.frame
printdf(x)
printdf(x)
x |
A data.frame |
No return value, called for side effects
x=mtcars[1:5,1:5] printdf(x)
x=mtcars[1:5,1:5] printdf(x)
Remove duplicated term
removeDup(x, replacement = "")
removeDup(x, replacement = "")
x |
A vector |
replacement |
A character to be replaced or NA |
A vector with the same class as x
x=rep(1:5,each=3) removeDup(x)
x=rep(1:5,each=3) removeDup(x)
Make a residual plot of NULL model
residualNull(x, add.log = TRUE, type = "martingale")
residualNull(x, add.log = TRUE, type = "martingale")
x |
An object of calss coxph |
add.log |
logical If true, log of predictor varaibles are added |
type |
character type of residuals |
library(survival) data(pharmacoSmoking,package="asaur") pharmacoSmoking$priorAttemptsT=pharmacoSmoking$priorAttempts pharmacoSmoking$priorAttemptsT[pharmacoSmoking$priorAttemptsT>20]=20 x=coxph(Surv(ttr,relapse)~age+priorAttemptsT+longestNoSmoke,data=pharmacoSmoking) residualNull(x)
library(survival) data(pharmacoSmoking,package="asaur") pharmacoSmoking$priorAttemptsT=pharmacoSmoking$priorAttempts pharmacoSmoking$priorAttemptsT[pharmacoSmoking$priorAttemptsT>20]=20 x=coxph(Surv(ttr,relapse)~age+priorAttemptsT+longestNoSmoke,data=pharmacoSmoking) residualNull(x)
Draw a residual plot with an object of class coxph
residualPlot( fit, type = "martingale", vars = NULL, ncol = 2, show.point = TRUE, se = TRUE, topn = 5, labelsize = 4 )
residualPlot( fit, type = "martingale", vars = NULL, ncol = 2, show.point = TRUE, se = TRUE, topn = 5, labelsize = 4 )
fit |
An object of class coxph or survreg |
type |
character One of the c("martingale","deviance","score","schoenfeld", "dfbeta","dfbetas","scaledsch","partial"). Default value is "martingale". |
vars |
character Names of variables to plot. default value is NULL |
ncol |
numeric number of columns |
show.point |
logical Whether or not show point |
se |
logical Whether or not show se |
topn |
numeric number of data to be labelled |
labelsize |
numeric size of label |
A patchwork object
require(survival) data(cancer) fit=coxph(Surv(time,status==2)~log(bili)+age+cluster(edema),data=pbc) residualPlot(fit) residualPlot(fit,vars="age") fit=coxph(Surv(time,status==2)~age,data=pbc) residualPlot(fit) residualPlot(fit,"partial") fit=coxph(Surv(time,status)~rx+sex+logWBC,data=anderson) residualPlot(fit,ncol=3) ## Not run: data(pharmacoSmoking,package="asaur") fit=coxph(Surv(ttr,relapse)~grp+employment+age,data=pharmacoSmoking) residualPlot(fit) residualPlot(fit,var="age") residualPlot(fit,type="dfbeta") residualPlot(fit,type="dfbeta",var="age") residualPlot(fit,type="dfbeta",var="employment") residualPlot(fit,type="dfbeta",var="employmentother") pharmacoSmoking$ttr[pharmacoSmoking$ttr==0]=0.5 fit=survreg(Surv(ttr,relapse)~grp+age+employment,data=pharmacoSmoking,dist="weibull") residualPlot(fit,type="response") residualPlot(fit,type="deviance") residualPlot(fit,type="dfbeta",vars="age") fit=survreg(Surv(time,status)~ph.ecog+sex*age,data=lung,dist="weibull") residualPlot(fit,"dfbeta") residualPlot(fit,"deviance") ## End(Not run)
require(survival) data(cancer) fit=coxph(Surv(time,status==2)~log(bili)+age+cluster(edema),data=pbc) residualPlot(fit) residualPlot(fit,vars="age") fit=coxph(Surv(time,status==2)~age,data=pbc) residualPlot(fit) residualPlot(fit,"partial") fit=coxph(Surv(time,status)~rx+sex+logWBC,data=anderson) residualPlot(fit,ncol=3) ## Not run: data(pharmacoSmoking,package="asaur") fit=coxph(Surv(ttr,relapse)~grp+employment+age,data=pharmacoSmoking) residualPlot(fit) residualPlot(fit,var="age") residualPlot(fit,type="dfbeta") residualPlot(fit,type="dfbeta",var="age") residualPlot(fit,type="dfbeta",var="employment") residualPlot(fit,type="dfbeta",var="employmentother") pharmacoSmoking$ttr[pharmacoSmoking$ttr==0]=0.5 fit=survreg(Surv(ttr,relapse)~grp+age+employment,data=pharmacoSmoking,dist="weibull") residualPlot(fit,type="response") residualPlot(fit,type="deviance") residualPlot(fit,type="dfbeta",vars="age") fit=survreg(Surv(time,status)~ph.ecog+sex*age,data=lung,dist="weibull") residualPlot(fit,"dfbeta") residualPlot(fit,"deviance") ## End(Not run)
restore data with factor in column name
restoreData(data)
restoreData(data)
data |
An object of class "data.frame" |
An object of class "data.frame"
restore data with I() in column name
restoreData2(df)
restoreData2(df)
df |
An object of class "data.frame" |
An object of class "data.frame"
restore data with operator in column name
restoreData3(df, changeLabel = FALSE)
restoreData3(df, changeLabel = FALSE)
df |
An object of class "data.frame" |
changeLabel |
logical |
An object of class "data.frame"
get opposite arithmetic operator
revOperator(operator)
revOperator(operator)
operator |
A character |
A character
Convert numeric columns of data.frame to character
roundDf(df, digits = 2)
roundDf(df, digits = 2)
df |
a data.frame |
digits |
integer indicating the number of decimal places |
An object of class "data.frame"
Add label to a vector
setLabel(x, label = "")
setLabel(x, label = "")
x |
a vector |
label |
string |
a labelled vector
Shorten an object of class gaze
shorten(x, xname = NULL, ref = 1)
shorten(x, xname = NULL, ref = 1)
x |
an object of class gaze |
xname |
A variable name |
ref |
Numeric Th number to be used as reference |
An object of class "gaze" which is described in gaze
data(acs,package="moonBook") x=gaze(sex~.,data=acs) shorten(x)
data(acs,package="moonBook") x=gaze(sex~.,data=acs) shorten(x)
Show effects of covariates
showEffect( fit, x = NULL, color = NULL, facet = NULL, autovar = TRUE, pred.values = list(), se = TRUE, logy = TRUE, collabel = label_both, rowlabel = label_both )
showEffect( fit, x = NULL, color = NULL, facet = NULL, autovar = TRUE, pred.values = list(), se = TRUE, logy = TRUE, collabel = label_both, rowlabel = label_both )
fit |
An object of class survreg |
x |
character name of x-axis variable |
color |
character name of color variable |
facet |
character name of facet variable |
autovar |
logical Whether or not select color and facet variable automatically |
pred.values |
list list of values of predictor variables |
se |
logical whether or not show se |
logy |
logical WHether or not draw y-axis on log scale |
collabel |
labeller for column |
rowlabel |
labeller for row |
A ggplot
library(survival) library(ggplot2) fit=survreg(Surv(time,status)~ph.ecog+sex*age,data=lung,dist="weibull") showEffect(fit) fit=survreg(Surv(time,status)~rx+sex+age+obstruct+adhere,data=colon,dist="weibull") showEffect(fit) showEffect(fit,rowlabel=label_value) fit=survreg(Surv(time,status)~ph.ecog+sex,data=lung,dist="weibull") showEffect(fit) fit=survreg(Surv(time,status)~ph.ecog+age,data=lung,dist="weibull") showEffect(fit) fit=survreg(Surv(time,status)~ph.ecog+sex*age,data=lung,dist="weibull") showEffect(fit,x="age",color="sex",facet="ph.ecog") showEffect(fit,pred.values=list(age=c(50,60,70),ph.ecog=c(0,3),sex=c(1,2)), x="ph.ecog",color="sex",facet="age",autovar=FALSE) fit=survreg(Surv(time,status)~age,data=lung,dist="weibull") showEffect(fit)
library(survival) library(ggplot2) fit=survreg(Surv(time,status)~ph.ecog+sex*age,data=lung,dist="weibull") showEffect(fit) fit=survreg(Surv(time,status)~rx+sex+age+obstruct+adhere,data=colon,dist="weibull") showEffect(fit) showEffect(fit,rowlabel=label_value) fit=survreg(Surv(time,status)~ph.ecog+sex,data=lung,dist="weibull") showEffect(fit) fit=survreg(Surv(time,status)~ph.ecog+age,data=lung,dist="weibull") showEffect(fit) fit=survreg(Surv(time,status)~ph.ecog+sex*age,data=lung,dist="weibull") showEffect(fit,x="age",color="sex",facet="ph.ecog") showEffect(fit,pred.values=list(age=c(50,60,70),ph.ecog=c(0,3),sex=c(1,2)), x="ph.ecog",color="sex",facet="age",autovar=FALSE) fit=survreg(Surv(time,status)~age,data=lung,dist="weibull") showEffect(fit)
Convert a character vector to a data.frame
strata2df(strata)
strata2df(strata)
strata |
A character vector |
A data.frame
Extract survival data from an object of class "survfit"
survfit2df(fit, labels = NULL)
survfit2df(fit, labels = NULL)
fit |
An object of class "survfit" |
labels |
Character |
A data.frame
library(survival) data(cancer,package="survival") fit=survfit(coxph(Surv(time,status)~sex+age+strata(rx),data=colon)) survfit2df(fit) ## Not run: fit=coxph(Surv(time,status)~sex+age+strata(rx),data=colon) fit=survfit(as.formula(deparse(fit$terms)),data=fit2model(fit)) survfit2df(fit) fit=survfit(Surv(time,status)~rx+sex+age,data=colon) survfit2df(fit) fit=survfit(Surv(time,status)~1,data=colon) survfit2df(fit) ## End(Not run)
library(survival) data(cancer,package="survival") fit=survfit(coxph(Surv(time,status)~sex+age+strata(rx),data=colon)) survfit2df(fit) ## Not run: fit=coxph(Surv(time,status)~sex+age+strata(rx),data=colon) fit=survfit(as.formula(deparse(fit$terms)),data=fit2model(fit)) survfit2df(fit) fit=survfit(Surv(time,status)~rx+sex+age,data=colon) survfit2df(fit) fit=survfit(Surv(time,status)~1,data=colon) survfit2df(fit) ## End(Not run)
Make final model using stepwise backward elimination
survreg2final(fit, threshold = 0.2)
survreg2final(fit, threshold = 0.2)
fit |
An object of class "survreg" |
threshold |
Numeric |
An object of class "survreg" which is described in survreg
require(survival) data(cancer) fit=survreg(Surv(time,status)~rx+age+sex+obstruct+perfor,data=colon) survreg2final(fit)
require(survival) data(cancer) fit=survreg(Surv(time,status)~rx+age+sex+obstruct+perfor,data=colon) survreg2final(fit)
Make multivariable regression model by selecting univariable models with p.value below threshold
survreg2multi(fit, threshold = 0.2)
survreg2multi(fit, threshold = 0.2)
fit |
An object of class "survreg" |
threshold |
Numeric |
An object of class "survreg"
require(survival) data(cancer) fit=survreg(Surv(time,status)~rx+age+sex+obstruct+perfor,data=colon) survreg2multi(fit)
require(survival) data(cancer) fit=survreg(Surv(time,status)~rx+age+sex+obstruct+perfor,data=colon) survreg2multi(fit)