# [R] Non-Linear Regression on a Matrix

Douglas Bates bates at stat.wisc.edu
Wed Nov 17 14:40:51 CET 2004

```apjaworski at mmm.com wrote:
>
>
>
>
> If your "non-linear function (A, B)" is parametric nls should do it for
> you.  If you have R version 2 (perhaps even 1.9) do ?nls to see the help
> page.  Older versions of R require library(nls) first.
>
> Hope this helps,
>
> Andy
>
> __________________________________
> Andy Jaworski
> 518-1-01
> Process Laboratory
> 3M Corporate Research Laboratory
> -----
> E-mail: apjaworski at mmm.com
> Tel:  (651) 733-6092
> Fax:  (651) 736-3122
>
>
>
>              Diana Abdueva
>              <diana.abdueva at gm
>              ail.com>                                                   To
>              Sent by:                  r-help at stat.math.ethz.ch
>              r-help-bounces at st                                          cc
>              at.math.ethz.ch
>                                                                    Subject
>                                        [R] Non-Linear Regression on a
>              11/16/2004 08:33          Matrix
>              PM
>
>
>              Please respond to
>                Diana Abdueva
>              <diana.abdueva at gm
>                  ail.com>
>
>
>
>
>
>
> Hi, I'm terribly sorry for submitting my primitive question, I'm a
> beginner in R and was hoping to get some help re: non-linear fit.
>
> I have a 2D data with the following structure:
>
> A     B        C
> 1      1      111
> 1      2      121
> 1      3      131
> 2      1      141
> 2      2      151
> 2      3      161
> 3      1      171
> 3      2      181
> 3      3      191
>
> I'm trying to fit C = non-linear function (A,B). I was wondering if
> there's a package that would save my time of doing direct least square
> estimation.
>
> Thank you,
> Diana

By "non-linear" do you mean something like a response surface model that
has quadratic terms in A and B and an interaction term?

If so, you can fit the model using the lm function, as in

> rs <- read.table("/tmp/rs.dat", header = TRUE)
> rs
A B   C
1 1 1 111
2 1 2 121
3 1 3 131
4 2 1 141
5 2 2 151
6 2 3 161
7 3 1 171
8 3 2 181
9 3 3 191
> fm <- lm(C ~ A * B + I(A^2) + I(B^2), rs)
> fm

Call:
lm(formula = C ~ A * B + I(A^2) + I(B^2), data = rs)

Coefficients:
(Intercept)            A            B       I(A^2)       I(B^2)
A:B
7.100e+01    3.000e+01    1.000e+01   -1.174e-15    7.217e-16
-4.008e-15

```

More information about the R-help mailing list