This is a problem due to difference in column names between newdata and Depression_1.
Error lies in step of creating dataframe newdata
,
newdata<-data.frame(`age in years at last birthday`=34,EDUCAT=3,`thousands of dollars per year`=20,`depressed is cesd >= 16`=0,`regular drinker?`=1)
> newdata
age.in.years.at.last.birthday EDUCAT thousands.of.dollars.per.year depressed.is.cesd....16
1 34 3 20 0
regular.drinker.
1 1
Notice how spaces and ?
are replaced by .
in columnnames, the reason being these won't satisfy requirement of dataframe to access columns in form newdata$column.name
. So, to fix this add argument check.names = FALSE
to data.frame function as
newdata <- data.frame(`age in years at last birthday`=34,EDUCAT=3,`thousands of dollars per year`=20,`depressed is cesd >= 16`=0,`regular drinker?`=1, check.names = FALSE)
> newdata
age in years at last birthday EDUCAT thousands of dollars per year depressed is cesd >= 16
1 34 3 20 0
regular drinker?
1 1