From d81061c335e5f18d2573100381f7b71f34a510f5 Mon Sep 17 00:00:00 2001 From: Manny Gimond Date: Tue, 23 Jul 2024 16:04:17 -0400 Subject: [PATCH] modified printed output to reflect poly order --- R/eda_lm.R | 19 +++++++++++++------ docs/reference/eda_lm.html | 5 +++-- man/eda_lm.Rd | 5 +++-- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/R/eda_lm.R b/R/eda_lm.R index ee3291d..72842ef 100755 --- a/R/eda_lm.R +++ b/R/eda_lm.R @@ -89,12 +89,13 @@ #' line to the data. \code{rlm} arguments can be passed as a list via the #' \code{rlm.d} argument. #' -#' @return Returns residuals, intercept and slope from an OLS fit. +#' @return Returns residuals, intercept and coefficient(s) from an OLS +#' fit if \code{reg = TRUE}. Returns \code{NULL} otherwise. #' #' \itemize{ #' \item \code{residuals}: Regression model residuals #' \item \code{a}: Intercept -#' \item \code{b}: Slope} +#' \item \code{b}: Polynomial coefficient(s)} #' #' @seealso \code{\link[graphics]{plot}} and \code{\link[stats]{loess.smooth}} #' functions @@ -279,8 +280,14 @@ eda_lm <- function(dat, x, y, xlab = NULL, ylab = NULL, px = 1, py = 1, # Reset plot parameters par(.pardef) - out_coef <- coef(M) - names(out_coef) <- c("int", paste0(xlab, "^", 1:poly)) - print(out_coef) - invisible(list(residuals = residuals(M), a = coef(M)[1], b = coef(M)[2])) + + # Output residuals and coefficients if regression is set to TRUE + if(reg == TRUE) { + out_coef <- coef(M) + names(out_coef) <- c("int", paste0(xlab, "^", 1:poly)) + print(out_coef) + invisible(list(residuals = residuals(M), a = out_coef[1], b = out_coef[-1])) + } else { + print(NULL) + } } diff --git a/docs/reference/eda_lm.html b/docs/reference/eda_lm.html index b974aa2..cd6a546 100755 --- a/docs/reference/eda_lm.html +++ b/docs/reference/eda_lm.html @@ -259,12 +259,13 @@

ArgumentsValue

-

Returns residuals, intercept and slope from an OLS fit.

+

Returns residuals, intercept and coefficient(s) from an OLS + fit if reg = TRUE. Returns NULL otherwise.

Details

diff --git a/man/eda_lm.Rd b/man/eda_lm.Rd index 447dd5e..5e30ae6 100755 --- a/man/eda_lm.Rd +++ b/man/eda_lm.Rd @@ -123,12 +123,13 @@ function.} \item{...}{Not used.} } \value{ -Returns residuals, intercept and slope from an OLS fit. +Returns residuals, intercept and coefficient(s) from an OLS + fit if \code{reg = TRUE}. Returns \code{NULL} otherwise. \itemize{ \item \code{residuals}: Regression model residuals \item \code{a}: Intercept - \item \code{b}: Slope} + \item \code{b}: Polynomial coefficient(s)} } \description{ \code{eda_lm} generates a scatter plot with a fitted regression