set.seed(123)
d = data.frame(x = sort(runif(n <- 100)))
realfun = function(x) 4 + 5*x
d = transform(d, y = realfun(x) + rnorm(n, sd=exp(1)))
d$y[1] = 4 * d$y[1] # Outlier
d$x[1] = -1 # Outlier
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