Can u please tell me if there's a major mistake in the code?
allvals.x=array(t(cdf.all[1]))
allvals.y=array(t(cdf.all[2]))
library(MASS)
bestval.exp.nls=bestval.exp.fit=-1
plot(allvals.x, allvals.y)
random=sort(sample(1:length(allvals.x), 15)) somevals.x=allvals.x[c(random)] somevals.y=allvals.y[c(random)]}
#fit with nls and fitdistr
fit.exp = fitdistr(somevals.y, "exponential") nls.exp <- nls(somevals.y ~ pexp(somevals.x, rate), start=list(rate=. 0001), model=TRUE)
#plot what you get out of the two fits
lines(allvals.x, pexp(allvals.x, coef(fit.exp)), col=it) lines(allvals.x, pexp(allvals.x, coef(nls.exp)), col=it)
#perform kolmogorov-smirnov test on your fit
ks.exp.nls = ks.test(somevals.y, "pexp", coef(nls.exp)) ks.exp.fit = ks.test(somevals.y, "pexp", coef(fit.exp)) bestval.exp.fit = max(bestval.exp.fit, ks.exp.fit$p.value) bestval.exp.nls = max(bestval.exp.nls, ks.exp.nls$p.value)
print(bestval.exp.fit)
print(bestval.exp.nls)
----------END OF
CODE-------------------------------------------------------------------- ______________________________________________R-help@stat.math.ethz.ch mailing list
Archive maintained by Robert King, hosted by
the discipline of
statistics at the
University of Newcastle,
Australia.
Archive generated by hypermail 2.1.8, at Sun 24 Sep 2006 - 07:30:06 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.