From 608afe02d8924c6c267bc408b2a730610d849014 Mon Sep 17 00:00:00 2001 From: agdamsbo Date: Tue, 23 Oct 2018 15:29:48 +0200 Subject: [PATCH] new quick function, should be revised later! --- DESCRIPTION | 2 +- NAMESPACE | 1 + R/rep_olr.R | 2 +- R/rep_olr_sngl.R | 26 ++++++++++++++++++++++++++ man/rep_olr.Rd | 4 ++-- man/rep_olr_sngl.Rd | 22 ++++++++++++++++++++++ 6 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 R/rep_olr_sngl.R create mode 100644 man/rep_olr_sngl.Rd diff --git a/DESCRIPTION b/DESCRIPTION index b04dad9..38c572d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: daDoctoR Type: Package Title: FUNCTIONS FOR HEALTH RESEARCH -Version: 0.1.0.9014 +Version: 0.1.0.9015 Author@R: 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/NAMESPACE b/NAMESPACE index baa11aa..44eff6c 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -16,6 +16,7 @@ export(rep_epi_tests) export(rep_glm) export(rep_lm) export(rep_olr) +export(rep_olr_sngl) export(rep_reg_cie) export(strobe_diff_bygroup) export(strobe_diff_byvar) diff --git a/R/rep_olr.R b/R/rep_olr.R index 6e5cdf6..d129f22 100644 --- a/R/rep_olr.R +++ b/R/rep_olr.R @@ -3,7 +3,7 @@ #' For bivariate analyses. The confint() function is rather slow, causing the whole function to hang when including many predictors and calculating the ORs with CI. #' @param meas Effect meassure. Input as c() of columnnames, use dput(). #' @param vars variables in model. Input as c() of columnnames, use dput(). -#' @param str variables to test. Input as c() of columnnames, use dput(). +#' @param string variables to test. Input as c() of columnnames, use dput(). #' @param ci flag to get results as OR with 95% confidence interval. #' @param dta data frame to pull variables from. #' @keywords olr diff --git a/R/rep_olr_sngl.R b/R/rep_olr_sngl.R new file mode 100644 index 0000000..16500fd --- /dev/null +++ b/R/rep_olr_sngl.R @@ -0,0 +1,26 @@ +#' A repeated ordinal logistic regression function for plotting +#' +#' Should be combined with "rep_olr()". For bivariate analyses. The confint() function is rather slow, causing the whole function to hang when including many predictors and calculating the ORs with CI. +#' @param meas primary outcome (factor with >2 levels). +#' @param vars variables in model. Input as c() of columnnames, use dput(). +#' @param dta data frame to pull variables from. +#' @keywords olr +#' @export +#' @examples +#' rep_olr_sngl() + + +rep_olr_sngl<-function(meas,vars,data){ + require(MASS) + + ad<-vars + d<-data + mat<-matrix(ncol = 3) + for (i in 1:length(ad)){ + d2<-d[,c(meas,ad[i])] + names(d2)[1]<-"meas" + x<-polr(meas~.,data = d2,Hess = TRUE) + mat<-rbind(mat,c(exp(coef(x)), exp(confint(x)))) + } + return(data.frame(mat[-1,])) +} diff --git a/man/rep_olr.Rd b/man/rep_olr.Rd index d3bc54c..ebaa5c7 100644 --- a/man/rep_olr.Rd +++ b/man/rep_olr.Rd @@ -11,9 +11,9 @@ rep_olr(meas, vars, string, ci = FALSE, data) \item{vars}{variables in model. Input as c() of columnnames, use dput().} -\item{ci}{flag to get results as OR with 95% confidence interval.} +\item{string}{variables to test. Input as c() of columnnames, use dput().} -\item{str}{variables to test. Input as c() of columnnames, use dput().} +\item{ci}{flag to get results as OR with 95% confidence interval.} \item{dta}{data frame to pull variables from.} } diff --git a/man/rep_olr_sngl.Rd b/man/rep_olr_sngl.Rd new file mode 100644 index 0000000..1b8f4ee --- /dev/null +++ b/man/rep_olr_sngl.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/rep_olr_sngl.R +\name{rep_olr_sngl} +\alias{rep_olr_sngl} +\title{A repeated ordinal logistic regression function for plotting} +\usage{ +rep_olr_sngl(meas, vars, data) +} +\arguments{ +\item{meas}{primary outcome (factor with >2 levels).} + +\item{vars}{variables in model. Input as c() of columnnames, use dput().} + +\item{dta}{data frame to pull variables from.} +} +\description{ +Should be combined with "rep_olr()". For bivariate analyses. The confint() function is rather slow, causing the whole function to hang when including many predictors and calculating the ORs with CI. +} +\examples{ +rep_olr_sngl() +} +\keyword{olr}