I am currently trying to generate nomograms and z-scores for a cardiovascular research project.
However, I have an issue with the gamlss package, in particular with the centiles.pred() function.
For instance, if I run the following code, I get stuck in an error:
library(gamlss)
x <- c(6, 6, 7, 7, 7, 7, 7, 8, 8, 8, 8, 7, 8, 8, 8)
y <- c(372, 375, 340, 370, 386, 396, 398, 357, 360, 360, 362, 415, 365, 366, 368)
data <- data.frame(x, y)
m1 <- gamlss(y~pb(x),sigma.fo=~pb(x), data=data, family=BCT)
centiles(m1, xvar = data$x)
newx <- seq(6, 8, 0.5)
mat <- centiles.pred(m1, xname = "x", xvalues = newx)
When I run the last row, I get the following message:
Error in data.frame(data, source = namelist) :
arguments imply differing number of rows: 5, 6
How can I overcome this error?
The problem is the labeling of the dataframe. I once had a similar error when I used the label table. I change data to data_ and it works. :)
library(gamlss)
x <- c(6, 6, 7, 7, 7, 7, 7, 8, 8, 8, 8, 7, 8, 8, 8)
y <- c(372, 375, 340, 370, 386, 396, 398, 357, 360, 360, 362, 415, 365, 366, 368)
data_ <- data.frame(x, y)
m1 <- gamlss(y~pb(x),sigma.fo=~pb(x), data=data_, family=BCT)
centiles(m1, xvar = data_$x)
newx <- seq(6, 8, 0.5)
mat <- centiles.pred(m1, xname = "x", xvalues = newx)
mat