'2D Spline and Nearest-Neighbor Adjustment examples not running in sommer package
I recently installed the sommer
package, but the 2D Spline and nna examples provided would not run for me. I updated my version of R to see if that would resolve the issue, but it did not. These are the examples I have been trying to run:
2D Spline:
data(CPdata)
head(CPpheno)
CPgeno[1:4,1:4]
#### create the variance-covariance matrix
A <- A.mat(CPgeno) # additive relationship matrix
#### look at the data and fit the model
head(CPpheno)
mix1 <- mmer2(Yield~1,
random=~g(id)
+ Rowf + Colf
+ spl2D(Row,Col),
rcov=~units,
G=list(id=A), silent=TRUE,
data=CPpheno)
summary(mix1)
###Warning message: In data(CPdata) : data set ‘CPdata’ not found
Nearest-Neighbor Adjustment
Found the dataset in agridat by doing a web search for yates.oats, otherwise warning states yates.oats not found
library(agridat)
# NOT RUN {
data(yates.oats)
head(yates.oats)
newyates <- nna(yates.oats, trait="Y")
head(newyates)
plot(newyates$Y, newyates$nnx)
cor(newyates$Y, newyates$nnx)
#### now fit the models and compare #####
m3 <- mmer2(fixed=Y ~ V+N+V:N, random = ~ B + B:MP,
data = yates.oats)
yates.oats$res <- residuals(m3)
m4 <- mmer2(fixed=Y ~ V+N+V:N + nnx, random = ~ B + B:MP,
data = newyates)
newyates$res <- residuals(m4)
# library(lattice)
# wireframe(res~row*col,yates.oats)
# wireframe(res~row*col,newyates)
# }
Error Message:
library(agridat)
data(yates.oats)
head(yates.oats)
row col yield nitro gen block grain straw
1 16 3 80 0 GoldenRain B1 20.00 28.00
2 12 4 60 0 GoldenRain B2 15.00 25.00
3 3 3 89 0 GoldenRain B3 22.25 40.50
4 14 1 117 0 GoldenRain B4 29.25 28.75
5 8 2 64 0 GoldenRain B5 16.00 32.00
6 5 2 70 0 GoldenRain B6 17.50 27.25
newyates <- nna(yates.oats, trait="Y")
Error in nna(yates.oats, trait = "Y") : could not find function "nna"
Solution 1:[1]
Please use the documentation from your current version. If you have the newest version installed you may notice that the mmer2() function doesn't exist anymore. If you check the recent documentation from the spl2D() function is this:
data(DT_cpdata)
DT <- DT_cpdata
GT <- GT_cpdata
MP <- MP_cpdata
A <- A.mat(GT)
mix <- mmer(Yield~1,
random=~vs(id, Gu=A) +
vs(Rowf) +
vs(Colf) +
spl2Db(Row,Col),
rcov=~units,
data=DT)
summary(mix)$varcomp
That should work well. The error seems to be that you use a new version of sommer with code from an old script. All the best.
Eduardo
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Kevin Wright |