# NOT RUN {
## Analyse wheat dat using asreml and asremlPlus (see also the Wheat Vignette)
## Set up for analysis
library(dae)
library(asreml)
library(asremlPlus)
## use ?Wheat.dat for data set details
data(Wheat.dat)
# Fit initial model
current.asr <- asreml(yield ~ Rep + WithinColPairs + Variety,
random = ~ Row + Column + units,
residual = ~ ar1(Row):ar1(Column),
data=Wheat.dat)
summary(current.asr)
# Intialize a testing sequence by loading the current fit into an asrtests object
current.asrt <- as.asrtests(current.asr, NULL, NULL)
# Check for and remove any boundary terms
current.asrt <- rmboundary(current.asrt)
#Unbind Rep, Row and Column components and reload into an asrtests object
current.asr <- setvarianceterms(current.asr$call,
terms = c("Rep", "Rep:Row", "Rep:Column"),
bounds = "U")
current.asrt <- as.asrtests(current.asr, NULL, NULL)
current.asrt <- rmboundary(current.asrt)
summary(current.asrt$asreml.obj)$varcomp
print(current.asrt, which = "testsummary")
print(current.asrt, which = "pseudoanova")
# Check term for within Column pairs (a post hoc covariate)
current.asrt <- testranfix(current.asrt, "WithinColPairs", drop.fix.ns=TRUE)
# Test nugget term
current.asrt <- testranfix(current.asrt, "units", positive=TRUE)
# Test Row autocorrelation
current.asrt <- testresidual(current.asrt, "~ Row:ar1(Column)",
label="Row autocorrelation", simpler=TRUE)
# Test Col autocorrelation (depends on whether Row autocorrelation retained)
(p <- getTestPvalue(current.asrt, label = "Row autocorrelation"))
{ if (p <= 0.05)
current.asrt <- testresidual(current.asrt, "~ ar1(Row):Column",
label="Col autocorrelation",
simpler=TRUE, update=FALSE)
else
current.asrt <- testresidual(current.asrt, "~ Row:Column",
label="Col autocorrelation",
simpler=TRUE, update=FALSE)
}
# Output the results
print(current.asrt, which = "test")
info <- infoCriteria(current.asrt$asreml.obj)
summary(current.asrt$asreml.obj)$varcomp
# Get current fitted asreml object and update to include standardized residuals
current.asr <- current.asrt$asreml.obj
current.asr <- update(current.asr, aom=TRUE)
Wheat.dat$res <- residuals(current.asr, type = "stdCond")
Wheat.dat$fit <- fitted(current.asr)
#### Do diagnostic checking
# Do residuals-versus-fitted values plot
with(Wheat.dat, plot(fit, res))
#Produce variogram and variogram faces plot (Stefanaova et al, 2009)
plot.varioGram(varioGram(current.asr))
faces <- variofaces(current.asr, V=NULL, units="addtores",
maxiter=50, update = FALSE)
#Get Variety predictions, sorted in increasing order for the predicted values,
#and all pairwise prediction differences and p-values
Var.diffs <- predictPlus(classify = "Variety",
asreml.obj=current.asr,
error.intervals="halfLeast",
wald.tab=current.asrt$wald.tab,
sortFactor = "Variety",
tables = "predictions")
print(Var.diffs, which = c("differences", "p.differences"))
# Plot the Variety predictions, with halfLSD intervals, and the p-values
plotPredictions(Var.diffs$predictions,
classify = "Variety", y = "predicted.value",
error.intervals = "half")
plotPvalues(Var.diffs)
# }
Run the code above in your browser using DataLab