
R version 2.15.0 (2012-03-30)
Copyright (C) 2012 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: x86_64-pc-mingw32/x64 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> ### Note: Simulations in Panel R20.11 take a long time
> 
> ###################################################
> ### code chunk: Chap20.4init
> ###################################################
> options(width = 65, digits = 5, show.signif.stars = FALSE)
> date()
[1] "Fri Mar 08 18:54:57 2013"
> 
> sessionInfo()
R version 2.15.0 (2012-03-30)
Platform: x86_64-pc-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=C                          
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods  
[7] base     
> 
> require(nlme)    #
Loading required package: nlme
> 
> data(armd, package="nlmeU")
> 
> lm3.form   <-                           # (12.9)
+      formula(visual ~ visual0 + time + treat.f) 
> fm16.5  <-     #update(fm16.4,          # M16.5 <- M16.4           
+      lme (lm3.form, 
+      random = list(subject = pdDiag(~time)),
+      weights = varPower(form = ~time), # 
+      data = armd)            
> fm16.5ml <- update(fm16.5, method = "ML")
> 
> 
> ###################################################
> ### code chunk: R20.11
> ###################################################
> library(nlmeU)
> simY <- simulateY(fm16.5ml, nsim = 1000, seed = 1238917)  # Simulated y from M16.1
> auxDt <- subset(armd,                    # Auxiliary data
+    select = c(subject, visual, visual0, time, treat.f))
> simYsumm <- 
+    apply(simY, 
+          MARGIN = 2,                     # Over columns
+          FUN = function(y){    
+             auxDt$visual <- y            # Dependent variable updated
+             auxFit <-                    # Update M16.1 with new y
+                update(fm16.5ml, data = auxDt)
+             summ <- summary(auxFit)      # Summary
+             beta <- fixef(summ)     
+             list(beta = beta)
+ })
> simYsumm[[1]]                            # beta for the 1st simulation
$beta
  (Intercept)       visual0          time treat.fActive 
      4.59395       0.90295      -0.24768      -3.94995 

> 
> 
> ###################################################
> ### code chunk: R20.12
> ###################################################
> betaE <- sapply(simYsumm,            # Matrix with betas
+   FUN = function(x) x$beta)
> rowMeans(betaE)                      # Empirical beta (see Panel R20.6b)
  (Intercept)       visual0          time treat.fActive 
      5.37646       0.90113      -0.24115      -2.66659 
> cov(t(betaE))                        # Emoirical Var(beta)
              (Intercept)     visual0        time treat.fActive
(Intercept)     4.7447722 -7.5371e-02 -3.5957e-03   -0.64417517
visual0        -0.0753712  1.3785e-03 -1.6726e-05    0.00072322
time           -0.0035957 -1.6726e-05  5.5794e-04    0.00183248
treat.fActive  -0.6441752  7.2322e-04  1.8325e-03    1.22061690
> 
> ## sessionInfo
> sessionInfo()
R version 2.15.0 (2012-03-30)
Platform: x86_64-pc-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=C                          
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods  
[7] base     

other attached packages:
[1] nlmeU_0.30-8 nlme_3.1-103

loaded via a namespace (and not attached):
[1] grid_2.15.0    lattice_0.20-6 tools_2.15.0  
> 
> proc.time()
   user  system elapsed 
 337.88    0.42  338.75 
