Stepping away from functional programming, identity
is also used in another context in R, namely statistics. Here, it is used to refer to the identity link function in generalized linear models. For more details about this, see ?family
or ?glm
. Here is an example:
> x <- rnorm(100)
> y <- rpois(100, exp(1+x))
> glm(y ~x, family=quasi(link=identity))
Call: glm(formula = y ~ x, family = quasi(link = identity))
Coefficients:
(Intercept) x
4.835 5.842
Degrees of Freedom: 99 Total (i.e. Null); 98 Residual
Null Deviance: 6713
Residual Deviance: 2993 AIC: NA
However, in this case parsing it as a string instead of a function will achieve the same: glm(y ~x, family=quasi(link="identity"))
EDIT: As noted in the comments below, the function base::identity
is not what is used by the link constructor, and it is just used for parsing the link name. (Rather than deleting this answer, I'll leave it to help clarify the difference between the two.)
curve(identity(x))
(rather than the slightly (?) more opaquecurve(x*1)
orcurve(x+0)
... – Exfoliatecurve(x)
? – BarfussError in eval(expr, envir, enclos) : could not find function "x"
) becausecurve
uses funny evaluation rules ... – Exfoliate