# bring the data and fit the model
data(abdom)
a<-gamlss(y~pb(x),sigma.fo=~pb(x), data=abdom, family=BCT)
#plot the centiles
centiles(a,xvar=abdom$x)
# calculate the centiles at new x values
newx<-seq(12,40,2)
mat <- centiles.pred(a, xname="x", xvalues=newx )
mat
# now plot the centiles
mat <- centiles.pred(a, xname="x",xvalues=newx, plot=TRUE )
# calculate standard-centiles for new x values using the fitted model
newx <- seq(12,40,2)
mat <- centiles.pred(a, xname="x",xvalues=newx, type="standard-centiles" )
mat
# now plot the centiles
mat <- centiles.pred(a, xname="x",xvalues=newx, type="s", plot = TRUE )
# create new y and x values and plot them in the previous plot
newx <- c(20,21.2,23,20.9,24.2,24.1,25)
newy <- c(130,121,123,125,140,145,150)
for(i in 1:7) points(newx[i],newy[i],col="blue")
# now calculate their z-scores
znewx <- centiles.pred(a, xname="x",xvalues=newx,yval=newy, type="z-scores" )
znewx
# now with transformed x-variable within the formula
aa<-gamlss(y~pb(x^0.5),sigma.fo=~pb(x^0.5), data=abdom, family=BCT)
centiles(aa,xvar=abdom$x)
mat <- centiles.pred(aa, xname="x",xvalues=c(30) )
xx<-rep(mat[,1],9)
yy<-mat[,2:10]
points(xx,yy,col="red")
# now with x-variable previously transformed
nx<-abdom$x^0.5
aa<-gamlss(y~pb(nx),sigma.fo=~pb(nx), data=abdom, family=BCT)
centiles(aa, xvar=abdom$x)
newd<-data.frame( abdom, nx=abdom$x^0.5)
mat <- centiles.pred(aa, xname="nx", xvalues=c(30), power=0.5, data=newd)
xxx<-rep(mat[,1],9)
yyy<-mat[,2:10]
points(xxx,yyy,col="red")
Run the code above in your browser using DataLab