[R] Interactions in a nls model
Anthony Lawrence Nguy-Robertson
anthony.robertson at huskers.unl.edu
Wed Feb 9 02:35:48 CET 2011
Bert,
Thanks for the input. I was hoping for an easy answer, but as life is,
there usually isn't one. I will find a statistician here on campus that
might be able to help. Just so you know, the data is remote sensing data
that is an average of 9 measurements on one day. However, the data set
is taken from 3 different fields over a period of 8 years. I found that
a non-linear fit is better than a linear or 2nd order polynomial.
However, my conundrum is that I want to tell if the fit using just corn
is different from the fit using just soybean. Again, thanks for your help.
Tony
On 2/8/2011 5:15 PM, Bert Gunter wrote:
> Nonlinear models are an entirely different kettle of fish then linear
> models. You need to specify exactly how the different crops affect the
> parameters in your growth model. I suggest you consult a local
> statistician for help (this is not an R question).
>
> Incidentally, depending on the nature of your data -- does it consist
> of repeated measures of individual plants, for example? -- you may
> need nlme or nlmer (or other special packages) to fit the data and do
> inference -- nls makes independence assumptions that aren't
> appropriate for such data. Your local statistician can help here, too,
> if needed. But be warned, inference is inherently difficult in such
> situations.
>
>
> -- Bert
>
> On Tue, Feb 8, 2011 at 1:12 PM, Anthony Lawrence Nguy-Robertson
> <anthony.robertson at huskers.unl.edu> wrote:
>
>> I am interested in testing two similar nls models to determine if the lines
>> are statistically different when fitted with two different data sets; one
>> corn, another soybean. I know I can do this in linear models by testing for
>> interactions. See Introductory Statistics with R by Dallgaard p212-218 for
>> an example. I have two different data sets I am comparing to lai. ci.re
>> should have very little difference between corn and soybean, while ci.gr,
>> there should be a difference. If I use the simplistic form described in
>> Dallgaard (see example in code below) it does not work correctly. What do I
>> need to do to test for this interaction? Thank you!
>>
>> My data is located here: ftp://snrftp.unl.edu/Outgoing/example/
>>
>> Here is my example code:
>>
>> ###load data###
>> data<- read.csv("example.csv", header=TRUE)
>> eq<- function(x,a,b,c) {a+b*exp(x^c)}
>>
>> ##create non-linear models##
>> nls.ci.re<- nls(lai~eq(ci.re,a,b,c),data=data, start=c(a=1,b=1,c=1))
>> nls.ci.gr<- nls(lai~eq(ci.gr,a,b,c),data=data, start=c(a=1,b=1,c=1))
>>
>> #create non-linear models for corn#
>> nls.ci.re.corn<- nls(lai~eq(ci.re,a,b,c),data=subset(data,crop=="corn"),
>> start=c(a=1,b=1,c=1))
>> nls.ci.gr.corn<- nls(lai~eq(ci.gr,a,b,c),data=subset(data,crop=="corn"),
>> start=c(a=1,b=1,c=1))
>>
>> #create non-linear models for soybean#
>> nls.ci.re.soybean<-
>> nls(lai~eq(ci.re,a,b,c),data=subset(data,crop=="soybean"),
>> start=c(a=1,b=1,c=1))
>> nls.ci.gr.soybean<-
>> nls(lai~eq(ci.gr,a,b,c),data=subset(data,crop=="soybean"),
>> start=c(a=1,b=1,c=1))
>>
>> #test interactions according to Introductory Statistics with R by Dalgaard
>> p. 213#
>> corn.soybean.interactions.ci.re.a<-
>> abs((summary(nls.ci.re.corn)$coeff[1,1]-
>> summary(nls.ci.re.soybean)$coeff[1,1])/
>> sqrt(summary(nls.ci.re.corn)$coeff[1,2]^2+
>> summary(nls.ci.re.soybean)$coeff[1,2]^2))
>>
>> corn.soybean.interactions.ci.gr.a<-
>> abs((summary(nls.ci.gr.corn)$coeff[1,1]-
>> summary(nls.ci.gr.soybean)$coeff[1,1])/
>> sqrt(summary(nls.ci.gr.corn)$coeff[1,2]^2+
>> summary(nls.ci.gr.soybean)$coeff[1,2]^2))
>>
>> corn.soybean.interactions.ci.re.a.p.value<-
>> pt(corn.soybean.interactions.ci.re.a,df=summary(nls.ci.re.corn)$df[2],lower.tail=FALSE)
>> corn.soybean.interactions.ci.gr.a.p.value<-
>> pt(corn.soybean.interactions.ci.gr.a,df=summary(nls.ci.gr.corn)$df[2],lower.tail=FALSE)
>>
>> ______________________________________________
>> 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.
>>
>>
>
>
>
--
Anthony L. Nguy-Robertson
Doctoral Student
University of Nebraska-Lincoln
School of Natural Resources
Center for Advanced Land Management Information Technologies (CALMIT)
223 Hardin Hall
3310 Holdrege Street
Lincoln, NE 68583
Office: 402-472-2565
Fax: 402-472-2946
Email: anguy-robertson at unlnotes.unl.edu
More information about the R-help
mailing list