[R] Drop in a Loop

Will Hopper wjhopper510 at gmail.com
Wed Sep 16 16:20:28 CEST 2015


The data structure returned by optimx (that you're storing as gmmiv) is
like a data frame, and stores the conversion code in the field  convcode.
So do something like this:

gmmiv =Optimx()
if (gmmiv$convcode ==0) {
  store[j,] = coef(gmmiv)
}

On Tue, Sep 15, 2015 at 3:12 PM, Olu Ola <oluola2011 at yahoo.com> wrote:

> Thanks Will.
>  Below is the flow of my code
>
> Yhat is the fitted value
> Errhat is the difference between the dependent variable and the yhat
> gmmdata is the data name
>
> N <- nrow(gmmdata)
> B <- 1000
> store <- matrix(0,B,11)
> for (j in 1:B) {
>   index = sample(1:N, N, replace=T)
>   errnew = errhat[index]
>   yt = yhat + errnew
> objective function subroutine
> gradient function subroutine
> gmmiv =Optimx()
>   store[j,] = coef(gmmiv)
> }
>
> What I want to do is that if the convergence code from optimx for a
> particular iteration is Not zero, then it should not be stored in store[j,].
>
> Any help will be appreciated
>
> Thank you
>
>
>
>
>
>
> --------------------------------------------
> On Tue, 9/15/15, Will Hopper <wjhopper510 at gmail.com> wrote:
>
>  Subject: Re: [R] Drop in a Loop
>  To: "Olu Ola" <oluola2011 at yahoo.com>
>  Cc: r-help at r-project.org
>  Date: Tuesday, September 15, 2015, 2:30 PM
>
>  I
>  think you ought to show a small example of how the code
>  you're using. Are you saving results at every iteration?
>  In a list, data frame, etc? People likely need that to help
>  answer your question.
>
>   Also probably have a look the control list
>  argument and the save.failures option, that might be
>  something you're interested in.
>
>  - Will
>
>  On Tue, Sep 15, 2015 at
>  1:34 PM, Olu Ola via R-help <r-help at r-project.org>
>  wrote:
>  Hello,
>
>  I am doing some estimation using optimx and after each round
>  of estimation, I store the coefficient. However, I need to
>  drop the set of coefficients for which the convergence code
>  in optimx is GREATER than Zero. How do I go about this?
>
>
>
>  A way forward will be highly appreciated.
>
>
>
>  Thank you
>
>
>
>  ______________________________________________
>
>  R-help at r-project.org
>  mailing list -- To UNSUBSCRIBE and more, see
>
>  https://stat.ethz.ch/mailman/listinfo/r-help
>
>  PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
>
>  and provide commented, minimal, self-contained, reproducible
>  code.
>
>
>
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list