Dear R group
 
Isimulate
100 data sets, each data set consists of 50000 observations (X,
Y) and 100 groups, each group contains 500 observations (data file=indiv).
Then I use the simulated population to draw a sample of 25 observations from 5
groups (s.grp) (5 observations from each group (p)) (data
file=indiv.str). And ,I am doing lmer on
the drawing sample with these two variables Y & X and group  as random effect. I estimate the slope of the
model of y on x.  But, I have a problem
which is the difference between the estimated slope (beta) and the real
value (r.beta=0.2) is sometimes large and I do not know the reason.
 
The program code is as follows:
hh=100                             * the
number of simulated data sets
beta<-rep(NA,hh)              * the estimated values of the
slope of the model
for (h in 1:hh){
n=50000                           * the total size of the simulated population
grp=100                          * the number of groups of the simulated
population
s.grp=5                           * the number of sampled groups from the
simulated popualtion
p=5                                *
the number of sampled observations  from
each group of the sampled groups
r.beta=0.2                        * the real value of
beta 
x=c(0)
y=c(0)
group=c(0)
e=c(0)                            * the error term within
each group
u=c(0)                            * the error term
between the groups
for (j in 1:100){
u[j] <- rnorm (1,0,1)
for (i in 1:500){
group[i+j*500-500]=j
e[i+j*500-500]<-rnorm(1,0,1)
x[i+j*500-500]=rnorm(1,3,1)
y[i+j*500-500]=2+b*x[i+j*500-500]+e[i+j*500-500]+u[j]}}
indiv<- data.frame(group,x,y)
s.id<-sample(1:100,s.grp)
str.rows<-c(0)
r1<-c(0)
r2<-c(0)
for (j in 1:s.grp){
r2[j]=500*s.id[j]
r1[j]=r2[j]-500+1
for (i in 1:p){
str.rows[i+j*p-p] <-c(sample(r1[j]:r2[j],1))}}
str <-indiv[str.rows,]
indiv.str=data.frame(str$group,str$x,str$y)
names(indiv.str)<-c("group","x","y”)
fcn=lmer(y~x+(1|group),data=indiv.str)
beta[h]<-fixef(fcn)["x"]}

many thanks
mervat

	[[alternative HTML version deleted]]

