[ADMB Users] quick TPL help ... ?

H. Skaug hskaug at gmail.com
Mon Dec 31 13:07:01 PST 2012


Yes, it appears that regression() was never implemented for the random
effects stuff. Without changing the code base you
can write your own function like this. If it works, you can give
me a word, I and I will add it to the code base.

Hans



DATA_SECTION

  init_int nobs
  init_vector Day(1,54)
  init_vector X(1,54)
  init_matrix XR(1,54,1,3)
  init_matrix Z(1,54,1,9)

PARAMETER_SECTION

  objective_function_value f
  init_number asympL
  init_vector Rvec(1,3)
  init_number xmid
  init_number scale
  init_bounded_number Rsigma(0,10)
   vector pred(1,nobs)       // predicted values
   vector Rval(1,nobs)       //
  random_effects_vector Ru(1,9)

GLOBALS_SECTION
  #include <df1b2fun.h>

  df1b2variable regression(const dvector& obs, const df1b2vector& pred)
  {
    double nobs=double(size_count(obs));
    df1b2variable vhat=norm2(obs-pred);
    vhat/=nobs;
    return (.5*nobs*log(vhat));
  }



PROCEDURE_SECTION
   Rval = XR*Rvec+Rsigma*(Z*Ru);
   pred = asympL+elem_div(Rval-asympL,1.0+exp(-(Day-xmid)/scale));
   f = regression(X,pred)+norm2(Ru);




On Mon, Dec 31, 2012 at 7:43 PM, Ben Bolker <bbolker at gmail.com> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> I have a fairly simple TPL file in which I'm trying to fit a
> four-parameter logistic regression model with a random effect on
> the right-hand (lower) asymptotic value parameter R.
>
>   I originally wrote my objective function as
>
>     f = regression(X,pred)+norm2(Ru);
>
> which gave me
>
> error: no matching function for call to ‘regression(data_vector&,
> df1b2vector&)’
> /usr/local/admb/include/fvar.hpp:4073: note: candidates are: dvariable
> regression(const dvector&, const dvar_vector&)
> /usr/local/admb/include/fvar.hpp:4074: note:                 double
> regression(const dvector&, const dvector&)
>
>   After quite a bit of fussing around I discovered that if I just
> replaced the regression() function with its guts,
>
>    f = 0.5*nobs*log(norm2(X-pred)/nobs)+norm2(Ru);
>
> I get reasonable answers ...
>
>   I'm satisfied for now, but I assume this is due to some bit that
> didn't get fully implemented in ADMB-RE?  I'm afraid I don't know
> quite enough to hack in the extension to regression(const dvector&,
> const dvector&); a boneheaded attempt to copy and modify the function
> definitions in src/linad99/vregress.cpp and src/linad99/fvar.hpp fails
> with
>
> fvar.hpp:4073: error: ISO C++ forbids declaration of ‘df1b2vector’
> with no type
> fvar.hpp:4073: error: expected ‘,’ or ‘...’ before ‘&’ token
>
> presumably because I ought to have put it into the df1b2-separable
> directory where it would know all about the type definition ... ?
>
>   The original TPL file:
> ==================
> DATA_SECTION
>
>   init_int nobs
>   init_vector Day(1,54)
>   init_vector X(1,54)
>   init_matrix XR(1,54,1,3)
>   init_matrix Z(1,54,1,9)
>
> PARAMETER_SECTION
>
>   objective_function_value f
>   init_number asympL
>   init_vector Rvec(1,3)
>   init_number xmid
>   init_number scale
>   init_bounded_number Rsigma(0,10)
>    vector pred(1,nobs)       // predicted values
>    vector Rval(1,nobs)       //
>   random_effects_vector Ru(1,9)
>
> PROCEDURE_SECTION
>    Rval = XR*Rvec+Rsigma*(Z*Ru);
>    pred = asympL+elem_div(Rval-asympL,1.0+exp(-(Day-xmid)/scale));
>    f = regression(X,pred)+norm2(Ru);
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (GNU/Linux)
> Comment: Using GnuPG with undefined - http://www.enigmail.net/
>
> iQEcBAEBAgAGBQJQ4dzRAAoJEOCV5YRblxUHxxAIAJi1LLLG2FzQzfXYJRmokL98
> 4c4jKjErKcue9gAlkeQP2rRrX8Px5jaAxuV8IkIEhigOwcvap0Ix1Ty/hMAN9cMs
> z3tAqZ9wiiYekdBNdzoYfHvFQWTxvfd3uhPRTkNwhWIYtxy5mmYVBF9l23HWE9Vp
> ZSENSpE6rPSgxiQLpTGENB6zh6Pd9twUIgQo2LgHmGRahY7nRPGfYy9T8laL1/4X
> c/b17o5H+yppdhDaRKQ6JahUcQrzyBMHKtd/A0r9u49xuxeTNLPzv3cdHBJV4zuV
> An1Js2KbRYqu070WdtAFXwWSmiffADzSRemM4H0JUObVuFwTLWmtfv3G5ls4Xik=
> =e6Ai
> -----END PGP SIGNATURE-----
> _______________________________________________
> Users mailing list
> Users at admb-project.org
> http://lists.admb-project.org/mailman/listinfo/users



More information about the Users mailing list