[R] plot multivariate function with known coefficient.
Gavin Simpson
gavin.simpson at ucl.ac.uk
Wed Dec 10 12:35:28 CET 2008
On Tue, 2008-12-09 at 16:07 -0800, YIHSU CHEN wrote:
> Dear R users --
>
> I have a simple question that I cannot find the answers in the archive
> email: how to plot a multivariate function if I know the coefficients
> already? For instance, if I like to plot a 3D fig of Pi against X and
> Y with the function Pi = a0 + a1X + a2Y, where a0, a1 & a2 are known.
> Can "curve" do this? So far, I have only seen univariate case.
Not sure about a "curve3D()" but you can do this yourself using
expand.grid (to give combinations of X and Y you wish to evaluate Pi at)
and then use the vectorised nature of R to compute Pi for the
combinations given known coefficients.
E.g.:
X <- seq(1, 100, by = 5)
Y <- seq(1, 100, by = 5)
XY <- expand.grid(X = X, Y = Y)
a0 <- 2
a1 <- 0.5
a2 <- -0.3
Pi <- with(XY, a0 + (a1 * X) + (a2 * Y))
Pi <- matrix(Pi, ncol = length(X), byrow = TRUE)
persp(X, Y, Pi)
HTH
G
>
> Thank you.
>
> Yihsu Chen
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
--
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
Dr. Gavin Simpson [t] +44 (0)20 7679 0522
ECRC, UCL Geography, [f] +44 (0)20 7679 0565
Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk
Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/
UK. WC1E 6BT. [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20081210/ff554eac/attachment.bin>
More information about the R-help
mailing list