1

Using R, I am running regressions, simulations , and testing the significance on a simple data set ("approval" in Zelig).

All is going well until I try to test the statistical significance.

This is my code:

library(mvtnorm)
library(Zelig)
data(approval)

set.seed(12345)
xh1 <- setx(approval, avg.price = mean(approval$avg.price) + sd(approval$avg.price), sept.oct.2001=1) 
xl1 <- setx(approval, avg.price= mean(approval$avg.price), sept.oct.2001=1)
xh0 <- setx(approval, avg.price = mean(approval$avg.price) + sd(approval$avg.price), sept.oct.2001 =0)
xl0 <- setx(approval, avg.price= mean(approval$avg.price), sept.oct.2001=0)
zh1 <- sim(approval, x=xh1)zl1 <- sim(approval, x=xl1)zh0 <-sim(approval, x=xh0)
zl0 <- sim(approval, x=xl0)
eff <- (zh1$qi$ev - zl1$qi$ev) -(zh0$qi$ev - zl0$qi$ev)
quantile(eff, c(.025, .975))

And the error that I get is

Quitting from lines 87-103 (Preview-151c5fba73e.Rmd) Error in terms.default(object) : no terms component nor attributeCalls: ... eval -> setx -> setx.default -> terms -> terms.default Execution halted

For reference,

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 for my simulations

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)

This all worked totally fine.

MichaelChirico
  • 33,841
  • 14
  • 113
  • 198
Sarah
  • 11
  • 1
  • 3
  • I even cannot run the first line with `setx`. It throws an error. Are you using the correct syntax? –  May 01 '15 at 03:00
  • `setx` has to be given the return of `zelig` which wont be a data frame like `approval` is – rawr May 01 '15 at 03:11
  • Pascal, the reason that you cannot run the code is because you don't have m2 I think. The order that my codes are is: first create m1, m2, and m3 as linear regressions (worked fine) , then simulations. I have it potsed on rpubs http://rpubs.com/sarahegayle/78712 . Rawr thanks but I don't understand what you are saying. Can you be more specific? I am not very good at this... – Sarah May 01 '15 at 13:23
  • I got it! I was using the data set instead of my regression model. Thanks !! – Sarah May 01 '15 at 16:07

0 Answers0