ANCOVA with contrasts, from the menus?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

ANCOVA with contrasts, from the menus?

Richard Ristow
I've been working with a grad student who asked,

>I am trying to run a regression in SPSS with 2 predictors and one
>outcome. One of the predictors is continuous and one is categorical,
>and the categorical variable has 3 categories.  I want to run a
>simultaneous regression on these variables, but I have specific
>contrasts that I want to include for the categorical variable (I want
>to look at 2 vs. 1&3 as well as 1 v. 3).

This is really an ANCOVA with contrasts, though described as a
'regression'. (Admittedly, both subsume in GLMs.)

Anyway, this student is definitely not a syntax user, and would very
much like a menu solution. (I could do a solution, but I'd far rather
have the student know how, as well.) I came up with the following.
Please let me know if there are better approaches - and (sigh) if I
muffed the definitions. (This uses generated data: "Factor" is the
factor, "FactorOnly" is a dependent depending only on the factor,
"Dependent" depends on both factor and covariate. See generating code
at end of this posting.)

>A.) ONEWAY: Menu Analyze>Compare Means>One-way Anova
>Move to Dependent list: FactorOnly
>.... to Factor window:  Factor
>
>Click "Contrasts". For contrast 1, enter coefficients -1 2 -1 (level 2
>vs. 1 and 3); for contrast 2, enter -1 0 1 (3 vs. 1).
>
>Click Continue, then Paste

That is avowedly an approach, omitting the covariate. Here's the pasted
code:

.  ONEWAY
      FactorOnly BY Factor
     /CONTRAST= -1 2 -1  /CONTRAST= -1 0 1
     /MISSING ANALYSIS .


>B.) UNIANOVA: Menu Analyze>General Linear Model>Univariate...
>
>Dependent: variable "Dependent". Factor, as above. Click Model and
>change type of sums of squares, if desired. Move Covariate to the
>covariates list. Click Contrasts and specify Difference. Continue,
>then Paste. On the pasted syntax, replace the
>"Contrasts(Factor)=Difference" subcommand by the form I have.

And here's the code, after pasting and editing in the SPECIAL contrast:

.  UNIANOVA
      Dependent  BY Factor  WITH Covariate
      /CONTRAST (Factor)=SPECIAL(-1  2 -1
                                 -1  0  1
                                  1  1 1)
      /METHOD = SSTYPE(3)
      /INTERCEPT = INCLUDE
      /CRITERIA = ALPHA(.05)
      /DESIGN = Covariate Factor .

===================
APPENDIX: Test data
===================
*  ................................................................. .
*  .................   Test data               ..................... .
SET RNG = MT       /* 'Mersenne twister' random number generator  */ .
SET MTINDEX = 7778 /*  Providence, RI telephone book              */ .

INPUT PROGRAM.
.  NUMERIC CaseID (N3).
.  LEAVE   CaseID.

.  NUMERIC Factor     (F2)
           /Covariate  (F6.2)
           /Dependent  (F6.2)
           /FactorOnly (F6.2).

.  LOOP CaseID = 1 TO 100.
.     COMPUTE Factor    = TRUNC(RV.UNIFORM(1,4)) /* equi-probable */ .
.     COMPUTE Covariate = RV.UNIFORM(3,33).
.     RECODE  Factor
           (1 = 0)
           (2 = 4)
           (3 = 5) INTO #FctrEff.
.     COMPUTE FactorOnly
             = #FctrEff        /* Effect of categorical variable   */
             + RV.NORMAL(0,3)  /* Error term                       */ .
.     COMPUTE DEPENDENT
             = #FctrEff        /* Effect of categorical variable   */
             + 1.25*Covariate  /* Effect of covariate              */
             + RV.NORMAL(0,3)  /* Error term                       */ .
.     END CASE.
.  END LOOP.
END FILE.
END INPUT PROGRAM.

DATASET NAME     PseudoData  WINDOW=FRONT.
Reply | Threaded
Open this post in threaded view
|

Re: ANCOVA with contrasts, from the menus?

Marta Garcia-Granero
Hi Richard

Just one small item: did your student check the homogeneity of slopes
assumption? It should be non significant for meaningful interpretation
of the contrasts.

(In UNIANOVA dialog window, go to Model, check user defined, add the
factor, the covariate and their interaction term)

Best regards,
Marta

>> I am trying to run a regression in SPSS with 2 predictors and one
>> outcome. One of the predictors is continuous and one is categorical,
>> and the categorical variable has 3 categories.  I want to run a
>> simultaneous regression on these variables, but I have specific
>> contrasts that I want to include for the categorical variable (I want
>> to look at 2 vs. 1&3 as well as 1 v. 3).
>
> This is really an ANCOVA with contrasts, though described as a
> 'regression'. (Admittedly, both subsume in GLMs.)
>
> Anyway, this student is definitely not a syntax user, and would very
> much like a menu solution. (I could do a solution, but I'd far rather
> have the student know how, as well.) I came up with the following.
> Please let me know if there are better approaches - and (sigh) if I
> muffed the definitions. (This uses generated data: "Factor" is the
> factor, "FactorOnly" is a dependent depending only on the factor,
> "Dependent" depends on both factor and covariate. See generating code
> at end of this posting.)
>
>> A.) ONEWAY: Menu Analyze>Compare Means>One-way Anova
>> Move to Dependent list: FactorOnly
>> .... to Factor window:  Factor
>>
>> Click "Contrasts". For contrast 1, enter coefficients -1 2 -1 (level 2
>> vs. 1 and 3); for contrast 2, enter -1 0 1 (3 vs. 1).
>>
>> Click Continue, then Paste
>
> That is avowedly an approach, omitting the covariate. Here's the pasted
> code:
>
> .  ONEWAY
>      FactorOnly BY Factor
>     /CONTRAST= -1 2 -1  /CONTRAST= -1 0 1
>     /MISSING ANALYSIS .
>
>
>> B.) UNIANOVA: Menu Analyze>General Linear Model>Univariate...
>>
>> Dependent: variable "Dependent". Factor, as above. Click Model and
>> change type of sums of squares, if desired. Move Covariate to the
>> covariates list. Click Contrasts and specify Difference. Continue,
>> then Paste. On the pasted syntax, replace the
>> "Contrasts(Factor)=Difference" subcommand by the form I have.
>
> And here's the code, after pasting and editing in the SPECIAL contrast:
>
> .  UNIANOVA
>      Dependent  BY Factor  WITH Covariate
>      /CONTRAST (Factor)=SPECIAL(-1  2 -1
>                                 -1  0  1
>                                  1  1 1)
>      /METHOD = SSTYPE(3)
>      /INTERCEPT = INCLUDE
>      /CRITERIA = ALPHA(.05)
>      /DESIGN = Covariate Factor .
>
> ===================
> APPENDIX: Test data
> ===================
> *  ................................................................. .
> *  .................   Test data               ..................... .
> SET RNG = MT       /* 'Mersenne twister' random number generator  */ .
> SET MTINDEX = 7778 /*  Providence, RI telephone book              */ .
>
> INPUT PROGRAM.
> .  NUMERIC CaseID (N3).
> .  LEAVE   CaseID.
>
> .  NUMERIC Factor     (F2)
>           /Covariate  (F6.2)
>           /Dependent  (F6.2)
>           /FactorOnly (F6.2).
>
> .  LOOP CaseID = 1 TO 100.
> .     COMPUTE Factor    = TRUNC(RV.UNIFORM(1,4)) /* equi-probable */ .
> .     COMPUTE Covariate = RV.UNIFORM(3,33).
> .     RECODE  Factor
>           (1 = 0)
>           (2 = 4)
>           (3 = 5) INTO #FctrEff.
> .     COMPUTE FactorOnly
>             = #FctrEff        /* Effect of categorical variable   */
>             + RV.NORMAL(0,3)  /* Error term                       */ .
> .     COMPUTE DEPENDENT
>             = #FctrEff        /* Effect of categorical variable   */
>             + 1.25*Covariate  /* Effect of covariate              */
>             + RV.NORMAL(0,3)  /* Error term                       */ .
> .     END CASE.
> .  END LOOP.
> END FILE.
> END INPUT PROGRAM.
>
> DATASET NAME     PseudoData  WINDOW=FRONT.
>
Reply | Threaded
Open this post in threaded view
|

Re: ANCOVA with contrasts, from the menus?

Richard Ristow
At 05:43 AM 10/11/2007, Marta Garcia-Granero wrote:

>Just one small item: did your student check the homogeneity of slopes
>assumption? It should be non significant for meaningful interpretation
>of the contrasts.

Excellent question. So far, the answer is 'no'; the student is having
enough trouble getting the analysis to run as far as I've described it.

BUT, this needs to be checked, once the snags with specifying the
analysis are worked out. So, I think, does homogeneity of variance,
plus at least a look at the data by cell, to see if it's prone to
outliers, etc.

And, though I don't have the data directly yet, I'll bet the design is
unbalanced.

>(In UNIANOVA dialog window, go to Model, check user defined, add the
>factor, the covariate and their interaction term)

Thank you very much, and warm regards to you!
Richard