Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Factor variable and menl

    Dear Statalist User,

    I am having a problem correctly defining factor variables in a nonlinear model using menl.
    In a bioassay study I have four treatment groups denoted by A, B, C, D with 10 animals in each groups( Id =A1,A2,.., B1, B2,..... D10). We recorded muscle contraction (y) at different concentrations (conc). The concentration - contraction curve can be described with a function in the following form y = (Bm * Conc)/(Kd+Conc). I think the treatment will change KD and I would like to get separate Kd estimates for each treatment group ( That is just want fixed Kd estimates for each group) .

    Here is a snapshot of my data:
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int conc float y long(Id Group)
       1 -2.75 1 1
      10 27.33 1 1
     100 89.77 1 1
     100 90.64 1 1
    1000 91.75 1 1
    1000 87.74 1 1
       1 -2.26 2 1
       1 -2.79 2 1
       1  -.34 2 1
       1  2.27 2 1
      10 41.73 2 1
      10 76.82 2 1
      10 21.64 2 1
      10  27.1 2 1
     100 89.38 2 1
     100 95.87 2 1
     100 97.57 2 1
     100 79.16 2 1
    1000  96.6 2 1
    1000 83.13 2 1
    1000 93.21 2 1
    1000 78.69 2 1
       1 -1.33 3 2
      10 16.63 3 2
      10 29.54 3 2
      10  6.95 3 2
     100 81.19 3 2
       1 -1.69 4 3
       1 -4.43 4 3
      10   1.8 4 3
      10  1.62 4 3
      10  3.91 4 3
     100 96.91 4 3
     100 97.88 4 3
     100 98.28 4 3
    1000 98.14 4 3
    1000 99.58 4 3
    1000 98.45 4 3
       1  -.99 5 4
       1  -.82 5 4
       1   .25 5 4
       1  -.77 5 4
      10  -.41 5 4
      10  1.11 5 4
      10  -.13 5 4
      10  -.64 5 4
     100 94.26 5 4
     100 95.38 5 4
     100 89.34 5 4
     100 75.41 5 4
    1000 95.31 5 4
    1000 79.85 5 4
    1000 97.57 5 4
    1000 97.85 5 4
    end
    label values Id Id
    label def Id 1 "A1", modify
    label def Id 2 "A10", modify
    label def Id 3 "B10", modify
    label def Id 4 "C4", modify
    label def Id 5 "D3", modify
    label values Group Group
    label def Group 1 "A", modify
    label def Group 2 "B", modify
    label def Group 3 "C", modify
    label def Group 4 "D", modify
    ------------------ copy up to and including the previous line ------------------

    I try to get these estimates with menl:

    Code:
    menl y = (({b0}+{U0[Id]})*conc)/(({b1}+ i.Group+ {U1[Id]})+conc)
    but I get the “invalid name i.Group” error message.
    This is strange because this simple test code provided the expected output.

    Code:
    regress y i.Group
    
    
    ------------------------------------------------------------------------------
               y |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
           Group |
              B  |  -30.77945   21.90323    -1.41   0.166    -74.77339    13.21449
              C  |  -3.698182   16.32571    -0.23   0.822    -36.48933    29.09296
              D  |  -12.21483    14.5259    -0.84   0.404    -41.39097    16.96131
                 |
           _cons |   57.37545   9.425651     6.09   0.000     38.44348    76.30743
    ------------------------------------------------------------------------------


    I am using Stata 15.1.

    I would be very grateful if somebody could fix my code.

    Kind regards,
    Laszlo


  • #2
    If you think through your attempt to use factor variable notation, you will see where is the problem. In non-linear commands that take syntax of the form

    (1) nl (y = {b}*x + {g}*z)

    just saying

    (2) nl (y = x + z)

    does not work for any variables x and z. I mean the syntax one line above eq(2) will fail for any variables, not only for factor variables.

    Hence the problem with your code is that you are trying to include the factor variables directly as i.Goup, whereas you should try to include them as a linear combination

    (3) {xb: i.Group}

    Now by experimentation with some other non-linear commands, and with your -menl- the syntax in eq(3) "works" in the sense that Stata does not produce an error message, and starts to calculate something.

    What does Stata calculate is not known to me, e.g., does Stata exclude one dummy as a reference category? This one I dont know.

    If I were you I would generate my dummies manually, say

    tab Group, gen(Grp)

    and then include manually the dummies less one omitted in a linear combination such as eq.(3).


    Comment


    • #3
      To add to Joro Kolev's useful comment, I would suggest you take a look at Example 4 in the menl documentation that addresses specifying linear combinations in the presence of factor variables. Your updated code should be
      Code:
      menl y = (({b0}+{U0[Id]})*conc)/( {xb: i.Group U1[Id]}+conc)

      Comment


      • #4
        Joro suggested generating indicator variables in the way as xi does. Houssein gave a code snippet which was syntactically different from the initial version of Joro. I have tested both approaches and both of them worked. Many thanks !
        Laszlo

        Comment

        Working...
        X