sábado, 30 de enero de 2016

Testing moderation in the context of ANOVA

Testing a Potential Moderator

 In this case, I am using the ANOVA tool for assessing the following hypothesis:
"There is a relationship between drink beer and be laid off at the last 12 months, as moderator is the situation to have got separated or broken off a relationship"
Quantity response variable=Quantity beer
Categorical explanatory variable=Be laid off or not
Moderator=got separated or broken off a relationship

In the first case when a person has got separated or broken off a relationship, p value =0.0735, that is it is not statistically significantly, for the second case p-value=.0001 it reveals that there is a relationship between the variables.

In general in the media values reveal for both cases either with or without to have got separated or broken relationship, people  who  has been laid off tend to drink more than who has a job. This can see in the group S1Q234(Laid off 1 yes, 2 no)  level  1 is bigger than level 2 in both cases

LIBNAME mydata "/courses/d1406ae5ba27fe300 " access=readonly;
DATA new; set mydata.nesarc_pds;

LABEL ALCABDEP12DX="Alcohol Dependence Past 12 Months"
      S2AQ5A=" Drank any beer Last 12 Months"
      S2AQ5B="How often Drank beer Last 12 Months"
      S2AQ5D="Numbers of beer consumed";
     
     
     /*Set appropriate missing data as needed*/
IF S2AQ5B=99 THEN S2AQ5B=.;
IF S2AQ5D=99 THEN S2AQ5D=.;


IF S2AQ5B=1 THEN FREQMO=365;
ELSE IF S2AQ5B=2 THEN FREQMO=312;
ELSE IF S2AQ5B=3 THEN FREQMO=208;
ELSE IF S2AQ5B=4 THEN FREQMO=104;
ELSE IF S2AQ5B=5 THEN FREQMO=52;
ELSE IF S2AQ5B=6 THEN FREQMO=36;
ELSE IF S2AQ5B=7 THEN FREQMO=12;
ELSE IF S2AQ5B=8 THEN FREQMO=11;
ELSE IF S2AQ5B=9 THEN FREQMO=6;
ELSE IF S2AQ5B=10 THEN FREQMO=2;
/*days per year
365=Every day
312=Nearly every day
208=3 to 4 times a week
104=2 times a week
52=Once a week
36=2 to 3 times a month
12=Once a month
11=7 to 11 times in the last year
6=3 to 6 times in the last year
2=1 or 2 times in the last year*/

NUMBEER=FREQMO*S2AQ5D;

/*subsetting data to include only past 12 month smokers, age 18-25*/
IF S2AQ5A=1;
IF AGE LE 25;

PROC SORT; by IDNUM;
PROC SORT; by S1Q238;
PROC ANOVA; CLASS S1Q234;
MODEL NUMBEER=S1Q234;
MEANS S1Q234;by S1Q238;


RUN;
Procedimiento ANOVA
Información de nivel de clase
Clase Niveles Valores
S1Q234 3 1 2 9
Número de observaciones leídas 494
Número de observaciones usadas 491

Procedimiento ANOVA
Variable dependiente: NUMBEER
Fuente DF Suma de cuadrados Cuadrado de la media F-Valor Pr > F
Modelo 2 3969215.1 1984607.6 2.62 0.0735
Error 488 369085652.9 756323.1
Total corregido 490 373054868.0
R-cuadrado Coef Var Raíz MSE NUMBEER Media
0.010640 201.4764 869.6684 431.6477
Fuente DF Anova SS Cuadrado de la media F-Valor Pr > F
S1Q234 2 3969215.143 1984607.572 2.62 0.0735
Distribución de NUMBEER por S1Q234

Procedimiento ANOVA
Distribución de NUMBEER por S1Q234
Nivel de
S1Q234
N NUMBEER
Media Dev std
1 102 605.029412 1215.06217
2 388 386.994845 753.92456
9 1 72.000000 .

Procedimiento ANOVA
Información de nivel de clase
Clase Niveles Valores
S1Q234 2 1 2
Número de observaciones leídas 2357
Número de observaciones usadas 2348

Procedimiento ANOVA
Variable dependiente: NUMBEER
Fuente DF Suma de cuadrados Cuadrado de la media F-Valor Pr > F
Modelo 1 6406134.2 6406134.2 15.21 <.0001
Error 2346 988331490.7 421283.7
Total corregido 2347 994737624.9
R-cuadrado Coef Var Raíz MSE NUMBEER Media
0.006440 216.3500 649.0637 300.0064
Fuente DF Anova SS Cuadrado de la media F-Valor Pr > F
S1Q234 1 6406134.184 6406134.184 15.21 <.0001
Distribución de NUMBEER por S1Q234

Procedimiento ANOVA
Distribución de NUMBEER por S1Q234


Nivel de
S1Q234
N NUMBEER
Media Dev std

1293438.337884
1079.88294

22055280.283212
561.59831