
R version 4.5.1 (2025-06-13 ucrt) -- "Great Square Root"
Copyright (C) 2025 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64

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.

  Natural language support but running in an English locale

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.

[Previously saved workspace restored]

> 
> ###################################################
> ### code chunk: Chap8init
> ###################################################
> options(width = 65, digits = 5, show.signif.stars = FALSE)
> date()
[1] "Mon Aug  4 20:08:43 2025"
> packageVersion("nlmeU")
[1] '0.75.0'
> packageVersion("nlme")
[1] '3.1.166'
> sessionInfo()
R version 4.5.1 (2025-06-13 ucrt)
Platform: x86_64-w64-mingw32/x64
Running under: Windows 11 x64 (build 22631)

Matrix products: default
  LAPACK version 3.12.1

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

time zone: America/New_York
tzcode source: internal

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

loaded via a namespace (and not attached):
[1] compiler_4.5.1
> data(armd, package = "nlmeU")
> 
> ## lm1.form was defined in Chapter 4
> lm1.form <- formula(visual ~ -1 + visual0 + time.f + treat.f:time.f )
> library(nlme)
> 
> ###################################################
> ### code chunk: R8.1
> ###################################################
> (val <- c("12wks" = 0.5, "24wks" = 2))  # delta1 = 1, delta2 = 0.5, delta3 = 2     
12wks 24wks 
  0.5   2.0 
> (fix <- c("52wks" = 3))                 # delta4 = 3 (fixed)
52wks 
    3 
> frm  <- formula(~1|time.f)              # time.f is a stratifying factor
> (vf0 <- 
+    varIdent(value = val,                # Var. function object defined... 
+             fixed = fix,
+             form  = frm)) 
Variance function structure of class varIdent with no parameters, or uninitialized
> (vf0i <- Initialize(vf0, armd))         # ... and initialized
Variance function structure of class varIdent representing
 4wks 12wks 24wks 52wks 
  1.0   0.5   2.0   3.0 
> 
> 
> ###################################################
> ### code chunk: R8.2a
> ###################################################
> coef(vf0i, unconstrained = FALSE, allCoef = TRUE) # All delta coefs
 4wks 12wks 24wks 52wks 
  1.0   0.5   2.0   3.0 
> coef(vf0i, unconstrained = FALSE, allCoef = FALSE)# Varying only
12wks 24wks 
  0.5   2.0 
> 
> 
> ###################################################
> ### code chunk: R8.2b
> ###################################################
> coef(vf0i, unconstrained = TRUE, allCoef = TRUE)  # All delta* coefs
[1] -0.69315  0.69315  1.09861
> coef(vf0i, unconstrained = TRUE, allCoef = FALSE) # Varying (default)
[1] -0.69315  0.69315
> coef(vf0i) <- c(-0.6, 0.7)                        # New coefs assigned   
> coef(vf0i, allCoef = TRUE)                        # All coefs printed
[1] -0.6000  0.7000  1.0986
> 
> 
> ###################################################
> ### code chunk: R8.3
> ###################################################
> summary(vf0i)               # Summary
Variance function:
 Structure: Different standard deviations per stratum
 Formula: ~1 | time.f 
 Parameter estimates:
   4wks   12wks   24wks   52wks 
1.00000 0.54881 2.01375 3.00000 
> formula(vf0i)               # Variance function formula
~1 | time.f
> getCovariate(vf0i)          # Variance covariate
NULL
> getGroupsFormula(vf0i)      # Formula for variance strata
~time.f
> length(stratum <-           # Length of stratum indicator
+          getGroups(vf0i)) 
[1] 867
> unique(stratum)             # Unique strata
[1] "4wks"  "12wks" "24wks" "52wks"
> stratum[1:6]                # First six observations
[1] "4wks"  "12wks" "4wks"  "12wks" "24wks" "52wks"
> varWeights(vf0i)[3:6]       # Variance weights 1/lambdai:(7.8)
   4wks   12wks   24wks   52wks 
1.00000 1.82212 0.49659 0.33333 
> logLik(vf0i)                # Contribution to the log-likelihood
'log Lik.' -227.83 (df=2)
> 
> ###### sessionInfo() with packages attached
> sessionInfo()
R version 4.5.1 (2025-06-13 ucrt)
Platform: x86_64-w64-mingw32/x64
Running under: Windows 11 x64 (build 22631)

Matrix products: default
  LAPACK version 3.12.1

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

time zone: America/New_York
tzcode source: internal

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

other attached packages:
[1] nlme_3.1-166

loaded via a namespace (and not attached):
[1] compiler_4.5.1 tools_4.5.1    grid_4.5.1     lattice_0.22-6
> detach(package:nlme)
> 
> proc.time()
   user  system elapsed 
   0.20    0.04    0.32 
