From 3573b74a1b1085e8195dfbd0ec57afd524fd91bb Mon Sep 17 00:00:00 2001 From: agdamsbo Date: Tue, 12 Nov 2019 14:12:27 +0100 Subject: [PATCH] updates --- DESCRIPTION | 2 +- R/strobe_diff_bygroup.R | 2 +- R/strobe_diff_byvar.R | 2 +- R/strobe_olr.R | 4 ++-- R/strobe_pred.R | 35 +++++++++++++++++++++++++---------- man/strobe_diff_bygroup.Rd | 4 ++-- man/strobe_diff_byvar.Rd | 4 ++-- man/strobe_olr.Rd | 4 ++-- man/strobe_pred.Rd | 7 +++++-- 9 files changed, 41 insertions(+), 23 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 2f32dbe..abccea3 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: daDoctoR Type: Package Title: FUNCTIONS FOR HEALTH RESEARCH -Version: 0.1.0.9024 +Version: 0.1.0.9025 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_diff_bygroup.R b/R/strobe_diff_bygroup.R index 47b0f2b..eba9c4b 100644 --- a/R/strobe_diff_bygroup.R +++ b/R/strobe_diff_bygroup.R @@ -3,7 +3,7 @@ #' Printable table of three dimensional regression analysis of group vs var for meas. By group. #' @param meas outcome meassure variable name in data-data.frame as a string. Can be numeric or factor. Result is calculated accordingly. #' @param var binary exposure variable to compare against (active vs placebo). As string. -#' @param groups groups to compare, as string. +#' @param group group to compare, as string. #' @param adj variables to adjust for, as string. #' @param data dataframe of data. #' @param dec decimals for results, standard is set to 2. Mean and sd is dec-1. pval has 3 decimals. diff --git a/R/strobe_diff_byvar.R b/R/strobe_diff_byvar.R index 3e48abd..bc21dcf 100644 --- a/R/strobe_diff_byvar.R +++ b/R/strobe_diff_byvar.R @@ -3,7 +3,7 @@ #' Printable table of three dimensional regression analysis of group vs var for meas. By var. Includes p-values. #' @param meas outcome meassure variable name in data-data.frame as a string. Can be numeric or factor. Result is calculated accordingly. #' @param var binary exposure variable to compare against (active vs placebo). As string. -#' @param groups groups to compare, as string. +#' @param group groups to compare, as string. #' @param adj variables to adjust for, as string. #' @param data dataframe of data. #' @param dec decimals for results, standard is set to 2. Mean and sd is dec-1. diff --git a/R/strobe_olr.R b/R/strobe_olr.R index 53ed158..6d46ea6 100644 --- a/R/strobe_olr.R +++ b/R/strobe_olr.R @@ -1,6 +1,6 @@ -#' Print regression results according to STROBE +#' Print ordinal logistic regression results according to STROBE #' -#' Printable table of logistic regression analysis oaccording to STROBE. +#' Printable table of ordinal logistic regression analysis oaccording to STROBE. Uses polr() funtion of the MASS-package. #' @param meas outcome meassure variable name in data-data.frame as a string. Can be numeric or factor. Result is calculated accordingly. #' @param vars variables to compare against. As vector of columnnames. #' @param data dataframe of data. diff --git a/R/strobe_pred.R b/R/strobe_pred.R index 47288d7..4323e68 100644 --- a/R/strobe_pred.R +++ b/R/strobe_pred.R @@ -1,15 +1,16 @@ #' Regression model of predictors according to STROBE, bi- and multivariate. #' -#' Printable table of regression model according to STROBE. Includes borth bivariate and multivariate in the same table. Output is a list, with the first item being the main "output" as a dataframe. Automatically uses logistic regression model for dichotomous outcome variable and linear regression model for continous outcome variable. +#' Printable table of regression model according to STROBE. Includes borth bivariate and multivariate in the same table. Output is a list, with the first item being the main "output" as a dataframe. Automatically uses logistic regression model for dichotomous outcome variable and linear regression model for continous outcome variable. Linear regression will give estimated adjusted true mean in list. #' @param meas binary outcome meassure variable, column name in data.frame as a string. Can be numeric or factor. Result is calculated accordingly. #' @param adj variables to adjust for, as string. #' @param data dataframe of data. #' @param dec decimals for results, standard is set to 2. Mean and sd is dec-1. #' @param n.by.adj flag to indicate wether to count number of patients in adjusted model or overall for outcome meassure not NA. +#' @param p.val flag to include p-values in linear regression for now, set to FALSE as standard. #' @keywords logistic #' @export -strobe_pred<-function(meas,adj,data,dec=2,n.by.adj=FALSE){ +strobe_pred<-function(meas,adj,data,dec=2,n.by.adj=FALSE,p.val=FALSE){ ## Ønskeliste: ## ## - Tæl selv antal a NA'er @@ -178,7 +179,7 @@ strobe_pred<-function(meas,adj,data,dec=2,n.by.adj=FALSE){ ads<-d[,c(adj)] dfcr<-data.frame(matrix(NA,ncol = 3)) - names(dfcr)<-c("pred","mean_ci","pv") + names(dfcr)<-c("pred","dif_ci","pv") n.mn<-c() nref<-c() @@ -192,9 +193,13 @@ strobe_pred<-function(meas,adj,data,dec=2,n.by.adj=FALSE){ suppressMessages(ci<-confint(mn)) l<-round(ci[-1,1],dec) u<-round(ci[-1,2],dec) - mean<-round(coef(mn)[-1],dec) - mean_ci<-paste0(mean," (",l," to ",u,")") + dif<-round(coef(mn)[-1],dec) + dif_ci<-paste0(dif," (",l," to ",u,")") pv<-round(tidy(mn)$p.value[-1],dec+1) + pv<-ifelse(pv<0.001,"<0.001",round(pv,3)) + pv <- ifelse(pv<=0.05|pv=="<0.001",paste0("*",pv), + ifelse(pv>0.05&pv<=0.1,paste0(".",pv),pv)) + x1<-ads[,i] if (is.factor(x1)){ @@ -205,7 +210,7 @@ strobe_pred<-function(meas,adj,data,dec=2,n.by.adj=FALSE){ pred<-names(ads)[i] } - dfcr<-rbind(dfcr,cbind(pred,mean_ci,pv)) + dfcr<-rbind(dfcr,cbind(pred,dif_ci,pv)) } ## Mutually adjusted ORs @@ -214,6 +219,7 @@ strobe_pred<-function(meas,adj,data,dec=2,n.by.adj=FALSE){ ma <- lm(m ~ ., data = dat) miss<-length(ma$na.action) + actable <- coef(summary(ma)) pa <- actable[,4] pa<-ifelse(pa<0.001,"<0.001",round(pa,3)) @@ -228,6 +234,8 @@ strobe_pred<-function(meas,adj,data,dec=2,n.by.adj=FALSE){ aup<-aci[,2] amean_ci<-paste0(aco," (",alo," to ",aup,")") + mean_est<-amean_ci[[1]] + nq<-c() @@ -312,12 +320,19 @@ strobe_pred<-function(meas,adj,data,dec=2,n.by.adj=FALSE){ suppressWarnings(re<-left_join(df,dfcr,by="names")) - ref<-data.frame(re[,1],re[,2],re[,5],re[,3]) + if (p.val==TRUE){ + ref<-data.frame(re[,1],re[,2],re[,5],re[,6],re[,3],re[,4]) - names(ref)<-c("Variable",paste0("N=",n.meas),"Crude OR (95 % CI)","Mutually adjusted OR (95 % CI)") + 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]) - ls<-list(tbl=ref,miss,n.meas,nrow(d)) - names(ls)<-c("Printable table","Deleted due to missingness in adjusted analysis","Number of outcome observations","Length of dataframe") + names(ref)<-c("Variable",paste0("N=",n.meas),"Difference (95 % CI)","Mutually adjusted difference (95 % CI)") + } + + ls<-list(tbl=ref,miss,n.meas,nrow(d),mean_est) + names(ls)<-c("Printable table","Deleted due to missingness in adjusted analysis","Number of outcome observations","Length of dataframe","Estimated true mean (95 % CI) in adjusted analysis") } diff --git a/man/strobe_diff_bygroup.Rd b/man/strobe_diff_bygroup.Rd index 0edf96d..ced733d 100644 --- a/man/strobe_diff_bygroup.Rd +++ b/man/strobe_diff_bygroup.Rd @@ -11,13 +11,13 @@ strobe_diff_bygroup(meas, var, group, adj, data, dec = 2) \item{var}{binary exposure variable to compare against (active vs placebo). As string.} +\item{group}{group to compare, as string.} + \item{adj}{variables to adjust for, as string.} \item{data}{dataframe of data.} \item{dec}{decimals for results, standard is set to 2. Mean and sd is dec-1. pval has 3 decimals.} - -\item{groups}{groups to compare, as string.} } \description{ Printable table of three dimensional regression analysis of group vs var for meas. By group. diff --git a/man/strobe_diff_byvar.Rd b/man/strobe_diff_byvar.Rd index 3968c78..b85073c 100644 --- a/man/strobe_diff_byvar.Rd +++ b/man/strobe_diff_byvar.Rd @@ -11,13 +11,13 @@ strobe_diff_byvar(meas, var, group, adj, data, dec = 2) \item{var}{binary exposure variable to compare against (active vs placebo). As string.} +\item{group}{groups to compare, as string.} + \item{adj}{variables to adjust for, as string.} \item{data}{dataframe of data.} \item{dec}{decimals for results, standard is set to 2. Mean and sd is dec-1.} - -\item{groups}{groups to compare, as string.} } \description{ Printable table of three dimensional regression analysis of group vs var for meas. By var. Includes p-values. diff --git a/man/strobe_olr.Rd b/man/strobe_olr.Rd index 0f0dd6b..a50b0bb 100644 --- a/man/strobe_olr.Rd +++ b/man/strobe_olr.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/strobe_olr.R \name{strobe_olr} \alias{strobe_olr} -\title{Print regression results according to STROBE} +\title{Print ordinal logistic regression results according to STROBE} \usage{ strobe_olr(meas, vars, data, dec = 2) } @@ -16,6 +16,6 @@ strobe_olr(meas, vars, data, dec = 2) \item{dec}{decimals for results, standard is set to 2. Mean and sd is dec-1.} } \description{ -Printable table of logistic regression analysis oaccording to STROBE. +Printable table of ordinal logistic regression analysis oaccording to STROBE. Uses polr() funtion of the MASS-package. } \keyword{olr} diff --git a/man/strobe_pred.Rd b/man/strobe_pred.Rd index 4e8ac80..067e056 100644 --- a/man/strobe_pred.Rd +++ b/man/strobe_pred.Rd @@ -4,7 +4,8 @@ \alias{strobe_pred} \title{Regression model of predictors according to STROBE, bi- and multivariate.} \usage{ -strobe_pred(meas, adj, data, dec = 2, n.by.adj = FALSE) +strobe_pred(meas, adj, data, dec = 2, n.by.adj = FALSE, + p.val = FALSE) } \arguments{ \item{meas}{binary outcome meassure variable, column name in data.frame as a string. Can be numeric or factor. Result is calculated accordingly.} @@ -16,8 +17,10 @@ strobe_pred(meas, adj, data, dec = 2, n.by.adj = FALSE) \item{dec}{decimals for results, standard is set to 2. Mean and sd is dec-1.} \item{n.by.adj}{flag to indicate wether to count number of patients in adjusted model or overall for outcome meassure not NA.} + +\item{p.val}{flag to include p-values in linear regression for now, set to FALSE as standard.} } \description{ -Printable table of regression model according to STROBE. Includes borth bivariate and multivariate in the same table. Output is a list, with the first item being the main "output" as a dataframe. Automatically uses logistic regression model for dichotomous outcome variable and linear regression model for continous outcome variable. +Printable table of regression model according to STROBE. Includes borth bivariate and multivariate in the same table. Output is a list, with the first item being the main "output" as a dataframe. Automatically uses logistic regression model for dichotomous outcome variable and linear regression model for continous outcome variable. Linear regression will give estimated adjusted true mean in list. } \keyword{logistic}