This commit is contained in:
agdamsbo 2018-10-23 14:54:21 +02:00
parent 538b769289
commit 323d8940f6
3 changed files with 16 additions and 6 deletions

View File

@ -1,7 +1,7 @@
Package: daDoctoR
Type: Package
Title: FUNCTIONS FOR HEALTH RESEARCH
Version: 0.1.0.9013
Version: 0.1.0.9014
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

@ -1,21 +1,28 @@
#' Forrest plot from ordinal logistic regression
#'
#' Heavily inspired by https://www.r-bloggers.com/plotting-odds-ratios-aka-a-forrestplot-with-ggplot2/
#' @param x ordinal logistic regression model.
#' @param x input data.
#' @param title plot title
#' @param dec decimals for labels
#' @param lbls labels for variable names. Carefull, as the right order is not checked automatically!
#' @param short flag to half number of ticks on horizontal axis.
#' @param input can be either "model", which is a olr model (polr()), or "df", which is a dataframe whith three columns for OR, lower CI and upper CI-
#' @keywords forestplot
#' @export
#' @examples
#' plot_ord_odds()
plot_ord_odds<-function(x, title = NULL,dec=3,lbls=NULL,short=FALSE){
plot_ord_odds<-function(x, title = NULL,dec=3,lbls=NULL,short=FALSE,input="model"){
require(ggplot2)
odds<-data.frame(cbind(exp(coef(x)), exp(confint(x))))
if (input=="model"){
odds<-data.frame(cbind(exp(coef(x)), exp(confint(x))))
}
if (input=="df"){
odds<-x
}
names(odds)<-c("or", "lo", "up")
rodds<-round(odds,digits = dec)

View File

@ -4,10 +4,11 @@
\alias{plot_ord_odds}
\title{Forrest plot from ordinal logistic regression}
\usage{
plot_ord_odds(x, title = NULL, dec = 3, lbls = NULL, short = FALSE)
plot_ord_odds(x, title = NULL, dec = 3, lbls = NULL, short = FALSE,
input = "model")
}
\arguments{
\item{x}{ordinal logistic regression model.}
\item{x}{input data.}
\item{title}{plot title}
@ -16,6 +17,8 @@ plot_ord_odds(x, title = NULL, dec = 3, lbls = NULL, short = FALSE)
\item{lbls}{labels for variable names. Carefull, as the right order is not checked automatically!}
\item{short}{flag to half number of ticks on horizontal axis.}
\item{input}{can be either "model", which is a olr model (polr()), or "df", which is a dataframe whith three columns for OR, lower CI and upper CI-}
}
\description{
Heavily inspired by https://www.r-bloggers.com/plotting-odds-ratios-aka-a-forrestplot-with-ggplot2/