data(usair)
# standarized the x's
for (i in 2:7) usair[,i] <- (usair[,i]-mean(usair[,i]))/sd(usair[,i])
# create a matrix
usair$X <-as.matrix(usair[,c("x1","x2", "x3","x4", "x5", "x6")])
m1<- gamlss(y~ridge(X, df=3), data=usair, family=GA)
m2<- gamlss(y~ridge(X, lambda=10), data=usair, family=GA)
# plotting the coeficients as function of the df
df <- seq(0,6,0.5)
resmat<-matrix(0, nrow=length(df), ncol=6)
for (i in 1:length(df))
{
resmat[i,] <- gamlss(y~ridge(X, df=df[i]), data=usair)$mu.coefSmo[[1]][["coef"]]
}
colnames(resmat)<-colnames(usair$X)
plot(1:length(df), type="n", xlim=c(-.5,6.5), ylim=c(-23, 38))
for (i in 1:6)
{
lines(resmat[,i]~df, col="purple")
points(resmat[,i]~df)
}
lines(rep(0,length(df))~df, col="black")
# now estimating the lambda
g1<-gamlss(y~ri(X), data=usair)
m1$mu.coefSmo
Run the code above in your browser using DataLab