Learn R Programming

cheddar (version 0.1-639)

LinearRegressionByClass: Linear regression by class

Description

Fit linear regressions to node data by class.

Usage

LinearRegressionByClass(community, X, Y, class)

Value

A list of lm objects.

Arguments

community

an object of class Community.

X

Independent variable. A property name that must meet the criteria of the properties parameter of NPS.

Y

Dependent variable. A property name that must meet the criteria of the properties parameter of NPS.

class

The property over which linear regressions are fitted.

Author

Lawrence Hudson

Details

A linear model is fitted through all data points and through each subset of the data given by class. A list of lm objects is returned. The list will contain NULL if it is not possible to fit a linear regression to that class; this will happen for classes that contain just a single node or that contain all or all but one nodes where X and/or Y is NA.

See Also

Community, ApplyByClass, NPS, NvMLinearRegressions, lm

Examples

Run this code
data(TL84)

# Regressions fitted to log10(Biomass) versus log10(M) data.
models <- LinearRegressionByClass(TL84, 'Log10M', 'Log10Biomass', 
                                  'category')

# 'all', 'producer', 'invertebrate', 'vert.ecto'
names(models)

# Extract slopes and intercepts
sapply(models, coef)

Run the code above in your browser using DataLab