Reputation: 25
I checked out multiple questions on the topic. They are specific, or not applicable to this case. It feels like there is something obvious I am overlooking. Tried removing the first few columns from dataframe as the error said variable "1". Here is my data:
fixed <- structure(list(fail = structure(c(1L, 1L, 1L, 1L, 1L, 1L), .Label = c("0",
"1"), class = "factor"), age30 = c(0L, 0L, 0L, 0L, 0L, 1L), age65 = c(0L,
0L, 0L, 1L, 0L, 0L), age66 = c(0L, 0L, 0L, 0L, 0L, 0L), dage10 = c(0L,
0L, 0L, 0L, 0L, 0L), dage15 = c(0L, 0L, 0L, 0L, 0L, 0L), dage20 = c(0L,
0L, 0L, 0L, 0L, 0L), dage30 = c(1L, 0L, 0L, 0L, 0L, 0L), dage55 = c(0L,
0L, 0L, 1L, 0L, 0L), dage60 = c(0L, 0L, 0L, 0L, 0L, 0L), dage70 = c(0L,
1L, 0L, 0L, 0L, 0L), dage71 = c(0L, 0L, 0L, 0L, 0L, 0L), alb25_recip = c(0L,
0L, 0L, 1L, 0L, 1L), alb20_recip = c(0L, 0L, 0L, 0L, 0L, 0L),
alb15_recip = c(0L, 0L, 0L, 0L, 0L, 0L), ascites = c(1L,
0L, 1L, 1L, 0L, 1L), bmi30 = c(0L, 0L, 0L, 1L, 1L, 0L), bmi35 = c(0L,
0L, 0L, 0L, 0L, 0L), bmi40 = c(0L, 0L, 0L, 0L, 0L, 0L), cit6 = c(0L,
0L, 1L, 0L, 0L, 0L), cit14 = c(0L, 0L, 0L, 0L, 0L, 0L), cit15 = c(0L,
0L, 0L, 0L, 0L, 0L), dcd = c(0L, 0L, 0L, 0L, 0L, 0L), cr15 = c(0L,
0L, 0L, 0L, 0L, 0L), cr20 = c(1L, 0L, 1L, 0L, 0L, 0L), hcv_mv = c(1L,
0L, 0L, 1L, 0L, 0L), hd = c(0L, 0L, 0L, 0L, 0L, 0L), distance500 = c(0L,
0L, 0L, 0L, 0L, 0L), distance1000 = c(0L, 0L, 0L, 0L, 0L,
0L), dropout = c(0L, 0L, 0L, 0L, 0L, 0L), highschool = c(0L,
0L, 0L, 0L, 0L, 0L), technical = c(0L, 0L, 0L, 0L, 0L, 0L
), bachelors = c(0L, 0L, 0L, 0L, 0L, 0L), doctor = c(0L,
0L, 0L, 0L, 1L, 0L), enceph = c(0L, 0L, 0L, 0L, 0L, 0L),
aa = c(0L, 0L, 0L, 0L, 0L, 0L), aa_don = c(0L, 0L, 0L, 0L,
0L, 1L), hcc = c(0L, 0L, 0L, 1L, 0L, 0L), meld30 = c(0L,
0L, 0L, 0L, 0L, 1L), meld35 = c(0L, 0L, 0L, 0L, 0L, 0L),
meld40 = c(0L, 0L, 0L, 0L, 0L, 0L), na130 = c(0L, 0L, 0L,
0L, 0L, 0L), na125 = c(0L, 0L, 0L, 0L, 0L, 1L), na120 = c(0L,
0L, 0L, 0L, 0L, 0L), na150 = c(0L, 0L, 0L, 0L, 0L, 0L), na155 = c(0L,
0L, 0L, 0L, 0L, 0L), na160 = c(0L, 0L, 0L, 0L, 0L, 0L), na161 = c(0L,
0L, 0L, 0L, 0L, 0L), fun10 = c(0L, 0L, 0L, 0L, 0L, 0L), fun20 = c(0L,
0L, 0L, 0L, 0L, 0L), fun50 = c(0L, 0L, 0L, 0L, 0L, 0L), fun60 = c(0L,
0L, 0L, 0L, 0L, 0L), fun70 = c(0L, 0L, 0L, 0L, 0L, 0L), fun80 = c(0L,
0L, 0L, 0L, 0L, 1L), fun90 = c(0L, 0L, 0L, 0L, 0L, 0L), fun100 = c(0L,
0L, 0L, 0L, 0L, 0L), hcv_don = c(0L, 0L, 0L, 0L, 0L, 0L),
height_diff = c(-2.6400001, -12.8, -12.96, 12.9, -20.719999,
-35.880001), height30 = c(0, 0, 0, 0, 0, 0), height60 = c(0L,
0L, 0L, 0L, 0L, 0L), height_neg30 = c(0L, 0L, 0L, 0L, 0L,
1L), height_neg60 = c(0L, 0L, 0L, 0L, 0L, 0L), inr25 = c(0L,
0L, 0L, 0L, 0L, 0L), inr3 = c(0L, 0L, 0L, 0L, 0L, 1L), inr35 = c(0L,
0L, 0L, 0L, 0L, 0L), inr4 = c(0L, 0L, 0L, 0L, 0L, 0L), inr41 = c(0L,
0L, 0L, 0L, 0L, 0L), lifesup = c(0L, 0L, 0L, 0L, 0L, 0L),
icu = c(1L, 1L, 0L, 0L, 0L, 1L), hospital = c(0L, 0L, 0L,
0L, 0L, 0L), prev_tx1 = c(0L, 0L, 0L, 0L, 0L, 0L), prev_tx2 = c(0L,
0L, 0L, 0L, 0L, 0L), interval = c(NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_), interval1 = c(NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_
), interval2 = c(NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_), lateretx = c(0L, 0L, 0L, 0L, 0L,
0L), earlyretx = c(0L, 0L, 0L, 0L, 0L, 0L), lateretx2 = c(0L,
0L, 0L, 0L, 0L, 0L), earlyretx2 = c(0L, 0L, 0L, 0L, 0L, 0L
), tx3 = c(0L, 0L, 0L, 0L, 0L, 0L), vent = c(0L, 0L, 0L,
0L, 0L, 0L), ph72 = c(0L, 0L, 0L, 0L, 0L, 0L), ph71 = c(0L,
0L, 0L, 0L, 0L, 0L), ph70 = c(0L, 0L, 0L, 0L, 0L, 0L), portal = c(0L,
0L, 0L, 0L, 0L, 0L), private = c(0L, 0L, 1L, 0L, 1L, 0L),
medicaid = c(0L, 0L, 0L, 0L, 0L, 1L), prev_surg = c(0L, 0L,
0L, 0L, 1L, 0L), region1 = c(0L, 0L, 0L, 0L, 0L, 0L), region2 = c(0L,
0L, 0L, 1L, 0L, 0L), region3 = c(0L, 0L, 0L, 0L, 0L, 0L),
region4 = c(0L, 0L, 0L, 0L, 1L, 0L), region5 = c(0L, 0L,
0L, 0L, 0L, 0L), region6 = c(0L, 0L, 0L, 0L, 0L, 0L), region7 = c(0L,
0L, 0L, 0L, 0L, 0L), region8 = c(0L, 0L, 0L, 0L, 0L, 0L),
region9 = c(1L, 1L, 1L, 0L, 0L, 1L), region10 = c(0L, 0L,
0L, 0L, 0L, 0L), region11 = c(0L, 0L, 0L, 0L, 0L, 0L), ast90 = c(0L,
0L, 1L, 0L, 0L, 1L), ast140 = c(1L, 0L, 0L, 0L, 1L, 0L),
alt60 = c(0L, 0L, 1L, 0L, 0L, 1L), alt100 = c(1L, 0L, 0L,
0L, 1L, 0L), regional = c(0L, 0L, 0L, 0L, 0L, 1L), national = c(0L,
0L, 0L, 0L, 0L, 0L), foreign = c(0L, 0L, 0L, 0L, 0L, 0L),
tbili2_recip = c(1L, 1L, 0L, 1L, 0L, 0L), tbili16_recip = c(0L,
0L, 0L, 0L, 0L, 0L), tbili32_recip = c(0L, 0L, 0L, 0L, 0L,
1L), tbili33_recip = c(0L, 0L, 0L, 0L, 0L, 0L), tbil_don1 = c(0L,
0L, 0L, 0L, 0L, 0L), tbil_don18 = c(1L, 0L, 0L, 0L, 1L, 0L
), tip = c(0L, 0L, 0L, 0L, 0L, 0L), wit70 = c(0L, 0L, 0L,
0L, 0L, 0L), wit80 = c(0L, 0L, 0L, 0L, 0L, 0L), wit90 = c(0L,
0L, 0L, 0L, 0L, 0L), wit91 = c(0L, 0L, 0L, 0L, 0L, 0L), weight_diff = c(-3,
-9, -33, 18, -8, -26), weight45 = c(0, 0, 0, 0, 0, 0), weight70 = c(0L,
0L, 0L, 0L, 0L, 0L), weight_neg45 = c(0L, 0L, 0L, 0L, 0L,
0L), weight_neg70 = c(0L, 0L, 0L, 0L, 0L, 0L), work = c(0L,
0L, 0L, 0L, 0L, 0L)), row.names = c(NA, 6L), class = "data.frame")
Here are the models tried
M99<-glm(data = train,fail~.)
M1 <- lm(fail~., data = fixed)
I know lm is not suitable for factor output, but just wanted to test it out in terms of the error.
Upvotes: 0
Views: 680
Reputation: 1831
You're seeing this error because your data includes columns that have all NA values. Remove those columns, and you should get past this error.
library(tidyr)
library(dplyr)
fixed %>%
gather() %>%
group_by(key) %>%
summarise(nas = sum(is.na(value))) %>%
filter(nas == nrow(fixed))
#> Warning: attributes are not identical across measure variables;
#> they will be dropped
#> # A tibble: 3 x 2
#> key nas
#> <chr> <int>
#> 1 interval 6
#> 2 interval1 6
#> 3 interval2 6
Upvotes: 1