Dear Zelig users,
I wonder if someone can help me with an issue running arima models in
Zelig. This may be down to my own unfamiliarity with the software (or
even with arima models in general).
First I want to fit an AR(1) model, and to make forecasts. I want to fit
a simple model with no predictors just to get things started, and then
to add a couple of predictor variables at a later stage.
> z.out1 <- zelig(Diff(log.subscribers.prelib, 0)~ lag.eps(0) +
lag.y(1), model="arima", data=prelib.data)
Error in arima(x = x, xreg = xreg, order = order, ...) :
non-stationary AR part from CSS
So my process is not stationary--but I have a feeling it will be once I
add my predictor variables, right? Still, it is no problem to fit an
arima(1,1,0) model in the mean time--I will check my acf and my pacf
later. This seems to work.
> z.out1 <- zelig(Diff(log.subscribers.prelib, 1)~ lag.eps(0) +
lag.y(1), model="arima", data=prelib.data)
How to cite this model in Zelig:
Justin Grimmer. 2007. "arima: Arima models for Time Series Data" in
Kosuke Imai, Gary King, and Olivia Lau, "Zelig: Everyone's Statistical
Software," http://gking.harvard.edu/zelig
>
Great. Now to predict ahead. But I get this error message.
> x.out1 <- setx(z.out1, pred.ahead=5)
Error in `[<-.ts`(`*tmp*`, ri, value = c(13.356190456064,
13.356190456064, :
only replacement of elements is allowed
>
Can anyone help me to figure out what is going on.
-
Zelig Mailing List, served by Harvard-MIT Data Center
Send messages: zelig(a)lists.gking.harvard.edu
[un]subscribe Options: http://lists.gking.harvard.edu/?info=zelig
Zelig program information: http://gking.harvard.edu/zelig/
Dear Everyone
Is it possible to run a three level or a cross-classified model with
Zelig logit.mixed (or any of the other mixed) commands?
If so, please let me know how to set it up. The manual is clear about
a single source of nesting (g) but not three levels (where g is nested
within h) or cross-classified (for example middle school and high
school where someone who went to one middle school possibly went to
any other high school in the dataset and vice versa) random effects.
Also, (assuming 3 level models are possible) please let me know how I
need to set up the id variables that define the nesting. Should I use:
1 1
1 1
1 2
1 2
2 1
2 1
2 2
For L3 and L2 ID or is this better?
1 11
1 11
1 12
1 12
2 21
2 21
2 22
Thanks.
L
-
Zelig Mailing List, served by Harvard-MIT Data Center
Send messages: zelig(a)lists.gking.harvard.edu
[un]subscribe Options: http://lists.gking.harvard.edu/?info=zelig
Zelig program information: http://gking.harvard.edu/zelig/
Dear Zelig users,
I wonder if someone can help me with an issue running arima models in
Zelig. This may be down to my own unfamiliarity with the software (or
even with arima models in general).
First I want to fit an AR(1) model, and to make forecasts. I want to fit
a simple model with no predictors just to get things started, and then
to add a couple of predictor variables at a later stage.
> z.out1 <- zelig(Diff(log.subscribers.prelib, 0)~ lag.eps(0) +
lag.y(1), model="arima", data=prelib.data)
Error in arima(x = x, xreg = xreg, order = order, ...) :
non-stationary AR part from CSS
So my process is not stationary--but I have a feeling it will be once I
add my predictor variables, right? Still, it is no problem to fit an
arima(1,1,0) model in the mean time--I will check my acf and my pacf
later. This seems to work.
> z.out1 <- zelig(Diff(log.subscribers.prelib, 1)~ lag.eps(0) +
lag.y(1), model="arima", data=prelib.data)
How to cite this model in Zelig:
Justin Grimmer. 2007. "arima: Arima models for Time Series Data" in
Kosuke Imai, Gary King, and Olivia Lau, "Zelig: Everyone's Statistical
Software," http://gking.harvard.edu/zelig
>
Great. Now to predict ahead. But I get this error message.
> x.out1 <- setx(z.out1, pred.ahead=5)
Error in `[<-.ts`(`*tmp*`, ri, value = c(13.356190456064,
13.356190456064, :
only replacement of elements is allowed
>
Can anyone help me to figure out what is going on.
-
Zelig Mailing List, served by Harvard-MIT Data Center
Send messages: zelig(a)lists.gking.harvard.edu
[un]subscribe Options: http://lists.gking.harvard.edu/?info=zelig
Zelig program information: http://gking.harvard.edu/zelig/
Hello,
This question is less an issue of an EI error and more one of
interpretation.
My collaborator and I have been experimenting with Zelig's EI routine.
We're considering an example in public health, where EI type problems
are common (though investigators at times seem rather oblivious to the
problem). In this case, we have data on mental health centers across
the country, and I'm interested in the relationship between race and the
use of psychotropic medications. The actual individual-specific data
show a strong relationship--African-American kids are less likely to be
medicated.
| medbeh.1: Taking
| medication for
| behavioral/emotional
| problems
black | No Yes | Total
-----------+----------------------+----------
0 | 6,343 7,555 | 13,898
| 45.64 54.36 | 100.00
-----------+----------------------+----------
1 | 2,617 2,391 | 5,008
| 52.26 47.74 | 100.00
-----------+----------------------+----------
Total | 8,960 9,946 | 18,906
| 47.39 52.61 | 100.00
So, black kids are 6.5 percentage points less likely to be medicaid.
The data are nested within 44 sites, and when one collapses the data to
the site level, one can generate a table like the following:
Since the % medicated and % black are now continuous variables, I could
calculate a table with blacksite (%black>.33) and medsite (% med >.50)
So, I can do an analogous site-level analysis
. tab blacksite medsite , row
| medsite
blacksite | 0 1 | Total
-----------+----------------------+----------
0 | 6 15 | 21
| 28.57 71.43 | 100.00
-----------+----------------------+----------
1 | 11 12 | 23
| 47.83 52.17 | 100.00
-----------+----------------------+----------
Total | 17 27 | 44
| 38.64 61.36 | 100.00
So, site-level analyses show an exaggerated relationship.
You can see this, too, by looking at the comparable logit coefficients
. logit medbeh_1 black
Iteration 0: log likelihood = -13078.918
Iteration 1: log likelihood = -13046.625
Iteration 2: log likelihood = -13046.625
Logistic regression Number of obs =
18906
LR chi2(1) =
64.59
Prob > chi2 =
0.0000
Log likelihood = -13046.625 Pseudo R2 =
0.0025
------------------------------------------------------------------------------
medbeh_1 | Coef. Std. Err. z P>|z| [95% Conf.
Interval]
-------------+----------------------------------------------------------------
black | -.2651747 .0330207 -8.03 0.000 -.3298941
-.2004552
_cons | .1748578 .0170299 10.27 0.000 .1414798
.2082357
------------------------------------------------------------------------------
. glm medbeh black , link(logit)
/{I probably should have weighted this by the number of kids in each site.)/
Iteration 0: log likelihood = 13.480109
Iteration 1: log likelihood = 13.486325
Iteration 2: log likelihood = 13.486326
Generalized linear models No. of obs
= 44
Optimization : ML Residual df
= 42
Scale parameter =
.0332277
Deviance = 1.395562768 (1/df) Deviance =
.0332277
Pearson = 1.395562768 (1/df) Pearson =
.0332277
Variance function: V(u) = 1 [Gaussian]
Link function : g(u) = ln(u/(1-u)) [Logit]
AIC =
-.5221057
Log likelihood = 13.48632594 BIC =
-157.5404
------------------------------------------------------------------------------
| OIM
medbeh | Coef. Std. Err. z P>|z| [95% Conf.
Interval]
-------------+----------------------------------------------------------------
black | -.3436786 .5148366 -0.67 0.504 -1.35274
.6653826
_cons | .2926308 .211924 1.38 0.167 -.1227326
.7079941
------------------------------------------------------------------------------
so, the site-level analyses exaggerates the relationships.
I wasn't sure EI would give me "the answer", but I didn't expect it to
be so off--the log odds implied by the expected values reported by Zelig
with ei is
-.570. It's actually a worse estimate that just naive, site-level analyses.
Any insights into the poor performance of EI in this case? Is it just a
case of "not every statistical method works every time"? Is there
substantive I can learn from this?
thanks--michael
E. Michael Foster
Professor
School of Public Health
UNC-CH
Is there any way to plot interaction effects with plot.ci?
when I try, for example, something like this (which works just fine w/o the
interaction effect):
z.out <- zelig(policy.taxcut.bin ~
age + income + educ +
east + churatd +
democrat + otherparty + conservative +
democrat*income +
egalitarianism + individualism +
conservative*income,
model = "logit",
data = mi(miin1, miin2, miin3, miin4, miin5))
summary(z.out)
income.range <- 1:14
x.low <- setx(z.out, democrat =0, otherparty=0, income = income.range)
x.high <- setx(z.out, democrat =1, otherparty=0, income = income.range)
s.out <- sim(z.out, x = x.low, x1 = x.high)
plot.ci(s.out, xlab = "Income Level",
ylab = "Increase Tax on Top Bracket?",
main = "Effect of Income on Support for Increased Tax by Party")
legend(45, 0.52, legend = c("Democrat",
"Republican"), col = c("blue","red"),
lty = c("solid"))
I get this:
Error in plot.ci(s.out, xlab = "Income Level", ylab = "Increase Tax on Top
Bracket?", :
x and x1 in vary on different dimensions.
Any advice?
Donald Braman
Associate Professor of Law
The George Washington University Law School
2000 H Street, NW | Washington, DC 20052
tel (202) 994-0572 | fax (202) 994-3377
http://www.law.gwu.edu/Faculty/profile.aspx?id=10123http://research.yale.edu/culturalcognitionhttp://ssrn.com/author=286206
Dear All,
I try to run a gamma mixed model in zelig, but got the following error message:
Error in eval(expr, envir, enclos) :
non-positive values not allowed for the gamma family
Besides the dependent structure among observations, a large proportion (about 75%) of my response variable is zero. I was advised that zelig gamma mixed model can handle my zero-augmented data. Is that true?
The code for my model is:
z.out1 <- zelig (OutDegr ~ Pr65 + Pr80 + Pr00 + Semipr65 + Semipr80 + Semipr00 + tag(1 | cityid), data = wc3, model = "gamma.mixed")
Could anybody give me some help?
Thank you very much!
Xiulian
Try restarting R. And type:
library(Zelig)
demo(gamma)
This should work.
Kosuke
--
Department of Politics
Princeton University
http://imai.princeton.edu
On Wed, 1 Apr 2009, Travis Porco wrote:
> Thanks much?download worked like a charm; I?ll keep trying to solve the
> Error message. Best, -travis
>
> The downloaded packages are in
> /private/tmp/Rtmpr2B1KP/downloaded_packages
> Updating HTML index of packages in '.Library'
>> require(Zelig)
>> z.out <- zelig(duration ~ fract + numst2, model="gamma",data=coalition)
> Error in xj[i] : invalid subscript type 'list'
>
>
>
>
> From: Kosuke Imai <kimai(a)Princeton.EDU>
> Date: Wed, 1 Apr 2009 20:30:28 -0400
> To: Travis Porco <Travis.Porco(a)ucsf.edu>
> Cc: <zelig(a)lists.gking.harvard.edu>
> Subject: Re: Zelig package
>
> If you are using Mac, try...
>
> install.packages("Zelig", repos = "http://gking.harvard.edu", type =
> "source")
>
> Kosuke
>
>
-
Zelig Mailing List, served by Harvard-MIT Data Center
Send messages: zelig(a)lists.gking.harvard.edu
[un]subscribe Options: http://lists.gking.harvard.edu/?info=zelig
Zelig program information: http://gking.harvard.edu/zelig/
If you are using Mac, try...
install.packages("Zelig", repos = "http://gking.harvard.edu", type =
"source")
Kosuke
--
Department of Politics
Princeton University
http://imai.princeton.edu
On Wed, 1 Apr 2009, Travis Porco wrote:
> Thanks much for your help?I will check the list. Warm regards, --travis
> Ps. I have the latest version from CRAN Berkeley (downloaded today); also
>
>> install.packages("Zelig", repos = "http://gking.harvard.edu")
> trying URL
> 'http://gking.harvard.edu/bin/macosx/universal/contrib/2.8/Zelig_3.4-3.tgz'
> Error in download.file(url, destfile, method, mode = "wb", ...) :
> cannot open URL
> 'http://gking.harvard.edu/bin/macosx/universal/contrib/2.8/Zelig_3.4-3.tgz'
> In addition: Warning message:
> In download.file(url, destfile, method, mode = "wb", ...) :
> cannot open: HTTP status was '404 Not Found'
> Warning in download.packages(p0, destdir = tmpd, available = available, :
> download of package 'Zelig' failed
>
>
>
>
> From: Kosuke Imai <kimai(a)Princeton.EDU>
> Date: Wed, 1 Apr 2009 20:25:10 -0400
> To: Travis Porco <Travis.Porco(a)ucsf.edu>
> Cc: <zelig(a)lists.gking.harvard.edu>
> Subject: Re: Zelig package
>
> Dear Travis,
>
> Please direct the questions to the email list to which I cc'd this
> message. To answer your question, please try installing the latest
> version of Zelig, which is available via:
>
> install.packages("Zelig", repos = "http://gking.harvard.edu")
>
> Thanks,
> Kosuke
>
>
-
Zelig Mailing List, served by Harvard-MIT Data Center
Send messages: zelig(a)lists.gking.harvard.edu
[un]subscribe Options: http://lists.gking.harvard.edu/?info=zelig
Zelig program information: http://gking.harvard.edu/zelig/
Dear Travis,
Please direct the questions to the email list to which I cc'd this
message. To answer your question, please try installing the latest
version of Zelig, which is available via:
install.packages("Zelig", repos = "http://gking.harvard.edu")
Thanks,
Kosuke
--
Department of Politics
Princeton University
http://imai.princeton.edu
On Wed, 1 Apr 2009, Travis Porco wrote:
> Hi?I wonder if I could presume to ask you a question about your Zelig
> package. I?m running R 2.8.1, and installed your package. I used your
> vignette
> http://gking.harvard.edu/zelig/docs/gamma.pdf to learn how to run a gamma
> model. I get the error: Error in xj[i] : invalid subscript type ?list?. I
> googled this error message and checked the R-lists and have found no clues.
> Perhaps I have packages installed that should not be installed, or have
> failed to install something that should be installed; note however that
> I have MASS, boot, and R above 2.6.
>
> Thanks for any insight you might have!
>
> I?m thankful for your software and hope to be able to use your product.
>
> Session below:
>
>> require(Zelig)
> Loading required package: Zelig
> ##
> ## Zelig (Version 3.4-3, built: 2009-02-12)
> ## Please refer to http://gking.harvard.edu/zelig for full
> --snip--
>
> ## To cite individual Zelig models, please use the citation format printed
> with
> ## each model run and in the documentation.
>
>> # example from page 2 of vignette
>> data(coalition)
>> z.out <- zelig(duration ~ fract + numst2, model="gamma",data=coalition)
> Error in xj[i] : invalid subscript type 'list'
>
>> # my data fails also:
>> zout <- zelig(formula(paste("fi
> ~",paste(var.set,collapse="+"))),model="gamma",data=zgdata)
> Error in xj[i] : invalid subscript type 'list'
>
>> # toy data fails also:
>> uk <- data.frame(y=rgamma(100,shape=2,scale=1),x=rnorm(100))
>> zelig(y ~ x, model="gamma",data=uk)
> Error in xj[i] : invalid subscript type 'list'
>
>> sessionInfo()
> R version 2.8.1 (2008-12-22)
> i386-apple-darwin8.11.1
>
> locale:
> en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8
>
> attached base packages:
> [1] splines stats graphics grDevices utils datasets methods
> base
>
> other attached packages:
> [1] Zelig_3.4-3 MASS_7.2-46 BMA_3.09 leaps_2.8
> [5] lme4_0.999375-28 Matrix_0.999375-22 lattice_0.17-20 Kendall_2.0
> [9] boot_1.2-36 nortest_1.0 splus2R_1.0-5
> survival_2.35-3
>
> loaded via a namespace (and not attached):
> [1] grid_2.8.1 tools_2.8.1
>
>
-
Zelig Mailing List, served by Harvard-MIT Data Center
Send messages: zelig(a)lists.gking.harvard.edu
[un]subscribe Options: http://lists.gking.harvard.edu/?info=zelig
Zelig program information: http://gking.harvard.edu/zelig/