[R] Non-Linear Regression Help

Zachary Shadomy shadomyzd at appstate.edu
Fri May 5 00:58:15 CEST 2017

I am having some errors come up in my first section of code. I have no
issue in plotting the points. Is there an easier method for creating a
non-linear regression using C*(x+a)^n. The .txt file is named
stage_discharge with the two variables being stage and discharge.
The data is a relatively small file listed below:

stage discharge
6.53 2592.05
6.32 559.5782
5.96 484.2151
4.99 494.7527
3.66 456.0778
0.51 291.13

> power.nls<-nls(stage_dischargee$discharge~C*(stage_discharge$stage+a)^n,
data=stage_discharge, start=list(C=4, a=0, n=1))
> C<-coef(power.nls)["C"]
> a<-coef(power.nls)["a"]
> n<-coef(power.nls)["n"]
> plot(stage_discharge$stage, stage_discharge$discharge, pch=17, cex=1.25,
ylab='Discharge (cfs )', xlab='Stage (ft)', font.lab=2, main='Boone Creek\n
St age-Discharge Curve')
> curve(C*(x+a)^n, add=TRUE, col="red")

	[[alternative HTML version deleted]]

More information about the R-help mailing list