Updated counting and added flag

This commit is contained in:
agdamsbo 2018-10-12 11:26:20 +02:00
parent 52f60b448b
commit fa76288a0a
3 changed files with 55 additions and 27 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.9008 Version: 0.1.0.9009
Author@R: c(person("Andreas", "Gammelgaard Damsbo", email = "agdamsbo@pm.me", role = c("cre", "aut"))) Author@R: 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

@ -5,12 +5,13 @@
#' @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.
#' @keywords logistic #' @keywords logistic
#' @export #' @export
#' @examples #' @examples
#' strobe_pred() #' strobe_pred()
strobe_pred<-function(meas,adj,data,dec=2){ strobe_pred<-function(meas,adj,data,dec=2,n.by.adj=FALSE){
## Ønskeliste: ## Ønskeliste:
## ##
## - Sum af alle, der indgår (Overall N) ## - Sum af alle, der indgår (Overall N)
@ -58,7 +59,7 @@ strobe_pred<-function(meas,adj,data,dec=2){
dat<-data.frame(m=m,ads) dat<-data.frame(m=m,ads)
ma <- glm(m ~ .,family = binomial(), data = dat) ma <- glm(m ~ .,family = binomial(), data = dat)
miss<-length(ma$na.action)
actable <- coef(summary(ma)) actable <- coef(summary(ma))
pa <- actable[,4] pa <- actable[,4]
@ -74,32 +75,54 @@ strobe_pred<-function(meas,adj,data,dec=2){
aup<-aci[,2] aup<-aci[,2]
aor_ci<-paste0(aco," (",alo," to ",aup,")") aor_ci<-paste0(aco," (",alo," to ",aup,")")
dat2<-dat[,-1]
# names(dat2)<-c(var,names(ads)) # names(dat2)<-c(var,names(ads))
nq<-c() nq<-c()
for (i in 1:ncol(dat2)){ if (n.by.adj==TRUE){
if (is.factor(dat2[,i])){ dat2<-ma$model[,-1]
vec<-dat2[,i] for (i in 1:ncol(dat2)){
ns<-names(dat2)[i] if (is.factor(dat2[,i])){
for (r in 1:length(levels(vec))){ vec<-dat2[,i]
vr<-levels(vec)[r] ns<-names(dat2)[i]
dr<-vec[vec==vr&!is.na(vec)] for (r in 1:length(levels(vec))){
n<-as.numeric(length(dr)) vr<-levels(vec)[r]
nall<-as.numeric(nrow(dat[!is.na(dat2[,c(ns)]),])) n<-as.numeric(length(vec[vec==vr&!is.na(vec)]))
nl<-paste0(ns,levels(vec)[r]) nall<-as.numeric(length(dat2[,c(ns)]))
pro<-round(n/nall*100,0) nl<-paste0(ns,levels(vec)[r])
rt<-paste0(n," (",pro,"%)") pro<-round(n/nall*100,0)
rt<-paste0(n," (",pro,"%)")
nq<-rbind(nq,cbind(nl,rt))
}}
if (!is.factor(dat2[,i])){
num<-dat2[,i]
nl<-names(dat2)[i]
rt<-as.numeric(length(dat2[,c(nl)]))
nq<-rbind(nq,cbind(nl,rt)) nq<-rbind(nq,cbind(nl,rt))
} }}}
}
if (!is.factor(dat2[,i])){ else {
num<-dat2[,i] dat2<-dat[,-1]
nl<-names(dat2)[i] for (i in 1:ncol(dat2)){
rt<-as.numeric(nrow(dat[!is.na(dat2[,c(nl)]),])) if (is.factor(dat2[,i])){
nq<-rbind(nq,cbind(nl,rt)) vec<-dat2[,i]
} ns<-names(dat2)[i]
} for (r in 1:length(levels(vec))){
vr<-levels(vec)[r]
n<-as.numeric(length(vec[vec==vr&!is.na(vec)]))
nall<-as.numeric(length(dat[,c(ns)]))
nl<-paste0(ns,levels(vec)[r])
pro<-round(n/nall*100,0)
rt<-paste0(n," (",pro,"%)")
nq<-rbind(nq,cbind(nl,rt))
}}
if (!is.factor(dat2[,i])){
num<-dat2[,i]
nl<-names(dat2)[i]
rt<-as.numeric(length(dat[,c(nl)]))
nq<-rbind(nq,cbind(nl,rt))
}}}
rnames<-c() rnames<-c()
@ -132,5 +155,8 @@ strobe_pred<-function(meas,adj,data,dec=2){
names(ref)<-c("Variable","N","Crude OR (95 % CI)","Mutually adjusted OR (95 % CI)") names(ref)<-c("Variable","N","Crude OR (95 % CI)","Mutually adjusted OR (95 % CI)")
return(ref) ls<-list(tbl=ref,miss)
names(ls)<-c("Printable table","Deleted due to missingness")
return(ls)
} }

View File

@ -4,7 +4,7 @@
\alias{strobe_pred} \alias{strobe_pred}
\title{Logistic regression of predictors according to STROBE} \title{Logistic regression of predictors according to STROBE}
\usage{ \usage{
strobe_pred(meas, adj, data, dec = 2) strobe_pred(meas, adj, data, dec = 2, n.by.adj = 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.}
@ -14,6 +14,8 @@ strobe_pred(meas, adj, data, dec = 2)
\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{n.by.adj}{flag to indicate wether to count number of patients in adjusted model or overall.}
} }
\description{ \description{
Printable table of logistic regression analysis according to STROBE. Printable table of logistic regression analysis according to STROBE.