Simulation of intra-subject variability [Regulatives / Guidelines]
All hands on deck!
I hope this illustrates the issue of no treament differences when fixed effects between subjects are zerod or some scatter in fixed effects between subjects exists:
Have a good day. As always it is prolly wrong and bugged.

EM
I hope this illustrates the issue of no treament differences when fixed effects between subjects are zerod or some scatter in fixed effects between subjects exists:
Per=c(1,2,3, 1,2,3, 1,2,3, 1,2,3, 1,2,3, 1,2,3, 1,2,3, 1,2,3, 1,2,3, 1,2,3, 1,2,3, 1,2,3)
Subj=c(1,1,1, 2,2,2, 3,3,3, 4,4,4, 5,5,5, 6,6,6, 7,7,7, 8,8,8, 9,9,9, 10,10,10, 11,11,11, 12,12,12)
Trt=c(1,2,3,1,2,3,1,3,2,1,3,2,2,1,3,2,1,3,2,3,1,2,3,1,3,2,1,3,2,1,3,1,2,3,1,2)
Seq=c("ABC","ABC","ABC","ABC","ABC","ABC","ACB","ACB","ACB","ACB","ACB",
"ACB","BAC","BAC","BAC","BAC","BAC","BAC","BCA","BCA","BCA","BCA","BCA",
"BCA","CBA","CBA","CBA","CBA","CBA","CBA","CAB","CAB","CAB","CAB","CAB","CAB")
Seq=sort(rep(1:6, 6))
SubjE1=c(rep(0,12)) ##fixed effects for subjs: zero for all 12
SubjE2=c(9*runif(12)) ##variation in fixed effects between subjects
TrtE=c(9.876, 8.765, 7.654) ## some fixed treatment effects
PerE=c(1.5, 1.5, 1.5) ##some fixed period effects all same
SeqE=c(2.0,2.0, 2.0, 2.0, 2.0, 2.0) ##some fixed sequence effects all same
set.seed(12041958)
rany = rnorm(36, mean=0, sd=2) ##our single error
Y1=c(1:36)
Y2=c(1:36)
for (i in 1:36)
{
indexTrt=Trt[i];
indexSubj=Subj[i];
indexPer=Per[i];
indexSeq=Seq[i];
rany = rnorm(1, mean=0, sd=2)
Y1[i] = TrtE[indexTrt] + SeqE[indexSeq] + SubjE1[indexSubj] + PerE[indexPer]+rany
Y2[i] = TrtE[indexTrt] + SeqE[indexSeq] + SubjE2[indexSubj] + PerE[indexPer]+rany
}
m1=lm(Y1~0+as.factor(Trt) + as.factor(Seq)+ as.factor(Subj) + as.factor(Per))
m2=lm(Y2~0+as.factor(Trt) + as.factor(Seq)+ as.factor(Subj) + as.factor(Per))
anova(m1)
cat("m1 no subject effect. They do not differ in this scenario.\n")
anova(m2)
cat("m2 p significant for subjects. They differ in this scenario.\n")
cat("m1 models all subjects fixed effects as zero.\n")
cat("m1 difference between treat effects 1 and 3:", coef(m1)[1]-coef(m1)[3], "\n")
cat("m1 residual error:", summary(m1)$sigma, "\n")
cat("m3 models subjects effects as fixed but different between subjects.\n")
cat("m2 difference between treat effects 1 and 3:", coef(m2)[1]-coef(m2)[3], "\n")
cat("m2 residual error:", summary(m2)$sigma, "\n")
#
#
Have a good day. As always it is prolly wrong and bugged.

EM
—
Pass or fail!
ElMaestro
Pass or fail!
ElMaestro
Complete thread:
- Anticonservativism?! ElMaestro 2010-02-06 17:10 [Regulatives / Guidelines]
- Conservativism? Helmut 2011-11-03 21:12
- In hindsight... ElMaestro 2011-11-03 21:43
- In hindsight... Helmut 2011-11-04 01:56
- In hindsight... ElMaestro 2011-11-04 08:41
- rlnorm simulates what? d_labes 2011-11-04 09:40
- Oops. Helmut 2011-11-04 16:05
- Oops. ElMaestro 2011-11-04 16:22
- Simulation of intra-subject variability d_labes 2011-11-07 11:16
- Simulation of intra-subject variabilityElMaestro 2011-11-08 11:02
- Simulation of intra-subject variability d_labes 2011-11-07 11:16
- Oops. Oops. d_labes 2011-11-25 13:54
- Another Oops. Helmut 2011-11-25 14:23
- Oops. ElMaestro 2011-11-04 16:22
- Oops. Helmut 2011-11-04 16:05
- In hindsight... Helmut 2011-11-04 01:56
- In hindsight... ElMaestro 2011-11-03 21:43
- Simul Ants questions d_labes 2011-11-04 15:46
- Simul Ants questions ElMaestro 2011-11-04 16:06
- Simul Ants questions Helmut 2011-11-04 16:09
- Liberal Conservatives d_labes 2011-11-08 11:31
- Liberal Conservatives martin 2011-11-08 20:50
- Liberal Conservatives Helmut 2011-11-08 22:56
- intra-subject correlation martin 2011-11-09 09:01
- intra-subject correlation Helmut 2011-11-25 17:16
- intra-subject correlation martin 2011-11-09 09:01
- Liberal Conservatives Helmut 2011-11-08 22:56
- Liberal Conservatives martin 2011-11-08 20:50
- Conservativism? Helmut 2011-11-03 21:12