Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

rSquared

Extract the coefficient of determination from a linear model object.


Description

Extracts the coefficient of determination (i.e., “r-squared”) from a linear model (i.e., lm) object.

Usage

rSquared(object, ...)

## Default S3 method:
rSquared(object, ...)

## S3 method for class 'lm'
rSquared(object, digits = getOption("digits"), percent = FALSE, ...)

Arguments

object

An object saved from lm.

...

Additional arguments for methods.

digits

A single number that is the number of digits to round the returned result to.

percent

A logical that indicates if the result should be returned as a percentage (=TRUE) or as a proportion (=FALSE; default).

Details

This is a convenience function to extract the r.squared part from summary(lm).

Value

A numeric, as either a proportion or percentage, that is the coefficient of determination for a linear model.

Examples

lm1 <- lm(mirex~weight, data=Mirex)
rSquared(lm1)
rSquared(lm1,digits=3)
rSquared(lm1,digits=1,percent=TRUE)

## rSquared only works with lm objects
## Not run: 
nls1 <- nls(mirex~a*weight^b,data=Mirex,start=list(a=1,b=1))
rSquared(nls1)

## End(Not run)

FSA

Simple Fisheries Stock Assessment Methods

v0.8.32
GPL (>= 2)
Authors
Derek Ogle [aut, cre] (<https://orcid.org/0000-0002-0370-9299>), Powell Wheeler [aut], Alexis Dinno [aut] (Provided base functionality of dunnTest())
Initial release
2021-1-15

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.