Having issues creating nomogram in R studio. any help?

Create the nomogram, specifying 'type'

nom <- nomogram(model, fun = function(x)1/(1+exp(-x)),

  •             lp = TRUE, funlabel = "Probability of High VCD",
    
  •             type = "terms") # Explicitly set type to "terms"
    

Error in nomogram(model, fun = function(x) 1/(1 + exp(-x)), lp = TRUE, :
factor name(s) not in the design: type

Hi, welcome to the forum.

I suspect that we need a lot more information about what you are doing. See

FAQ Asking Questions

i am trying to create a nomogram to explain the relationship between the variables in my experiment. The code i am using is do below. Do let me know if there's any additional information i need to provide in order for you to me. thank you

if (!requireNamespace("Hmisc", quietly = TRUE)) {
  install.packages("Hmisc")
}
if (!requireNamespace("rms", quietly = TRUE)) {
  install.packages("rms")
}
library(Hmisc)
library(rms)

set.seed(123) 

data <- data.frame(
  VCD = runif(100, 0, 10), 
  VIB = runif(100, 0, 10),  
  Glucose = runif(100, 0, 10),
  Lactate = runif(100, 0, 10),
  NH4 = runif(100, 0, 10)
)

# Create a datadist object
dd <- datadist(data)
options(datadist = 'dd')

# Linear model without splines
model <- lm(VCD ~ VIB + Glucose + Lactate + NH4, data = data) 

print(summary(model))

# Create the nomogram, specifying 'type'
nom <- nomogram(model, fun = function(x)1/(1+exp(-x)), 
                lp = TRUE, funlabel = "Probability of High VCD",
                type = "terms") # Explicitly set type to "terms"
plot(nom)

Thank you. Everything looks good but just as a matter of formatting, next time can you paste code between

```

```

It makes reading the code much easier.

I am not familiar with {rms} though I have been a fan of {Hmisc} for years.

Anyway I think* you have two issues.

The first is that {rms} has its own form of regression equation ols() rather than the base lm(). It looks like you need to do

model <- ols(VCD ~ VIB + Glucose + Lactate + NH4, data = dat1)

Second, I cannot see where

type = "terms"

comes from. I do not see it in the nomogram function (See ?nomogram)

This appears to work. Note, I changed your data.frame name to "dat1". data is a function name and occasionally using it as a variable name causes problems.

library(Hmisc)
library(rms)

set.seed(123)

dat1 <- data.frame(
VCD = runif(100, 0, 10),
VIB = runif(100, 0, 10),
Glucose = runif(100, 0, 10),
Lactate = runif(100, 0, 10),
NH4 = runif(100, 0, 10)
)

#Create a datadist object
dd <- datadist(dat1)
options(datadist = 'dd')

#Linear model without splines
model <- ols(VCD ~ VIB + Glucose + Lactate + NH4, data = dat1)

# print(summary(model))

# Create the nomogram, specifying 'type'
nom <- nomogram(model, fun = function(x)1/(1+exp(-x)),
lp = TRUE, funlabel = "Probability of High VCD")

plot(nom)