[R] Robust nonlinear regression - better example

cstrato cstrato at aon.at
Mon Feb 2 23:17:33 CET 2004


Dear all

Here is a hopefully better example with regards to
nonlinear robust fitting:

# fitting a polynomial:
x <- seq(-10,10,0.2)
y <- 10*x + 4*x*x - 2*x*x*x
plot(x,y)
z <- jitter(y,amount=300)
plot(x,z)
df <- as.data.frame(cbind(x,z))
nf <- nls(z ~ a*x + b*x*x + c*x*x*x, data=df,
+           start=list(a=4,b=2,c=1), trace = TRUE)
127697531 :  4 2 1
2974480 :  10.972123  3.793426 -1.942278

# introducing outliers before fitting the  polynomial:
z1 <- z
z1[c(16,22,23,34,36,42,67,69,72,76)] <-
+ c(2000,1900,2000,1900,1600,1600,500,-2000,-1700,-1800)
plot(x,z1)
df1 <- as.data.frame(cbind(x,z1))
nf1 <- nls(z1 ~ a*x + b*x*x + c*x*x*x, data=df1,
+           start=list(a=4,b=2,c=1), trace = TRUE)
159359174 :  4 2 1
24098548 :  -59.053288   4.169518  -1.072027

# plotting the results:
y1 <- 10.97*x + 3.79*x*x - 1.94*x*x*x
y2 <- -59.05*x + 4.17*x*x - 1.07*x*x*x
oldpar <- par(pty="s",mfrow=c(2,2),mar=c(5,5,4,1))
plot(x,y)
plot(x,z1)
plot(x,y1)
plot(x,y2)
par(oldpar)

In my opinion this fit could hardly be considered
to be robust.

Are there functions in R which can do robust fitting?
(Sorrowly, at the moment I could not test the package
nlrq mentioned by Roger Koenker)

Best regards
Christian
_._._._._._._._._._._._._._._._
C.h.i.s.t.i.a.n S.t.r.a.t.o.w.a
V.i.e.n.n.a       A.u.s.t.r.i.a
_._._._._._._._._._._._._._._._




More information about the R-help mailing list