I am attempting to using ggplot2
to graph some basic simulations and multi-variable regression models but am at a loss.
I am using Zelig 3.5
(as newer Zeligs have glitches with simulations)
Based on a blog I found, I tried this
AppMod1 <- (s1$qi)
AppMod1 <- data.frame(AppMod1$ev)
AppMod1 <- melt(AppMod1, measure=1:86)
AppMod1 <- ggplot(AppMod1, aes(approve, year)) +
geom_point() +
geom_smooth(colour="blue") +
theme_tufte()
AppMod1
` This didn't work. I got an error
"Error: measure variables not found in data:NA"
My models are m1, m2, and m3, and my simulations are m1 and m2. I am using the "approval" data set which comes in Zelig.
The models are calculated as follows
data(approval)
m1 <- zelig(approve~avg.price, model="ls", data=approval)
m2 <- zelig(approve~avg.price+sept.oct.2001+iraq.war, model="ls", data=approval)
m3 <- zelig(approve~avg.price+sept.oct.2001+avg.price:sept.oct.2001, model="ls", data=approval)
And the simulations are
x1 <- setx(m2, sept.oct.2001= 1)
s1 <- sim(m2, x=x1)
summary(s1)
x1 <- setx(m2, sept.oct.2001= 0)
s1 <- sim(m2, x=x1)
summary(s1)
oilprice <- min(approval$avg.price):max(approval$avg.price)
x2 <- setx(m2, sept.oct.2001=0, avg.price=oilprice)
s2 <-sim (m2, x=x2)
plot.ci(s2)
oilprice <- min(approval$avg.price):max(approval$avg.price)
x2 <- setx(m2, sept.oct.2001=1, avg.price=oilprice)
s2 <-sim (m2, x=x2)
plot.ci(s2)