Closed proshano closed 3 months ago
I would have expected that, if models are fit on different sample sizes, lrtest() would throw an error, but it does not:
library(rms) set.seed(123) simulate_data <- function(n) { data <- data.frame( x1 = rnorm(n), x2 = rnorm(n), y = rbinom(n, 1, prob = 0.5) ) return(data) } data_small <- simulate_data(100) data_large <- simulate_data(500) model_small <- lrm(y ~ x1 + x2, data = data_small) model_large <- lrm(y ~ x1, data = data_large) tryCatch( { lrtest(model_large, model_small) }, error = function(e) { message("Error: ", e$message) } )
Model 1: y ~ x1 Model 2: y ~ x1 + x2
L.R. Chisq d.f. P 2.3160658 1.0000000 0.1280435
Right, lrtest is not smart about this.
lrtest
I would have expected that, if models are fit on different sample sizes, lrtest() would throw an error, but it does not:
Model 1: y ~ x1 Model 2: y ~ x1 + x2
L.R. Chisq d.f. P 2.3160658 1.0000000 0.1280435