new quick function, should be revised later!

This commit is contained in:
agdamsbo 2018-10-23 15:29:48 +02:00
parent 323d8940f6
commit 608afe02d8
6 changed files with 53 additions and 4 deletions

View File

@ -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 <agdamsbo@pm.me>
Description: I am a Danish medical doctor involved in neuropsychiatric research.

View File

@ -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)

View File

@ -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

26
R/rep_olr_sngl.R Normal file
View File

@ -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,]))
}

View File

@ -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.}
}

22
man/rep_olr_sngl.Rd Normal file
View File

@ -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}