[R] nls problem

Troels Ring tr|ng @end|ng |rom gvdnet@dk
Thu Apr 2 13:07:51 CEST 2020


Dear friends - I'm on Win10 with R 6.3.1 and have a very simple problem with
nls which apparently gives a decent fit to the parable below, even without
starting values. But when I then think I know the meaning of the three
parameters a, b, and d it goes very wrong. I guess I am again overlooking
something easy but cannot spot it.

BW
Troels Ring,

Aalborg, Denmark

 

 

aedf <- structure(list(Flux = c(-0.141256, -0.154709, -0.215247, -0.302691, 

            -0.32287, -0.511211, -0.605381, -0.813901, -1.11659, -1.76906

), pH = c(7.06273, 7.11182, 7.16182, 7.18818, 7.21455, 7.23818, 

          7.26273, 7.28455, 7.31182, 7.34364)), class = "data.frame",
row.names = c(NA, 

 
-10L))

m <- with(aedf,nls(Flux~a + b*pH + d*pH^2))

 

with(aedf,plot(pH,Flux))

with(aedf,lines(pH,fitted(m),lty=1,col="red",lwd=3))

 

m

# a        b        d 

# -1630.70   457.67   -32.11 

 

fitted(m)

# 1] -0.22087053 -0.09989926 -0.13579690 -0.21936385 -0.34761742 -0.50048799

# [7] -0.69729602 -0.90471194 -1.20692552 -1.61994657

 

FPG <- function(pH) -1630.70 + 457.67*pH -32.11*pH^2

 

FPG(aedf$pH)

# [1] -0.016359649  0.107602395  0.074773375 -0.007166685 -0.133786467

# [6] -0.285187665 -0.480463769 -0.686513537 -0.987013685 -1.398026917

 

# So why aren't fitted(m) and FPG(aedf$pH) not closer ("equal")?

 


This email has been scanned by BullGuard antivirus protection.
For more info visit www.bullguard.com
<http://www.bullguard.com/tracking.aspx?affiliate=bullguard&buyaffiliate=smt
p&url=/> 

	[[alternative HTML version deleted]]



More information about the R-help mailing list