diff --git a/NAMESPACE b/NAMESPACE index 32edf62..6024aa3 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -15,3 +15,4 @@ export(rep_epi_tests) export(rep_glm) export(rep_lm) export(rep_reg_cie) +export(strobe_print) diff --git a/R/strobe_print.R b/R/strobe_print.R new file mode 100644 index 0000000..a65fab8 --- /dev/null +++ b/R/strobe_print.R @@ -0,0 +1,67 @@ +#' Print regression results according to STROBE +#' +#' 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 var exposure variable to compare against (active vs placebo). As string. +#' @param groups 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. +#' @keywords cpr +#' @export +#' @examples +#' strobe_print() + +strobe_print<-function(meas,var,group,adj,data,dec=2){ + ## meas: sdmt + ## var: rtreat + ## group: genotype + ## for dichotome exposure variable (var) + + d<-data + m<-d[,c(meas)] + v<-d[,c(var)] + g<-d[,c(group)] + + ads<-d[,c(adj)] + + dat<-data.frame(m,v,g,ads) + + 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") + + for (i in 1:length(levels(g))){ + grp<-levels(dat$g)[i] + di<-dat[dat$g==grp,][,-3] + + mod<-lm(m~v,data=di) + co<-round(coef(mod)[-1],dec) + lo<-round(confint(mod)[-1,1],dec) + up<-round(confint(mod)[-1,2],dec) + + ci<-paste0(co," (",lo," to ",up,")") + + amod<-lm(m~.,data=di) + aco<-round(coef(amod)[2],dec) + alo<-round(confint(amod)[2,1],dec) + aup<-round(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),])) + mean<-round(mean(dr$m,na.rm = TRUE),dec-1) + sd<-round(sd(dr$m,na.rm = TRUE),dec-1) + ms<-paste0(mean," (",sd,")") + + nr<-c(nr,n,ms) + } + irl<-c(grp,nr,ci,aci) + df<-rbind(df,irl) + } + return(df) +} diff --git a/man/strobe_print.Rd b/man/strobe_print.Rd new file mode 100644 index 0000000..caee245 --- /dev/null +++ b/man/strobe_print.Rd @@ -0,0 +1,28 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/strobe_print.R +\name{strobe_print} +\alias{strobe_print} +\title{Print regression results according to STROBE} +\usage{ +strobe_print(meas, var, group, adj, data, dec = 2) +} +\arguments{ +\item{meas}{outcome meassure variable name in data-data.frame as a string.} + +\item{var}{exposure variable to compare against (active vs placebo). 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 linear regression analysis of group vs var for meas. +} +\examples{ +strobe_print() +} +\keyword{cpr}