[R] how to draw a multivariate function
ggrothendieck at myway.com
Sun Oct 17 08:19:42 CEST 2004
Sun <sun <at> cae.wisc.edu> writes:
> 3. Where can I get resources of R? The help file seems not very helpful to
> me. For example, the lm () function, its weighted least square option does
> not say clearly the weight = standard deviation. It said it is to minimize
> sum w*error^2, which mislead us to think it takes variance. I have to ask
> experienced people. And everytime the answer depends on luck.
1. There are quite a few pointers under Documentation in the left hand
pane of the R web site at www.r-project.org .
2. If you have something specific like weighted regression you can
try the Search link at that same site or just use google, e.g. try
these search words and you will find some examples of using lm with
r-help weight lm
3. Sometimes its easiest to check your understanding by just plugging
in some variables for which you know the answer and see what it does.
R> y <- rnorm(10)
R> w <- runif(10)
R> # Run 1
R> coef(lm(w*y ~ w+0)) # +0 means no intercept
R> # Run 2
R> coef(lm(y~1,weight=w^2)) # ~1 means regression against intercept
R> # Run 3
The first two runs give the same answer so it seems the help
page was correect because the first run finds the b that
minimizes sum((w*y - b*w)^2) and we can factor the w out to give
= sum(w^2 * (y-b)^2) which corresponds to Run 2, not Run 3.
More information about the R-help