set.seed(123)
d = data.frame(x = sort(runif(n <- 10 )))
realfun = function(x) 4 + 5*x
d = transform(d, y = realfun(x) + rnorm(n, sd=exp(1)))
# Make the first observation an outlier
d = transform(d, y = c(4*y[1], y[-1]), x=c(-1, x[-1]))
fit = vglm(y ~ x, fam = lqnorm(qpower=1.2), data=d)
coef(fit, matrix=TRUE)
fitted(fit)[1:4,]
fit@misc$qpower
fit@misc$objectiveFunction
# Graphical check
with(d, plot(x, y, main=paste("LS=red, lqnorm=blue (qpower = ",
fit@misc$qpower, "), truth=black", sep=""), col="blue"))
it = lm(y ~ x, data=d)
with(d, lines(x, fitted(fit), col="blue"))
with(d, lines(x, it$fitted, col="red"))
with(d, lines(x, realfun(x), col="black"))
Run the code above in your browser using DataLab