Disclaimer:
First up - I am not a stats man - I am a struggling computer science
guy - so sorry if I make a meal of explaining this.
Problem:
I am trying to figure out how to plot my fitted model created by
applying logistic regression to my data. My data and R code for
creating my model are attached.
What I want is to have two repression lines - as in the chart attached
which was created with the following code
ggplot(stack.data,aes(x=version,y=fail/(pass+fail
+notexe),colour=impl,group=impl)) + geom_point() +
stat_smooth(method=lm)
The example on the ggplot site for logistic regression is based on
having raw 0s and 1s. I cant see how to apply my data to this
approach. (http://had.co.nz/ggplot2/stat_smooth.html)
Also my data is categorical, so I have no idea how the code above even
worked - because the coefficients created in my model dont seem to
provide slopes. So I dont know how the ) "+ stat_smooth(method=lm)"
clause created the attached graph. Does it ignore the fact that
version is a factor?
Any help would be great,
Thanks,
Andrew
Why would you want to convert categorical variables into continuous?
Here's how I'd visualise your data and model:
library(ggplot2)
stack.data <- read.csv("stack.csv")
stack.data$version <- factor(stack.data$version)
stack.data$prob <- with(stack.data, fail / (pass+fail+notexe))
model.bin <- glm(cbind(fail,(pass+fail+notexe)) ~ impl + version,
family = binomial,data = stack.data)
grid <- with(stack.data, expand.grid(
impl = levels(impl),
version = levels(version)
))
grid$prob <- predict(model.bin, grid, type = "response")
ggplot(stack.data, aes(version, prob, colour = impl)) +
geom_point() +
geom_line(aes(group = impl), data = grid)
If it's not obvious from the plot, your model isn't very good. Have
you mislabelled impl for version 1?
Hadley