[R] suggestion for example for base:naresid
ripley@stats.ox.ac.uk
ripley at stats.ox.ac.uk
Mon May 20 23:34:26 CEST 2002
On Mon, 20 May 2002, Markus Jantti wrote:
> Dear list:
>
> since it took me a little while to figure out how to make use of naresid, I thought that
> the below R code might be useful as an example on the help page.
It isn't really intended for end users, as the help page effectively says.
It is part of a standard way to write methods for modelling functions, and
people doing so should copy the examples like lm and glm.
It definitely is not intended to be used like this, and any time you find
yourself changing a class do bear in mind that is rarely a good idea.
>
> Regards,
>
> Markus
>
> # generate some data
> x1 <- runif(20)
> y <- 10 + 5*x1 + rnorm(20)
> summary(lm.0 <- lm(y ~ x1))
> # append some NA's to y
> y <- c(y, rep(NA, 5))
> # generate some further x1s
> x1 <- c(x1, runif(5))
> # this fills the residuals vector with NA's to the end
> summary(lm.1 <- lm(y ~ x1, na.action = na.exclude))
> residuals(lm.1) # is equal to
> naresid(na.exclude(lm.1), lm.1$residuals)
> tmp.omit <- lm.1$na.action # modify the na.action to omit
> class(tmp.omit) <- "omit"
> naresid(tmp.omit, lm.1$residuals)
> # same as residuals(lm.0)
> summary(lm.2 <- lm(y ~ x1))
> residuals(lm.2)
> tmp.omit <- lm.2$na.action # modify the na.action to be "exclude"
> class(tmp.omit) <- "exclude"
> naresid(tmp.omit, lm.2$residuals)
>
> --
> Markus Jantti
> markus.jantti at uta.fi ** http://www.abo.fi/~mjantti
> Dept of Economics ** University of Tampere ** FIN 33014 University of Tampere
> PGP public key: http://www.abo.fi/~mjantti/pubring.asc
>
>
>
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272860 (secr)
Oxford OX1 3TG, UK Fax: +44 1865 272595
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list