mirror of
https://github.com/agdamsbo/daDoctoR.git
synced 2024-11-23 20:30:21 +01:00
Updated print_log function to actually work..
This commit is contained in:
parent
77930fce38
commit
32054658bb
@ -1,6 +1,6 @@
|
|||||||
Package: daDoctoR
|
Package: daDoctoR
|
||||||
Title: Functions For Health Research
|
Title: Functions For Health Research
|
||||||
Version: 0.21.10
|
Version: 0.21.11
|
||||||
Year: 2021
|
Year: 2021
|
||||||
Author: Andreas Gammelgaard Damsbo <agdamsbo@pm.me>
|
Author: Andreas Gammelgaard Damsbo <agdamsbo@pm.me>
|
||||||
Maintainer: Andreas Gammelgaard Damsbo <agdamsbo@pm.me>
|
Maintainer: Andreas Gammelgaard Damsbo <agdamsbo@pm.me>
|
||||||
|
@ -5,12 +5,12 @@
|
|||||||
#' Printable table of two dimensional regression analysis of group vs variable for outcome measure. By group. Includes p-value
|
#' Printable table of two dimensional regression analysis of group vs variable for outcome measure. By group. Includes p-value
|
||||||
#' Group and variable has to be dichotomous factor.
|
#' Group and variable has to be dichotomous factor.
|
||||||
#' @param meas outcome measure variable name in data-data.frame as a string. Can be numeric or factor. Result is calculated accordingly.
|
#' @param meas outcome measure 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. Horisontal.
|
||||||
#' @param group binary group to compare, as string.
|
#' @param group binary stratum to compare, as string. Vertical.
|
||||||
#' @param adj variables to adjust for, as string.
|
#' @param adj variables to adjust for, as string.
|
||||||
#' @param data dataframe to subset from.
|
#' @param data dataframe to subset from.
|
||||||
#' @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.
|
||||||
#' @keywords strobe
|
#' @keywords print stratum
|
||||||
#' @export
|
#' @export
|
||||||
#' @examples
|
#' @examples
|
||||||
#' data('mtcars')
|
#' data('mtcars')
|
||||||
|
@ -10,17 +10,23 @@
|
|||||||
#' @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.
|
||||||
#' @keywords logistic
|
#' @keywords logistic
|
||||||
#' @export
|
#' @export
|
||||||
|
#' @examples
|
||||||
|
#' ##Example with with sample data
|
||||||
|
#' sz=100
|
||||||
|
#' dta<-data.frame(out=factor(sample(c("yes","no"),sz,replace=TRUE)),variable=factor(sample(c("down","up"),sz,replace=TRUE)),sex=factor(sample(c("male","female"),sz,replace=TRUE,prob=c(0.6,0.4))),age=as.numeric(sample(18:80,sz,replace=TRUE)))
|
||||||
|
#' print_log(meas="out",var="variable",adj=c("sex","age"),data=dta,dec=2)
|
||||||
|
|
||||||
|
|
||||||
print_log<-function(meas,var,adj,data,dec=2){
|
print_log<-function(meas,var,adj,data,dec=2){
|
||||||
## Ønskeliste:
|
## Ønskeliste:
|
||||||
##
|
##
|
||||||
## - Sum af alle, der indgår (Overall N)
|
|
||||||
## - Ryd op i kode, der der er overflødig %-regning, alternativt, så fiks at NA'er ikke skal regnes med.
|
## - Ryd op i kode, der der er overflødig %-regning, alternativt, så fiks at NA'er ikke skal regnes med.
|
||||||
##
|
##
|
||||||
|
|
||||||
require(dplyr)
|
require(dplyr)
|
||||||
|
|
||||||
d<-data
|
d<-data
|
||||||
|
|
||||||
m<-d[,c(meas)]
|
m<-d[,c(meas)]
|
||||||
v<-d[,c(var)]
|
v<-d[,c(var)]
|
||||||
|
|
||||||
@ -34,7 +40,7 @@ print_log<-function(meas,var,adj,data,dec=2){
|
|||||||
ma <- glm(m ~ .,family = binomial(), data = dat)
|
ma <- glm(m ~ .,family = binomial(), data = dat)
|
||||||
|
|
||||||
ctable <- coef(summary(mn))
|
ctable <- coef(summary(mn))
|
||||||
pa <- ctable[, 4]
|
pa <- ctable[,4]
|
||||||
pa<-ifelse(pa<0.001,"<0.001",round(pa,3))
|
pa<-ifelse(pa<0.001,"<0.001",round(pa,3))
|
||||||
pa <- ifelse(pa<=0.05|pa=="<0.001",paste0("*",pa),
|
pa <- ifelse(pa<=0.05|pa=="<0.001",paste0("*",pa),
|
||||||
ifelse(pa>0.05&pa<=0.1,paste0(".",pa),pa))
|
ifelse(pa>0.05&pa<=0.1,paste0(".",pa),pa))
|
||||||
@ -42,8 +48,8 @@ print_log<-function(meas,var,adj,data,dec=2){
|
|||||||
|
|
||||||
co<-round(exp(coef(mn)),dec)[-1]
|
co<-round(exp(coef(mn)),dec)[-1]
|
||||||
ci<-round(exp(confint(mn)),dec)[-1,]
|
ci<-round(exp(confint(mn)),dec)[-1,]
|
||||||
lo<-ci[,1]
|
lo<-ci[1]
|
||||||
up<-ci[,2]
|
up<-ci[2]
|
||||||
|
|
||||||
or_ci<-c("REF",paste0(co," (",lo," to ",up,")"))
|
or_ci<-c("REF",paste0(co," (",lo," to ",up,")"))
|
||||||
|
|
||||||
@ -132,10 +138,8 @@ print_log<-function(meas,var,adj,data,dec=2){
|
|||||||
|
|
||||||
ls$adjusted<-data.frame(rbind(header,coll))
|
ls$adjusted<-data.frame(rbind(header,coll))
|
||||||
|
|
||||||
fnames<-c("Variable","N","OR (95 % CI)","p value")
|
names(ls$unadjusted)<-c("Variable",paste0("N (n=",nrow(mn$model),")"),"OR (95 % CI)","p value")
|
||||||
|
names(ls$adjusted)<-c("Variable",paste0("N (n=",nrow(ma$model),")"),"OR (95 % CI)","p value")
|
||||||
names(ls$unadjusted)<-fnames
|
|
||||||
names(ls$adjusted)<-fnames
|
|
||||||
|
|
||||||
return(ls)
|
return(ls)
|
||||||
}
|
}
|
||||||
|
@ -9,9 +9,9 @@ print_diff_bygroup(meas, var, group, adj, data, dec = 2)
|
|||||||
\arguments{
|
\arguments{
|
||||||
\item{meas}{outcome measure variable name in data-data.frame as a string. Can be numeric or factor. Result is calculated accordingly.}
|
\item{meas}{outcome measure variable name in data-data.frame as a string. Can be numeric or factor. Result is calculated accordingly.}
|
||||||
|
|
||||||
\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. Horisontal.}
|
||||||
|
|
||||||
\item{group}{binary group to compare, as string.}
|
\item{group}{binary stratum to compare, as string. Vertical.}
|
||||||
|
|
||||||
\item{adj}{variables to adjust for, as string.}
|
\item{adj}{variables to adjust for, as string.}
|
||||||
|
|
||||||
@ -32,4 +32,5 @@ Group and variable has to be dichotomous factor.
|
|||||||
mtcars$am<-factor(mtcars$am)
|
mtcars$am<-factor(mtcars$am)
|
||||||
print_diff_bygroup(meas="mpg",var="vs",group = "am",adj=c("disp","wt"),data=mtcars)
|
print_diff_bygroup(meas="mpg",var="vs",group = "am",adj=c("disp","wt"),data=mtcars)
|
||||||
}
|
}
|
||||||
\keyword{strobe}
|
\keyword{print}
|
||||||
|
\keyword{stratum}
|
||||||
|
@ -23,4 +23,10 @@ New function ready for revision
|
|||||||
\details{
|
\details{
|
||||||
Printable table of logistic regression analysis. Leaves out other variables from results.
|
Printable table of logistic regression analysis. Leaves out other variables from results.
|
||||||
}
|
}
|
||||||
|
\examples{
|
||||||
|
##Example with with sample data
|
||||||
|
sz=100
|
||||||
|
dta<-data.frame(out=factor(sample(c("yes","no"),sz,replace=TRUE)),variable=factor(sample(c("down","up"),sz,replace=TRUE)),sex=factor(sample(c("male","female"),sz,replace=TRUE,prob=c(0.6,0.4))),age=as.numeric(sample(18:80,sz,replace=TRUE)))
|
||||||
|
print_log(meas="out",var="variable",adj=c("sex","age"),data=dta,dec=2)
|
||||||
|
}
|
||||||
\keyword{logistic}
|
\keyword{logistic}
|
||||||
|
Loading…
Reference in New Issue
Block a user