mirror of
https://github.com/agdamsbo/daDoctoR.git
synced 2024-11-22 11:50:23 +01:00
u
This commit is contained in:
parent
38928f53c1
commit
a56f4d3a1d
@ -1,7 +1,7 @@
|
|||||||
#' Print regression results according to STROBE
|
#' Print regression results according to STROBE
|
||||||
#'
|
#'
|
||||||
#' Printable table of linear regression analysis of group vs var for meas.
|
#' Printable table of linear regression analysis of group vs var for meas.
|
||||||
#' @param meas outcome meassure variable name in data-data.frame as a string.
|
#' @param meas outcome meassure variable name in data-data.frame as a string. Can be numeric or factor. Result is calculated accordingly.
|
||||||
#' @param var exposure variable to compare against (active vs placebo). As string.
|
#' @param var exposure variable to compare against (active vs placebo). As string.
|
||||||
#' @param groups groups to compare, as string.
|
#' @param groups groups to compare, as string.
|
||||||
#' @param adj variables to adjust for, as string.
|
#' @param adj variables to adjust for, as string.
|
||||||
@ -28,7 +28,8 @@ strobe_print<-function(meas,var,group,adj,data,dec=2){
|
|||||||
dat<-data.frame(m,v,g,ads)
|
dat<-data.frame(m,v,g,ads)
|
||||||
|
|
||||||
df<-data.frame(matrix(ncol=7))
|
df<-data.frame(matrix(ncol=7))
|
||||||
names(df)<-c("grp",paste0("N.",substr(levels(v)[1],1,3)),paste0("M.",substr(levels(v)[1],1,3)),paste0("N.",substr(levels(v)[2],1,3)),paste0("M.",substr(levels(v)[2],1,3)),"diff","ad.diff")
|
|
||||||
|
if(!is.factor(m)){
|
||||||
|
|
||||||
for (i in 1:length(levels(g))){
|
for (i in 1:length(levels(g))){
|
||||||
grp<-levels(dat$g)[i]
|
grp<-levels(dat$g)[i]
|
||||||
@ -62,6 +63,46 @@ strobe_print<-function(meas,var,group,adj,data,dec=2){
|
|||||||
}
|
}
|
||||||
irl<-c(grp,nr,ci,aci)
|
irl<-c(grp,nr,ci,aci)
|
||||||
df<-rbind(df,irl)
|
df<-rbind(df,irl)
|
||||||
|
names(df)<-c("grp",paste0("N.",substr(levels(v)[1],1,3)),paste0("M.",substr(levels(v)[1],1,3)),paste0("N.",substr(levels(v)[2],1,3)),paste0("M.",substr(levels(v)[2],1,3)),"diff","ad.diff")
|
||||||
|
}}
|
||||||
|
|
||||||
|
if(is.factor(m)){
|
||||||
|
|
||||||
|
for (i in 1:length(levels(g))){
|
||||||
|
grp<-levels(dat$g)[i]
|
||||||
|
di<-dat[dat$g==grp,][,-3]
|
||||||
|
|
||||||
|
mod<-glm(m~v,family=binomial(),data=di)
|
||||||
|
co<-round(exp(coef(mod)[-1]),dec)
|
||||||
|
lo<-round(exp(confint(mod)[-1,1]),dec)
|
||||||
|
up<-round(exp(confint(mod)[-1,2]),dec)
|
||||||
|
|
||||||
|
ci<-paste0(co," (",lo," to ",up,")")
|
||||||
|
|
||||||
|
amod<-glm(m~.,family=binomial(),data=di)
|
||||||
|
aco<-round(exp(coef(amod)[2]),dec)
|
||||||
|
alo<-round(exp(confint(amod)[2,1]),dec)
|
||||||
|
aup<-round(exp(confint(amod)[2,2]),dec)
|
||||||
|
|
||||||
|
aci<-paste0(aco," (",alo," to ",aup,")")
|
||||||
|
|
||||||
|
nr<-c()
|
||||||
|
|
||||||
|
for (r in 1:2){
|
||||||
|
vr<-levels(di$v)[r]
|
||||||
|
dr<-di[di$v==vr,]
|
||||||
|
n<-as.numeric(nrow(dr[!is.na(dr$m),]))
|
||||||
|
nl<-levels(m)[2]
|
||||||
|
out<-nrow(dr[dr$m==nl&!is.na(dr$m),])
|
||||||
|
pro<-round(out/n*100,0)
|
||||||
|
rt<-paste0(out," (",pro,"%)")
|
||||||
|
|
||||||
|
nr<-c(nr,n,rt)
|
||||||
}
|
}
|
||||||
|
irl<-c(grp,nr,ci,aci)
|
||||||
|
df<-rbind(df,irl)
|
||||||
|
names(df)<-c("grp",paste0("N.",substr(levels(v)[1],1,3)),paste0(nl,".",substr(levels(v)[1],1,3)),paste0("N.",substr(levels(v)[2],1,3)),paste0(nl,".",substr(levels(v)[2],1,3)),"OR","ad.OR")
|
||||||
|
}}
|
||||||
|
|
||||||
return(df)
|
return(df)
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
strobe_print(meas, var, group, adj, data, dec = 2)
|
strobe_print(meas, var, group, adj, data, dec = 2)
|
||||||
}
|
}
|
||||||
\arguments{
|
\arguments{
|
||||||
\item{meas}{outcome meassure variable name in data-data.frame as a string.}
|
\item{meas}{outcome meassure variable name in data-data.frame as a string. Can be numeric or factor. Result is calculated accordingly.}
|
||||||
|
|
||||||
\item{var}{exposure variable to compare against (active vs placebo). As string.}
|
\item{var}{exposure variable to compare against (active vs placebo). As string.}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user