Dear All
I am quite new to R and would appreciate some help fitting 95% confidence
intervals to a nls function. I have the data
DOY CET
90 5.9
91 8
92 8.4
93 7.7
95 6.6
96 6.8
97 7.1
98 9.7
99 12.3
100 12.8
102 11
103 9.3
104 9.8
105 9.9
107 7.7
110 6.2
111 5.9
112 5.9
113 3.4
114 3.5
116 3.3
117 5.4
118 6.3
119 9.7
120 11.2
121 7.3
124 7.8
etc
I am trying to use some code that has been previously posted on the help
boards but keep getting an error message "dim(X) must have a positive
length"
plot(DOY, CET)
model<-nls(CET~a+(b*sin(((2*pi)/365)*(DOY+t))),start=list(a=9.5, b=-6.5,
t=65))
summary(model)
days<-seq(0,365,1)
predict(model,list(DOY=days))
se.fit <- sqrt(apply(attr(predict(model,list(DOY =
days)),"gradient"),1,
function(x) sum(vcov(fm)*outer(x,x))))
matplot(days, predict(model,list(DOY = days))+
outer(se.fit,qnorm(c(.5, .025,.975))),type="l")
Any help would be greatly appreciated
Best wishes
Tom
--
View this message in context:
http://n4.nabble.com/Confidence-intervals-nls-tp1556487p1556487.html
Sent from the R help mailing list archive at Nabble.com.
On 2010-02-15 12:01, FishR wrote:> > Dear All > > I am quite new to R and would appreciate some help fitting 95% confidence > intervals to a nls function. I have the data > > DOY CET > 90 5.9 > 91 8 > 92 8.4 > 93 7.7 > 95 6.6 > 96 6.8 > 97 7.1 > 98 9.7 > 99 12.3 > 100 12.8 > 102 11 > 103 9.3 > 104 9.8 > 105 9.9 > 107 7.7 > 110 6.2 > 111 5.9 > 112 5.9 > 113 3.4 > 114 3.5 > 116 3.3 > 117 5.4 > 118 6.3 > 119 9.7 > 120 11.2 > 121 7.3 > 124 7.8 > etc > > I am trying to use some code that has been previously posted on the help > boards but keep getting an error message "dim(X) must have a positive > length" > > plot(DOY, CET) > model<-nls(CET~a+(b*sin(((2*pi)/365)*(DOY+t))),start=list(a=9.5, b=-6.5, > t=65)) > summary(model) > days<-seq(0,365,1) > predict(model,list(DOY=days)) > > se.fit<- sqrt(apply(attr(predict(model,list(DOY = days)),"gradient"),1, > function(x) sum(vcov(fm)*outer(x,x)))) > matplot(days, predict(model,list(DOY = days))+ > outer(se.fit,qnorm(c(.5, .025,.975))),type="l") > > Any help would be greatly appreciated > > Best wishes > > Tom >Maybe you just need to change 'fm' to 'model' in function(x) sum(vcov(fm)*outer(x,x)))) ? -Peter Ehlers
Dear Peter Thank you that is an error in the code but unfortunately the problem is still apparent. I think it is related to calculating the gradient Tom -- View this message in context: http://n4.nabble.com/Confidence-intervals-nls-tp1556487p1556585.html Sent from the R help mailing list archive at Nabble.com.