From 93fea3a8a6701c5489b7347d3a2aecd64be251ec Mon Sep 17 00:00:00 2001 From: agdamsbo Date: Wed, 13 Nov 2019 11:11:26 +0100 Subject: [PATCH] new var.names --- DESCRIPTION | 2 +- R/strobe_pred.R | 26 ++++++++++++++++++++++---- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index f4962c5..814a782 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: daDoctoR Type: Package Title: FUNCTIONS FOR HEALTH RESEARCH -Version: 0.1.0.9028 +Version: 0.1.0.9029 Author: c(person("Andreas", "Gammelgaard Damsbo", email = "agdamsbo@pm.me", role = c("cre", "aut"))) Maintainer: Andreas Gammelgaard Damsbo Description: I am a Danish medical doctor involved in neuropsychiatric research. diff --git a/R/strobe_pred.R b/R/strobe_pred.R index f61d9dc..32f110f 100644 --- a/R/strobe_pred.R +++ b/R/strobe_pred.R @@ -161,13 +161,22 @@ strobe_pred<-function(meas,adj,data,dec=2,n.by.adj=FALSE,p.val=FALSE){ suppressWarnings(re<-left_join(df,dfcr,by="names")) + rona<-c() + for (i in 1:length(ads)){ + if (is.factor(ads[,i])){ + rona<-c(rona,names(ads[i]),levels(ads[,i])) + if (!is.factor(ads[,i])){ + rona<-c(rona,names(ads[i]),"Per unit increase") + } + }} + if (p.val==TRUE){ - ref<-data.frame(re[,1],re[,2],re[,5],re[,6],re[,3],re[,4]) + ref<-data.frame(c(NA,rona),re[,2],re[,5],re[,6],re[,3],re[,4]) names(ref)<-c("Variable",paste0("N=",n.meas),"Crude OR (95 % CI)","p-value","Mutually adjusted OR (95 % CI)","A p-value") } else{ - ref<-data.frame(re[,1],re[,2],re[,5],re[,3]) + ref<-data.frame(c(NA,rona),re[,2],re[,5],re[,3]) names(ref)<-c("Variable",paste0("N=",n.meas),"Crude OR (95 % CI)","Mutually adjusted OR (95 % CI)") } @@ -319,13 +328,22 @@ strobe_pred<-function(meas,adj,data,dec=2,n.by.adj=FALSE,p.val=FALSE){ suppressWarnings(re<-left_join(df,dfcr,by="names")) + rona<-c() + for (i in 1:length(ads)){ + if (is.factor(ads[,i])){ + rona<-c(rona,names(ads[i]),levels(ads[,i])) + if (!is.factor(ads[,i])){ + rona<-c(rona,names(ads[i]),"Per unit increase") + } + }} + if (p.val==TRUE){ - ref<-data.frame(re[,1],re[,2],re[,5],re[,6],re[,3],re[,4]) + ref<-data.frame(c(NA,rona),re[,2],re[,5],re[,6],re[,3],re[,4]) names(ref)<-c("Variable",paste0("N=",n.meas),"Difference (95 % CI)","p-value","Mutually adjusted difference (95 % CI)","A p-value") } else{ - ref<-data.frame(re[,1],re[,2],re[,5],re[,3]) + ref<-data.frame(c(NA,rona),re[,2],re[,5],re[,3]) names(ref)<-c("Variable",paste0("N=",n.meas),"Difference (95 % CI)","Mutually adjusted difference (95 % CI)") }