ERROR: model.frame.default : invalid type(NULL)

I am working on an underwriting regression model and this error pops up saying that the variable created 'test[protected]' is Null

predictorlist = list("BLACK","HISPANIC","API","FEMALE")
predictorlist = list("BLACK","HISPANIC","API","FEMALE","lowmod","minority","majblhs")

for (i in predictorlist) {

control <- "MALE"
if (protected=="AGE62") {
control <- "AGEL62"

control <- "notlowmod"

control <- "notminority"
control <- "notmajblhs"

myttest <-print(t.test(as.formula(paste("test[[depvar]]", "test[[protected]]", sep = "~"))) )

Original error message: Error in model.frame.default(formula = as.formula(paste("test[[depvar]]", :
invalid type (NULL) for variable 'test[[protected]]'

I think it may have something to do with "lowmod" and "notlowmod"

This file uses a previous Rda and the numbers don't look unusual so I am curious if it is in original code or if I need to examine original data file

Also, first time posting so apologize for any confusion

Hi, this is hard to tell without the test object. The way to fix this is with a reprex. See the FAQ. That way, everyone interested in helping can see what you are seeing. Here's what one looks like using a simulated dataset and taking a functional programming approach.

# f(x) = y
# step 1: create fake_data
# x: col 1:7 are loanfile data
# y: col 8:12 are control flags to be set
var_num <- 12
fake_rows <- 90
input <- sample(c(TRUE,FALSE),var_num * fake_rows, 
                replace = TRUE)
m <- matrix(input, nrow = fake_rows, ncol = var_num)
col_header <- c("BLACK","HISPANIC","API","FEMALE",
                "c_gender", "c_lowmod", "c_elder","c_majblhs")
colnames(m) <- col_header
# control flags intitially set FALSE
m[,8:12] <- FALSE
before = head(m)

# step 2: f to set control flags

m[which(rowSums(m[,1:3]) > 0),8] <- TRUE
m[which(m[,4]),9] <- TRUE
m[which(m[,5]),10] <- TRUE
m[which(m[,6]),11] <- TRUE
m[which(m[,7]),12] <- TRUE
after <- head(m)

# show example of which control flags were changed
# from FALSE to TRUE
(before == after)[,8:12]
#>      c_minority c_gender c_lowmod c_elder c_majblhs
#> [1,]      FALSE    FALSE    FALSE    TRUE     FALSE
#> [2,]      FALSE    FALSE    FALSE   FALSE     FALSE
#> [3,]      FALSE     TRUE    FALSE    TRUE      TRUE
#> [4,]      FALSE    FALSE     TRUE    TRUE      TRUE
#> [5,]       TRUE     TRUE    FALSE   FALSE     FALSE
#> [6,]       TRUE    FALSE     TRUE   FALSE     FALSE

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.