[R] please help me
Ben Bolker
bolker at ufl.edu
Sat Oct 20 14:18:50 CEST 2007
azadeh sadeghian wrote:
>
> dear list
> I am student M.S. statistics in department statistics . I am working in
> the function "nls" in the [R 2.3.1] with 246 data and want to fit a model
> to vectors( v and u ) but I have
> a problem to use it
>
>
Thanks for providing a reproducible example. Your version of R is
_really_ old:
you should probably update (or ask you administrator to update) to make sure
that all possible bugs etc. are fixed.
u=c(5.000000e-13,2.179057e+03,6.537171e+03,1.089529e+04,1.525340e+04,
1.91151e+04,2.396963e+04,2.832774e+04,3.268586e+04,3.704397e+04,
4.140209e+04,4.576020e+04,5.011831e+04,5.447643e+04)
v=c(8.382562e-01,4.090868e+02,1.311053e+03,2.124143e+03,3.365494e+03,
2.138903e+03,7.687774e+03,1.028396e+04,1.004186e+04,2.059798e+04,
1.438464e+04,2.861373e+04,2.294919e+04,2.807701e+04)
## always a good idea to look at the data
plot(v~u)
## your code: error
nls(v~c0+.5(a^2)*(u^2),start=list(c0=0,a=.3))
## you need a * between ".5" and "(a^2)"
m2 = nls(v~c0+.5*(a^2)*(u^2),start=list(c0=0,a=.3))
coef(n2)
## you can also fit this (quadratic regression) with lm
m3 = lm(v~I(u^2))
## converting the coefficient
sqrt(2*coef(m3)[2])
## you need to use sensible starting conditions!
## one way to get is to look at the plot and
## take a guess. Another would be to assume
## c0=0 and fit a linear model to log(v) as a function
## of log(u)
nls(v~c0+a*(u^s),start=list(c0=0,a=1,s=2))
--
View this message in context: http://www.nabble.com/please-help-me-tf4657131.html#a13309307
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list