########################
set.seed(1)
x<-seq(0,1,0.01)
rho<-sample(x,1000,replace=T)

##no_child<-sample(1:10,1000,replace=T)
##sum(no_child)

m_wt<-rnorm(1000,0,1)
summary(m_wt)

no_child<-rpois(1000,2)
sum_child<-sum(no_child)

bwt<-rnorm(sum_child,0,1)
m_wt_long<-rep(m_wt,no_child)

v<-rnorm(1000,0,1)
v_long<-rep(v,no_child)
g<-rnorm(sum_child,0,1)
wt_2<-(3.1+(0.02*m_wt_long)+(0.03*bwt)+0.3*(((0.2*v_long)+(sqrt(1-0.04)*g))))
id<-rep(1:1000,no_child)
d1<-data.frame(id,bwt,m_wt_long,v_long,g)

##### Loading packages
library(nlme)
library(lme4)
library(mlmRev)

##Fitting multilevel model with interest on the random slope only
fit_x4_sl<-lme(wt_2~bwt,random = ~bwt|id, data=d1)
summary(fit_x4_sl)



## Simulation for 10000 with interest on random slope only
est_int<-NULL
est_slope<-NULL

se_int<-NULL
se_slope<-NULL

t_int<-NULL
t_slope<-NULL

p_int<-NULL
p_slope<-NULL

## rho=(0,1) with 0.01 spacing ie 0, 0.01, 0.02, ..., 1

rho<-seq(0,1,by=0.01)

for(i in 1:length(rho))
{
for (j in 1:10000)
{
d1$wt_2<-(3.1+(0.02*m_wt_long)+(0.03*bwt)+0.3*(((rho[i]*v_long)+(sqrt(1-(rho[i]^2))*g))))
fit_x4_sl<-lme(fixed = wt_2~bwt,data=d1,random = ~ bwt|id)
p_slope[i]<-summary(fit_x4_sl)$tTable[2,5]

}

}

After running the above codes, below is the error message:

Error in solve.default(estimates[dimE[1] - (p:1), dimE[2] - (p:1), drop = FALSE]) : 
  system is computationally singular: reciprocal condition number = 1.43197e-16

Please, kindly help me rectify this problem in my codes.
Many thanks in advance.


Kind regards.
  
Justice Moses K. Aheto
(Chief Executive Officer)
Statistics & Analytics Consultancy Services Ltd.
E-mail: justiceaheto@yahoo.com
Mobile:00447417589148
	[[alternative HTML version deleted]]

