EVOLUTION-MANAGER
Edit File: sigma.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Extract Residual Standard Deviation 'Sigma'</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for sigma {stats}"><tr><td>sigma {stats}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Extract Residual Standard Deviation 'Sigma'</h2> <h3>Description</h3> <p>Extract the estimated standard deviation of the errors, the “residual standard deviation” (misnomed also “residual standard error”, e.g., in <code><a href="summary.lm.html">summary.lm</a>()</code>'s output, from a fitted model). </p> <p>Many classical statistical models have a <em>scale parameter</em>, typically the standard deviation of a zero-mean normal (or Gaussian) random variable which is denoted as <i>σ</i>. <code>sigma(.)</code> extracts the <em>estimated</em> parameter from a fitted model, i.e., <i>sigma^</i>. </p> <h3>Usage</h3> <pre> sigma(object, ...) ## Default S3 method: sigma(object, use.fallback = TRUE, ...) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>object</code></td> <td> <p>an <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> object, typically resulting from a model fitting function such as <code><a href="lm.html">lm</a></code>.</p> </td></tr> <tr valign="top"><td><code>use.fallback</code></td> <td> <p>logical, passed to <code><a href="nobs.html">nobs</a></code>.</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>potentially further arguments passed to and from methods. Passed to <code><a href="deviance.html">deviance</a>(*, ...)</code> for the default method.</p> </td></tr> </table> <h3>Details</h3> <p>The <span class="pkg">stats</span> package provides the S3 generic and a default method. The latter is correct typically for (asymptotically / approximately) generalized gaussian (“least squares”) problems, since it is defined as </p> <pre> sigma.default <- function (object, use.fallback = TRUE, ...) sqrt( deviance(object, ...) / (NN - PP) ) </pre><p> where <code>NN <- <a href="nobs.html">nobs</a>(object, use.fallback = use.fallback)</code> and <code>PP <- sum(!is.na(<a href="coef.html">coef</a>(object)))</code> – where in older <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> versions this was <code>length(coef(object))</code> which is too large in case of undetermined coefficients, e.g., for rank deficient model fits. </p> <h3>Value</h3> <p>typically a number, the estimated standard deviation of the errors (“residual standard deviation”) for Gaussian models, and—less interpretably—the square root of the residual deviance per degree of freedom in more general models. In some generalized linear modelling (<code><a href="glm.html">glm</a></code>) contexts, <i>sigma^2</i> (<code>sigma(.)^2</code>) is called “dispersion (parameter)”. Consequently, for well-fitting binomial or Poisson GLMs, <code>sigma</code> is around 1. </p> <p>Very strictly speaking, <i>σ^</i> (“<i>σ</i> hat”) is actually <i>√(hat(σ^2))</i>. </p> <p>For multivariate linear models (class <code>"mlm"</code>), a <em>vector</em> of sigmas is returned, each corresponding to one column of <i>Y</i>. </p> <h3>Note</h3> <p>The misnomer “Residual standard <b>error</b>” has been part of too many <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> (and S) outputs to be easily changed there. </p> <h3>See Also</h3> <p><code><a href="deviance.html">deviance</a></code>, <code><a href="nobs.html">nobs</a></code>, <code><a href="vcov.html">vcov</a></code>. </p> <h3>Examples</h3> <pre> ## -- lm() ------------------------------ lm1 <- lm(Fertility ~ . , data = swiss) sigma(lm1) # ~= 7.165 = "Residual standard error" printed from summary(lm1) stopifnot(all.equal(sigma(lm1), summary(lm1)$sigma, tol=1e-15)) ## -- nls() ----------------------------- DNase1 <- subset(DNase, Run == 1) fm.DN1 <- nls(density ~ SSlogis(log(conc), Asym, xmid, scal), DNase1) sigma(fm.DN1) # ~= 0.01919 as from summary(..) stopifnot(all.equal(sigma(fm.DN1), summary(fm.DN1)$sigma, tol=1e-15)) ## -- glm() ----------------------------- ## -- a) Binomial -- Example from MASS ldose <- rep(0:5, 2) numdead <- c(1, 4, 9, 13, 18, 20, 0, 2, 6, 10, 12, 16) sex <- factor(rep(c("M", "F"), c(6, 6))) SF <- cbind(numdead, numalive = 20-numdead) sigma(budworm.lg <- glm(SF ~ sex*ldose, family = binomial)) ## -- b) Poisson -- from ?glm : ## Dobson (1990) Page 93: Randomized Controlled Trial : counts <- c(18,17,15,20,10,20,25,13,12) outcome <- gl(3,1,9) treatment <- gl(3,3) sigma(glm.D93 <- glm(counts ~ outcome + treatment, family = poisson())) ## (currently) *differs* from summary(glm.D93)$dispersion # == 1 ## and the *Quasi*poisson's dispersion sigma(glm.qD93 <- update(glm.D93, family = quasipoisson())) sigma (glm.qD93)^2 # 1.282285 is close, but not the same summary(glm.qD93)$dispersion # == 1.2933 ## -- Multivariate lm() "mlm" ----------- utils::example("SSD", echo=FALSE) sigma(mlmfit) # is the same as {but more efficient than} sqrt(diag(estVar(mlmfit))) </pre> <hr /><div style="text-align: center;">[Package <em>stats</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>