Coding interaction term in Design Matrix

questions concerning analysis/theory using program MARK

Coding interaction term in Design Matrix

Postby Miina Kovanen » Thu Jan 14, 2010 3:20 pm

It would be most helpful to get any comments on the following problem:

I have tested two different ways to code an interaction term in DM, and don't understand why do they differ and which is the correct way. This interaction is between an individual time-variant covariate (age class, young/old) and a season. I also need to build candidate model including the interaction but not the independent effects, thus it is important to understand how to build these models also without using the product-function (if possible...).

Age class is coded as an individual time-variable covariate in my data; for each individual I have coded an age class constraint for each week. These weekly age class constraints are named as var1, var2, var3 etc. in the .inp -file and get values -1(individual not yet/anymore in the study that week), 0(young), 1(old)). Do I mixed up things somehow since the covariate names are var1, var2 etc. but also in the DM funtions, columns are coded with var (instead of col as it used to be in an earlier version)?

Here are simplified design matrix examples, model {age+age*snowseason}:

1) I build the interaction with the product of colums -function:

Age Snowseason Age*Snowseason Constant
1:s var1 1 product(var1,var2) 1
2:s var2 1 product(var1,var2) 1
3:s var3 1 product(var1,var2) 1
4:s var4 0 product(var1,var2) 1
5:s var5 0 product(var1,var2) 1
6:s var6 0 product(var1,var2) 1
7:s var7 0 product(var1,var2) 1
8:s var8 0 product(var1,var2) 1
9:s var9 0 product(var1,var2) 1
10:s var10 0 product(var1,var2) 1


2) I build the interaction without using the product function:

Age Snowseason Age*Snowseason Constant
1:s var1 1 var1 1
2:s var2 1 var2 1
3:s var3 1 var3 1
4:s var4 0 0 1
5:s var5 0 0 1
6:s var6 0 0 1
7:s var7 0 0 1
8:s var8 0 0 1
9:s var9 0 0 1
10:s var10 0 0 1

When I run this model built according to each example, I get different results. Why?
Miina Kovanen
 
Posts: 12
Joined: Tue Nov 25, 2008 6:11 am
Location: University of Jyväskylä, Finland

Correction

Postby Miina Kovanen » Thu Jan 14, 2010 3:40 pm

Sorry, the model in the example above should be {snowseason+age+age*snowseason}
Miina Kovanen
 
Posts: 12
Joined: Tue Nov 25, 2008 6:11 am
Location: University of Jyväskylä, Finland

Postby Miina Kovanen » Fri Jan 15, 2010 3:53 am

A reply to myself. I found out that building the interaction in model {age+snowseason+age*snowseason} by using in DM for the interaction term code:

product(name of the age constraint in data, value for the season)

gives the same results as using:

product(var1,var3)

and is probably a correct way to build the interaction also in models in which the independent effects are not included.
Miina Kovanen
 
Posts: 12
Joined: Tue Nov 25, 2008 6:11 am
Location: University of Jyväskylä, Finland

Coding interaction term in Design Matrix Message

Postby gwhite » Fri Jan 15, 2010 8:09 pm

Miina:

Your first solution is incorrect:

1) I build the interaction with the product of colums -function:

Age Snowseason Age*Snowseason Constant
1:s var1 1 product(var1,var2) 1
2:s var2 1 product(var1,var2) 1
3:s var3 1 product(var1,var2) 1
4:s var4 0 product(var1,var2) 1
5:s var5 0 product(var1,var2) 1
6:s var6 0 product(var1,var2) 1
7:s var7 0 product(var1,var2) 1
8:s var8 0 product(var1,var2) 1
9:s var9 0 product(var1,var2) 1
10:s var10 0 product(var1,var2) 1


This is because you are always multipying var1 times var2 to create the interaction. If you had an individual variable called SnowSeason, then you could have created the following design matrix that would be correct:

Age Snowseason Age*Snowseason Constant
1:s var1 SnowSeason product(var1,SnowSeason) 1
2:s var2 SnowSeason product(var2,SnowSeason) 1
3:s var3 SnowSeason product(var3,SnowSeason) 1
4:s var4 SnowSeason product(var4,SnowSeason) 1
5:s var5 SnowSeason product(var5,SnowSeason) 1
6:s var6 SnowSeason product(var6,SnowSeason) 1
7:s var7 SnowSeason product(var7,SnowSeason) 1
8:s var8 SnowSeason product(var8,SnowSeason) 1
9:s var9 SnowSeason product(var9,SnowSeason) 1
10:s var10 SnowSeason product(var10,SnowSeason) 1


Your second solution is correct, because it duplicates the above design matrix without the individual covariate SnowSeason.

2) I build the interaction without using the product function:

Age Snowseason Age*Snowseason Constant
1:s var1 1 var1 1
2:s var2 1 var2 1
3:s var3 1 var3 1
4:s var4 0 0 1
5:s var5 0 0 1
6:s var6 0 0 1
7:s var7 0 0 1
8:s var8 0 0 1
9:s var9 0 0 1
10:s var10 0 0 1

Gary
gwhite
 
Posts: 340
Joined: Fri May 16, 2003 9:05 am


Return to analysis help

Who is online

Users browsing this forum: No registered users and 4 guests