Announcement

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

  • How get Ha:diff < 0 or Ha: diff > 0 with contrast (post regression)

    Hi all,

    I am trying to get alternative Hypotheses in a contrast post regresion to get similar ttest results, I wonder if its posible:

    Ha:diff < 0
    Ha: diff > 0

    In my example I show ttest results and contrast to get the same results: The signs for the difference, the test statistic, and the confidence intervals are reversed because
    the difference is taken in the opposite direction, also I tried with pwmean test:


    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte(fertilizer irrigation) float(yield N03_N)
    1 0   25.5471    9
    1 0   26.9514  7.5
    1 0  30.42061    8
    1 0 32.142567    8
    1 0 33.476627  9.5
    1 0 35.112484  8.5
    1 0 35.643112    9
    1 0 36.786076 10.5
    1 0 37.020485  9.5
    1 0 37.382446   10
    1 0 37.633434    8
    1 0  38.24033   10
    1 0  38.47208    9
    1 0  39.00444  9.5
    1 0  39.03085  8.5
    1 0  39.46735    9
    1 0  42.28565  8.5
    1 0   42.9318    9
    1 0  44.10148  9.5
    1 0  46.60105 10.5
    1 1 35.594612   10
    1 1  36.84657    9
    1 1  39.16208  8.5
    1 1  39.64972 10.5
    1 1  41.53548 10.5
    1 1  41.65326 10.5
    1 1  42.89606    9
    1 1  43.16227   10
    1 1  43.19808 10.5
    1 1  46.89809 10.5
    1 1  46.99522    9
    1 1  47.37473   10
    1 1  48.75241    9
    1 1  48.78089   11
    1 1   49.3729   10
    1 1  49.88928 10.5
    1 1  50.06085   10
    1 1  50.10778   10
    1 1  53.88142 10.5
    1 1   60.4341   11
    2 0  30.33382    8
    2 0 33.649242  5.5
    2 0 33.986282    6
    2 0 34.199596    6
    2 0  34.30233  7.5
    2 0 34.330006  5.5
    2 0  34.98474  7.5
    2 0 35.485172    8
    2 0 35.540104    6
    2 0 36.922596  6.5
    2 0   41.4649    8
    2 0  41.47297  8.5
    2 0  41.63222    7
    2 0  41.70517  9.5
    2 0  42.54293    9
    2 0  42.77414    8
    2 0  43.02679    8
    2 0  43.03543  7.5
    2 0  46.14563 10.5
    2 0  48.36243   11
    2 1   41.1847    9
    2 1  42.89641    9
    2 1  45.26883  8.5
    2 1  45.53941    7
    2 1  45.77157 10.5
    2 1  46.79755  9.5
    2 1  49.55231  8.5
    2 1  49.87773   10
    2 1  50.73264    9
    2 1  51.20868   11
    2 1  51.83252 10.5
    2 1  52.63506 10.5
    2 1  52.82097    9
    2 1  53.07209  8.5
    2 1  55.70432   11
    2 1  56.25944 10.5
    2 1  56.64001   12
    2 1  57.53093    9
    2 1  58.14713   11
    2 1  60.03719 12.5
    3 0 28.385687 12.5
    3 0   31.1877   13
    3 0 31.540403   13
    3 0 32.954784 12.5
    3 0 33.825752 13.5
    3 0 34.072716   14
    3 0 35.216423 14.5
    3 0 35.538937   14
    3 0  35.55414 13.5
    3 0 35.731876   14
    3 0 38.014694   15
    3 0  38.35717   15
    3 0  38.37197 14.5
    3 0  38.76787 14.5
    3 0  39.05844 14.5
    3 0  39.13557   15
    3 0  39.53992   14
    3 0  40.09854 14.5
    3 0  40.11148   15
    3 0  41.41248   16
    end
    label values fertilizer fertlbl
    label def fertlbl 1 "10-10-10", modify
    label def fertlbl 2 "10-08-22", modify
    label def fertlbl 3 "16-04-08", modify
    
    *****************************************************************
    *ttest test
    
    . ttest yield, by(irrigation)
    
    Two-sample t test with equal variances
    ------------------------------------------------------------------------------
       Group |     Obs        Mean    Std. err.   Std. dev.   [95% conf. interval]
    ---------+--------------------------------------------------------------------
           0 |     100    37.91277    .5300607    5.300607    36.86102    38.96453
           1 |     100    47.93122    .5630353    5.630353    46.81403     49.0484
    ---------+--------------------------------------------------------------------
    Combined |     200    42.92199    .5242462    7.413961     41.8882    43.95579
    ---------+--------------------------------------------------------------------
        diff |           -10.01844    .7732872               -11.54338   -8.493509
    ------------------------------------------------------------------------------
        diff = mean(0) - mean(1)                                      t = -12.9557
    H0: diff = 0                                     Degrees of freedom =      198
    
        Ha: diff < 0                 Ha: diff != 0                 Ha: diff > 0
     Pr(T < t) = 0.0000         Pr(|T| > |t|) = 0.0000          Pr(T > t) = 1.0000
    
    ********************************************************************
    *post regresion test
    
    qui reg yield i.irrigation
    contrast i.irrigation, effect nowald
    
    Contrasts of marginal linear predictions
    
    Margins: asbalanced
    
    ------------------------------------------------------------------------------
                 |   Contrast   Std. err.      t    P>|t|     [95% conf. interval]
    -------------+----------------------------------------------------------------
      irrigation |
    (1 vs base)  |   10.01844   .7732872    12.96   0.000     8.493509    11.54338
    ------------------------------------------------------------------------------
    
    *******************************************************************************
    
    *pwmean test
    
    . pwmean yield, over(irrigation) effects
    
    Pairwise comparisons of means with equal variances
    
    Over: irrigation
    
    ------------------------------------------------------------------------------
                 |                            Unadjusted           Unadjusted
           yield |   Contrast   Std. err.      t    P>|t|     [95% conf. interval]
    -------------+----------------------------------------------------------------
      irrigation |
         1 vs 0  |   10.01844   .7732872    12.96   0.000     8.493509    11.54338
    ------------------------------------------------------------------------------
    Thanks in advance,
    Regards
    Rodrigo
    Last edited by Rodrigo Badilla; 22 Mar 2023, 10:16.

  • #2
    Hello Rodrigo Badilla. This FAQ may help. Cheers,
    Bruce
    --
    Bruce Weaver
    Email: [email protected]
    Version: Stata/MP 19.5 (Windows)

    Comment


    • #3
      Thanks Bruce Weaver for the link!

      Regards
      Rodrigo

      Comment

      Working...
      X