Running examples in ‘agriTutorial-Ex.R’ failed
The error most likely occurred in:

> base::assign(".ptime", proc.time(), pos = "CheckExEnv")
> ### Name: example4
> ### Title: Example 4: One qualitative treatment factor with repeated
> ###   measurements over time.
> ### Aliases: example4
> 
> ### ** Examples
> 
> 
> ## *************************************************************************************
> ##                       How to run the code
> ## *************************************************************************************
> 
> ## Either type example("example4") to run ALL the examples succesively
> ## or copy and paste examples sucessively, as required
> 
> ## *************************************************************************************
> ##                          Options and required packages
> ## *************************************************************************************
> 
> options(contrasts = c('contr.treatment','contr.poly'))
> require(nlme)
Loading required package: nlme
> 
> ## *************************************************************************************
> ##            Section 1:  Polynomials for weeks and blocks contrasts
> ## *************************************************************************************
> 
> sorghum$rawWeeks = poly(sorghum$varweek, degree = 4, raw = TRUE)
> sorghum$polWeeks = poly(sorghum$varweek, degree = 4, raw = FALSE)
> sorghum$polBlocks = poly(sorghum$varblock, degree = 4, raw = FALSE)
> sorghum$factblock = factor(sorghum$varblock)
> 
> ## *************************************************************************************
> ## Section 2: Various correlation models assuming full factorial blocks and weeks model
> ## *************************************************************************************
> 
> AIC = NULL
> logLik = NULL
> Model = c("ID", "CS", "AR(1)", "AR(1) + nugget", "UN")
> 
> ## independent uncorrelated random plots
> full_indy = gls(y ~ factweek * (Replicate + variety), sorghum)
> anova(full_indy)
Denom. DF: 60 
                   numDF  F-value p-value
(Intercept)            1 80947.08  <.0001
factweek               4   220.90  <.0001
Replicate              4   358.86  <.0001
variety                3   334.87  <.0001
factweek:Replicate    16     1.82  0.0495
factweek:variety      12     4.48  <.0001
> AIC = c(AIC, AIC(full_indy))
> logLik = c(logLik, logLik(full_indy))
> 
> ## corCompSymm compound symmetry
> corCompSymm = gls(y ~ factweek * (Replicate + variety),
+ corr = corCompSymm(form = ~ varweek|factplot), sorghum)
> anova(corCompSymm)
Denom. DF: 60 
                   numDF   F-value p-value
(Intercept)            1 21284.930  <.0001
factweek               4   738.198  <.0001
Replicate              4    94.361  <.0001
variety                3    88.053  <.0001
factweek:Replicate    16     6.077  <.0001
factweek:variety      12    14.975  <.0001
> AIC = c(AIC, AIC(corCompSymm))
> logLik = c(logLik, logLik(corCompSymm))
> Variogram(corCompSymm)
     variog dist n.pairs
1 0.1458280    1      80
2 0.1805148    2      60
3 0.2136222    3      40
4 0.2433676    4      20
> 
> ## corExp without nugget
> corExp = gls(y ~ factweek * (Replicate + variety),
+  corr = corExp(form = ~ varweek|factplot), sorghum)
> anova(corExp)
Denom. DF: 60 
                   numDF   F-value p-value
(Intercept)            1 26108.428  <.0001
factweek               4   272.514  <.0001
Replicate              4   112.786  <.0001
variety                3   102.241  <.0001
factweek:Replicate    16     3.206   5e-04
factweek:variety      12    10.297  <.0001
> AIC = c(AIC, AIC(corExp))
> logLik = c(logLik, logLik(corExp))
> Variogram(corExp)
     variog dist n.pairs
1 0.1525443    1      80
2 0.1888286    2      60
3 0.2234608    3      40
4 0.2545762    4      20
> 
> ##  corExp with nugget
> corExp_nugget = gls(y ~ factweek * (Replicate + variety),
+  corr = corExp(form = ~ varweek|factplot, nugget = TRUE), sorghum)
> anova(corExp_nugget)
Denom. DF: 60 
                   numDF   F-value p-value
(Intercept)            1 22278.120  <.0001
factweek               4   447.078  <.0001
Replicate              4    97.680  <.0001
variety                3    88.735  <.0001
factweek:Replicate    16     4.220  <.0001
factweek:variety      12    12.578  <.0001
> AIC = c(AIC, AIC(corExp_nugget))
> logLik = c(logLik, logLik(corExp_nugget))
> Variogram(corExp)
     variog dist n.pairs
1 0.1525443    1      80
2 0.1888286    2      60
3 0.2234608    3      40
4 0.2545762    4      20
> 
> ##  corSymm unstructured
> corSymm = gls(y ~ factweek * (Replicate + variety), corr = corSymm(form = ~ 1|factplot),
+  weights = varIdent(form = ~ 1|varweek), sorghum)
> anova(corSymm)
Denom. DF: 60 
                   numDF  F-value p-value
(Intercept)            1 57534.14  <.0001
factweek               4   594.16  <.0001
Replicate              4   217.57  <.0001
variety                3   144.72  <.0001
factweek:Replicate    16     4.04  <.0001
factweek:variety      12    12.18  <.0001
> AIC = c(AIC, AIC(corSymm))
> logLik = c(logLik, logLik(corSymm))
> Variogram(corSymm)
     variog dist n.pairs
1 0.1421985    1      80
2 0.1789136    2      60
3 0.2110624    3      40
4 0.2797197    4      20
> 
> ##  Table 11 Comparison of log Likelihood and AIC statistics for different correlation structures
> dAIC = AIC - AIC[4]
> logLik = -2 * logLik
> dlogLik = logLik - logLik[4]
> AICtable = data.frame(Model, round(logLik, 2), round(dlogLik, 2), round(AIC, 2), round(dAIC, 2))
> colnames(AICtable) = c("Covar_Model", "-2logLr", "-diff2logLr", "AIC", "diffAIC")
> AICtable
     Covar_Model -2logLr -diff2logLr   AIC diffAIC
1             ID   -3.74       44.78 78.26   40.78
2             CS  -45.62        2.90 38.38    0.90
3          AR(1)  -45.96        2.57 38.04    0.57
4 AR(1) + nugget  -48.52        0.00 37.48    0.00
5             UN  -62.90      -14.38 47.10    9.62
> 
> ## *************************************************************************************
> ##  Section 3: Factorial block and variety effects assuming full polynomial week effects
> ## *************************************************************************************
> 
> ## Table A2 (cf Table 14) Sequential Wald tests for full model sorghum data
> pol_Wald =
+ gls(y ~ (factblock+variety) * (rawWeeks[,1] + rawWeeks[,2] + polWeeks[,3] + polWeeks[,4]),
+ corr = corExp(form = ~ varweek | factplot, nugget = TRUE), sorghum)
Error in call[[1L]] : object of type 'symbol' is not subsettable
Calls: gls ... model.frame.default -> makepredictcall -> makepredictcall.poly -> eval
Execution halted