lmEqn: Get equation from a linear model.

Description Usage Arguments Value Note Author(s) Examples

Description

Given a linear model the function get back the equation and goodness of fit as a string.

Usage

1
lmEqn(m)

Arguments

m

Linear model. It is a linear model to extract the formula, coefficients, and goodness of fit measures.

Value

The output is a character string with the formaula, with coefficients and a summary of the fit.

Note

I took this from internet: http://stackoverflow.com/questions/7549694/ggplot2-adding-regression-line-equation-and-r2-on-graph.

Author(s)

Diego Nieto Lugilde

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function (m) 
{
    l <- list(a = format(coef(m)[1], digits = 2), b = format(abs(coef(m)[2]), 
        digits = 2), r2 = format(summary(m)$r.squared, digits = 3))
    if (coef(m)[2] >= 0) {
        eq <- substitute(italic(y) == a + b %.% italic(x) * "," ~ 
            ~italic(r)^2 ~ "=" ~ r2, l)
    }
    else {
        eq <- substitute(italic(y) == a - b %.% italic(x) * "," ~ 
            ~italic(r)^2 ~ "=" ~ r2, l)
    }
    as.character(as.expression(eq))
  }

dinilu/paleoCLMs-package documentation built on May 15, 2019, 8:46 a.m.