Let’s simply read and think about the error message:
Error: variable ‘dummygen’ was fitted with type “numeric” but type “factor” was supplied
This error occurs after the line:
ooslogit <- predict.glm(logit, newlogit, se.fit=TRUE)
(Presumably, at least, because you’re question isn’t very clear about this and provides lots of code that doesn’t seem related.)
So R is telling you that when the model was fit the variable dummygen
was numeric, but now you’ve given it a factor.
So let’s look:
str(newlogit)
'data.frame': 20 obs. of 2 variables:
$ age : num 1 1.26 1.53 1.79 2.05 ...
$ dummygen: Factor w/ 1 level "0": 1 1 1 1 1 1 1 1 1 1 ...
Yep!
So your problem was that you inexplicably created the data frame newlogit
by specifying:
newlogit <- data.frame(age=seq(1,6, length=20), dummygen=("0"))
which clearly specifies that the variable dummygen
is not going to be numeric. Just convert it back, or remove the quotes in the first place. For example:
newlogit <- data.frame(age=seq(1,6, length=20), dummygen= 0)
or
newlogit$dummygen <- as.numeric(newlogit$dummygen)
1
solved Error in setting up and cleaning a dataframe R