Time-varying individual covariates was all simple prior to adding Robust Design models. With RD, the covariates can either align with sessions (primary), times(secondary), or with session-time values.
Here is the logic the code uses when it encounters a variable name in the formula that is not in the design data. I use cov as the variable name used in the formula. If there is a variable called cov then it skips everything below because the covariate is static (not time-varying).
1) First it looks in the data where individual covariates are for variables with names covst where cov is base name of variable in formula, s is session and t is time. If each of those variables is available in the data then it assumes that cov depends on session and time.
2) If not then it looks for covs in the data and if it finds all of those then it assumes they are session dependent.
3) If any of those are missing then it constructs covt and if all of those are available then it assumes time dependence.
4) If none of the above then the code whines at you that it can't find the variable you used. Something like:
Error in make.mark.model(data.proc, title = title, parameters = model.parameters, :
Error: Variable AirT used in formula is not defined in data
What I may need to add is a way to force the use of time when the #sesssions<=#times. In that case,
the problem will be that because it first tries to match it to session, there will be a covariate name for each session if the sequence of session numbers is the same as the times (what happens when begin.time=1 the default). I guess I could add code to see whether there are more than the # of sessions, but that will still
fall down if #sessions=#times.
Some suggestions for this are:
1) change the value of begin.time (used to label sessions in RD model) (see example below)
2) use cov_s_t approach but then some of your covariate values are redundant.
3) modify session values in your ddl so they don't include time values and rename covariates so they match time and not session. This is what
setting begin.time does.
I'm not entirely sure how to get around this problem other than the suggestions above but I'm not sure how often it happens that you have a covariate that is constant across secondary sampling occasions. Feedback? I could have another attribute for a formula that specified which variable names are
time, session or session-time dependent. I'll give this some more thought if folks think this would be useful.
Here is an example of Tyler's design data when default begin.time=1 is used and begin.time=0 is used. Now session numbers are different than times and the code won't get confused because the covariates will have to be named cov0,cov1,cov2 to be session dependent and cov1,cov2,...cov6 to be time dependent.
- Code: Select all
> LIBL.ddl$p
par.index model.index group time session Time pA pB pC
1 1 6 1 1 1 0 1 0 0
2 2 7 1 2 1 1 1 0 0
3 3 8 1 3 1 2 1 0 0
4 4 9 1 1 2 0 1 1 0
5 5 10 1 2 2 1 1 1 0
6 6 11 1 3 2 2 1 1 0
7 7 12 1 1 3 0 1 0 1
8 8 13 1 2 3 1 1 0 1
9 9 14 1 3 3 2 1 0 1
10 10 15 1 4 3 3 1 0 1
11 11 16 1 5 3 4 1 0 1
12 12 17 1 6 3 5 1 0 1
> LIBL.process=process.data(LIBL.inp, model="RDOccupEG", time.intervals=c(0,0,1,0,0,1,0,0,0,0,0),begin.time=0)
> LIBL.ddl=make.design.data(LIBL.process)
> LIBL.ddl$p
par.index model.index group time session Time
1 1 6 1 1 0 0
2 2 7 1 2 0 1
3 3 8 1 3 0 2
4 4 9 1 1 1 0
5 5 10 1 2 1 1
6 6 11 1 3 1 2
7 7 12 1 1 2 0
8 8 13 1 2 2 1
9 9 14 1 3 2 2
10 10 15 1 4 2 3
11 11 16 1 5 2 4
12 12 17 1 6 2 5
regards --jeff