Description Usage Arguments Value Note Author(s) Examples
Given a linear model the function get back the equation and goodness of fit as a string.
1 | lmEqn(m)
|
m |
Linear model. It is a linear model to extract the formula, coefficients, and goodness of fit measures. |
The output is a character string with the formaula, with coefficients and a summary of the fit.
I took this from internet: http://stackoverflow.com/questions/7549694/ggplot2-adding-regression-line-equation-and-r2-on-graph.
Diego Nieto Lugilde
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))
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.