This commit is contained in:
agdamsbo 2019-11-12 14:12:27 +01:00
parent 662d111f0b
commit 3573b74a1b
9 changed files with 41 additions and 23 deletions

View File

@ -1,7 +1,7 @@
Package: daDoctoR Package: daDoctoR
Type: Package Type: Package
Title: FUNCTIONS FOR HEALTH RESEARCH 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"))) Author: c(person("Andreas", "Gammelgaard Damsbo", email = "agdamsbo@pm.me", role = c("cre", "aut")))
Maintainer: Andreas Gammelgaard Damsbo <agdamsbo@pm.me> Maintainer: Andreas Gammelgaard Damsbo <agdamsbo@pm.me>
Description: I am a Danish medical doctor involved in neuropsychiatric research. Description: I am a Danish medical doctor involved in neuropsychiatric research.

View File

@ -3,7 +3,7 @@
#' Printable table of three dimensional regression analysis of group vs var for meas. By group. #' 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 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 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 adj variables to adjust for, as string.
#' @param data dataframe of data. #' @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. #' @param dec decimals for results, standard is set to 2. Mean and sd is dec-1. pval has 3 decimals.

View File

@ -3,7 +3,7 @@
#' Printable table of three dimensional regression analysis of group vs var for meas. By var. Includes p-values. #' 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 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 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 adj variables to adjust for, as string.
#' @param data dataframe of data. #' @param data dataframe of data.
#' @param dec decimals for results, standard is set to 2. Mean and sd is dec-1. #' @param dec decimals for results, standard is set to 2. Mean and sd is dec-1.

View File

@ -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 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 vars variables to compare against. As vector of columnnames.
#' @param data dataframe of data. #' @param data dataframe of data.

View File

@ -1,15 +1,16 @@
#' Regression model of predictors according to STROBE, bi- and multivariate. #' 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 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 adj variables to adjust for, as string.
#' @param data dataframe of data. #' @param data dataframe of data.
#' @param dec decimals for results, standard is set to 2. Mean and sd is dec-1. #' @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 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 #' @keywords logistic
#' @export #' @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: ## Ønskeliste:
## ##
## - Tæl selv antal a NA'er ## - 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)] ads<-d[,c(adj)]
dfcr<-data.frame(matrix(NA,ncol = 3)) dfcr<-data.frame(matrix(NA,ncol = 3))
names(dfcr)<-c("pred","mean_ci","pv") names(dfcr)<-c("pred","dif_ci","pv")
n.mn<-c() n.mn<-c()
nref<-c() nref<-c()
@ -192,9 +193,13 @@ strobe_pred<-function(meas,adj,data,dec=2,n.by.adj=FALSE){
suppressMessages(ci<-confint(mn)) suppressMessages(ci<-confint(mn))
l<-round(ci[-1,1],dec) l<-round(ci[-1,1],dec)
u<-round(ci[-1,2],dec) u<-round(ci[-1,2],dec)
mean<-round(coef(mn)[-1],dec) dif<-round(coef(mn)[-1],dec)
mean_ci<-paste0(mean," (",l," to ",u,")") dif_ci<-paste0(dif," (",l," to ",u,")")
pv<-round(tidy(mn)$p.value[-1],dec+1) 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] x1<-ads[,i]
if (is.factor(x1)){ if (is.factor(x1)){
@ -205,7 +210,7 @@ strobe_pred<-function(meas,adj,data,dec=2,n.by.adj=FALSE){
pred<-names(ads)[i] pred<-names(ads)[i]
} }
dfcr<-rbind(dfcr,cbind(pred,mean_ci,pv)) dfcr<-rbind(dfcr,cbind(pred,dif_ci,pv))
} }
## Mutually adjusted ORs ## Mutually adjusted ORs
@ -214,6 +219,7 @@ strobe_pred<-function(meas,adj,data,dec=2,n.by.adj=FALSE){
ma <- lm(m ~ ., data = dat) ma <- lm(m ~ ., data = dat)
miss<-length(ma$na.action) miss<-length(ma$na.action)
actable <- coef(summary(ma)) actable <- coef(summary(ma))
pa <- actable[,4] pa <- actable[,4]
pa<-ifelse(pa<0.001,"<0.001",round(pa,3)) 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] aup<-aci[,2]
amean_ci<-paste0(aco," (",alo," to ",aup,")") amean_ci<-paste0(aco," (",alo," to ",aup,")")
mean_est<-amean_ci[[1]]
nq<-c() 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")) suppressWarnings(re<-left_join(df,dfcr,by="names"))
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),"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(re[,1],re[,2],re[,5],re[,3])
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)","Mutually adjusted difference (95 % CI)")
}
ls<-list(tbl=ref,miss,n.meas,nrow(d)) 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") 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")
} }

View File

@ -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{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{adj}{variables to adjust for, as string.}
\item{data}{dataframe of data.} \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{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{ \description{
Printable table of three dimensional regression analysis of group vs var for meas. By group. Printable table of three dimensional regression analysis of group vs var for meas. By group.

View File

@ -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{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{adj}{variables to adjust for, as string.}
\item{data}{dataframe of data.} \item{data}{dataframe of data.}
\item{dec}{decimals for results, standard is set to 2. Mean and sd is dec-1.} \item{dec}{decimals for results, standard is set to 2. Mean and sd is dec-1.}
\item{groups}{groups to compare, as string.}
} }
\description{ \description{
Printable table of three dimensional regression analysis of group vs var for meas. By var. Includes p-values. Printable table of three dimensional regression analysis of group vs var for meas. By var. Includes p-values.

View File

@ -2,7 +2,7 @@
% Please edit documentation in R/strobe_olr.R % Please edit documentation in R/strobe_olr.R
\name{strobe_olr} \name{strobe_olr}
\alias{strobe_olr} \alias{strobe_olr}
\title{Print regression results according to STROBE} \title{Print ordinal logistic regression results according to STROBE}
\usage{ \usage{
strobe_olr(meas, vars, data, dec = 2) 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.} \item{dec}{decimals for results, standard is set to 2. Mean and sd is dec-1.}
} }
\description{ \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} \keyword{olr}

View File

@ -4,7 +4,8 @@
\alias{strobe_pred} \alias{strobe_pred}
\title{Regression model of predictors according to STROBE, bi- and multivariate.} \title{Regression model of predictors according to STROBE, bi- and multivariate.}
\usage{ \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{ \arguments{
\item{meas}{binary outcome meassure variable, column name in data.frame as a string. Can be numeric or factor. Result is calculated accordingly.} \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{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{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{ \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} \keyword{logistic}