[R] easy way to do a 2-D fit to an array of data?

From: Carl Witthoft <carl_at_witthoft.com>
Date: Mon, 02 May 2011 19:14:00 -0400

I've got a matrix, Z, of values representing (as it happens) optical power at each pixel location. Since I know in advance I've got a single, convex peak, I would like to do a 2D parabolic fit of the form Z = poly((x+y),2) where x and y are the x,y coordinates of each pixel (or equivalently, the row, column numbers). Is there an R function that lets me easily implement that? I've started down the path of something like

zvec <- as.vector(Z), and creating applicable x,y vectors by something like (where for the sake of argument Z is 128x128)


xvec <- as.vector(foo)
yvec <- as.vector(t(foo))

at which point I can feed zvec, xvec, yvec to lm() .

I'm hopeful someone can point me to a much easier way to do the same thing. Oh, and if there's a 2-D splinefunction generator, that would work for me as well.


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. Received on Thu 05 May 2011 - 06:25:05 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 05 May 2011 - 07:00:05 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive