Skip to content

Commit

Permalink
Fix broken example in vignette
Browse files Browse the repository at this point in the history
  • Loading branch information
kwstat committed Oct 28, 2024
1 parent 0e9e632 commit 6a7d28a
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 54 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: gge
Title: Genotype Plus Genotype-by-Environment Biplots
Version: 1.8
Version: 1.9
Authors@R: c(
person("Kevin", "Wright", , "[email protected]", role = c("aut", "cre", "cph"),
comment = c(ORCID = "0000-0002-0617-8673")),
Expand Down
9 changes: 9 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,18 @@ Bootstrap testing for PCs (Forkman 2019 paper)
Bootstrap conf int


# gge 1.9 (2024.10.28)

* Documentation pages now created via Github Actions.

* Changed vignette chunk option `eval=0` to `eval=FALSE` to maybe fix error when `revdep`-checking `agridat`.

* Fixed vignette example showing the difference between genotype-focused and environment-focused biplots.

# gge 1.8 (2023-08-20)

* Switch from GPL3 to MIT license.

* Fix docType issue as requested by CRAN.


Expand Down
37 changes: 26 additions & 11 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# gge 1.9

## Test environments & results

* Local R 4.4.1 on Windows 11
* WinBuilder R-devel
* WinBuilder R-oldrelease

Checked OK

## revdepcheck results

No problems with revdep `agridat`.

# gge 1.8

* Switch license from GPL3 to MIT.
Expand All @@ -6,8 +20,8 @@
## Test environments & results

* Local R 4.3.1 on Windows 10
* WinBuilder devel
* rhub::check_for_cran()
* WinBuilder R-devel
* Rhub

No problems.

Expand Down Expand Up @@ -73,8 +87,8 @@ No ERRORs in agridat, GGEBiplots.
## test environments

* local R 3.5.0 on Windows 7
* win-builder release
* win-builder devel
* win-builder R-release
* win-builder R-devel

## R CMD check results

Expand All @@ -89,8 +103,8 @@ No ERRORs in agridat, GGEBiplots.
## test environments

* local R 3.4.2 on Windows 7
* win-builder release
* win-builder devel
* win-builder R-release
* win-builder R-devel

## R CMD check results

Expand All @@ -110,8 +124,8 @@ Possibly mis-spelled words in DESCRIPTION:
## test environments

* local R 3.4.0 on Windows 7
* win-builder release
* win-builder devel
* win-builder R-release
* win-builder R-devel

## R CMD check results

Expand All @@ -135,8 +149,8 @@ None.
## test environments

* local R 3.3.1 on Windows 7
* win-builder release
* win-builder devel
* win-builder R-release
* win-builder R-devel

## R CMD check results

Expand Down Expand Up @@ -164,7 +178,8 @@ package.
## test environments

* local R 3.2.3 on Windows 7
* win-builder (devel & release)
* win-builder R-devel
* win-builder R-release

## R CMD check results

Expand Down
2 changes: 1 addition & 1 deletion man/RedGrayBlue.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/gge.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

97 changes: 57 additions & 40 deletions vignettes/gge_examples.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -37,31 +37,29 @@ biplot(m1, main="yan.winterwheat - GGE biplot",
```

Many people prefer to use 'standardized' biplots, in which the data for each environment has been centered and scaled. For standardized biplots, a unit circle is drawn. Environment vectors that reach out to the unit circle are perfectly represented in the two dimensional plane.

```{r}
m2 <- gge(dat1, yield~gen*env, scale=TRUE)
biplot(m2, main="yan.winterwheat - GGE biplot",
flip=c(1,1), origin=0)
```

As seen above, the environment vectors are fairly long, so that relative performance of genotypes in environments can be assessed with reasonable accuracy. In contrast, a biplot based on principal components 2 and 3 has shorter vectors which should not be interpreted.

```{r}
biplot(m2, main="yan.winterwheat - GGE biplot - PC 2 & 3",
comps=c(2,3), flip=c(1,1), origin=0)
```
@laffont2007numerical showed how to partition the sums-of-squares
simultaneously along the principal component axes and along 'G' and 'GxE'
axes.

@laffont2007numerical showed how to partition the sums-of-squares simultaneously along the principal component axes and along 'G' and 'GxE' axes.

```{r mosaic}
plot(m1, main="yan.winterwheat")
```

The mosaic plot above shows that the first principal component axis is
capturing almost all of the variation between genotypes, so that a projection
of the genotype markers onto the first principal component axis is a good
overall representation of the rankings of the genotypes.
The mosaic plot above shows that the first principal component axis is capturing almost all of the variation between genotypes, so that a projection of the genotype markers onto the first principal component axis is a good overall representation of the rankings of the genotypes.

@laffont2013genotype presented GGB (genotype plus genotype-by-block of
environments) biplots, which are useful to enhance the view of
mega-environments consisting of multiple locations.
@laffont2013genotype presented GGB (genotype plus genotype-by-block of environments) biplots, which are useful to enhance the view of mega-environments consisting of multiple locations.

```{r ggb}
library(agridat)
Expand All @@ -78,55 +76,74 @@ library(gge)
# Specify env.group as column in data frame
m3 <- gge(dat2, yield~gen*loc, env.group=eg, scale=FALSE)
biplot(m3, main="crossa.wheat - GGB biplot")
```

# How to modify the "focus" of a biplot

Let `X` be a genotype-by-environment matrix.

Let the Singular Value Decomposition be `X = USV'`.

Let the NIPALS decomposition be `X = TLP'`. DANGER, some algorithms do not factor L out of T.

```{r , eval=FALSE}
library(agridat)
library(reshape2)
library(nipals)
dat3 <- agridat::yan.winterwheat
dat3 <- acast(dat3, gen~env, value.var="yield")
dat3 <- scale(dat3, center=TRUE, scale=FALSE)
Xsvd <- svd(dat3)
Xnip <- nipals(dat3, center=FALSE, scale=FALSE)
U <- Xsvd$u
S <- diag(Xsvd$d)
V <- Xsvd$v
T <- Xnip$scores
Lam <- diag(Xnip$eig)
P <- Xnip$loadings
```

## Biplots with genotype focus

## Biplot with genotype focus
To obtain a *genotype-focused* biplot the eigenvalues are associated with `U`.

When $\bf X$ is a genotype-by-environment matrix, a *genotype-focused* biplot is easily obtained. The genotype coordinates are can be obtained from the SVD using the first two columns of $\bf G_{gf} = U S$ or equivalently from NIPALS $\bf G_{gf} = T$.
The genotype coordinates are can be obtained from the SVD using the first two columns of `U*S` or equivalently from NIPALS `T*Lam`.

```{r , eval=0}
u <- Xc.svd$u
s <- diag(Xc.svd$d)
v <- Xc.svd$v
(u %*% s)[,1:2]
t[,1:2]
```{r, eval=FALSE}
(U %*% S)[ , 1:2]
(T %*% Lam)[ , 1:2]
```
The environment coordinates are the first two columns of
$\bf E_{gf} = V$ (from the SVD) or
$\bf E_{gf} = P$ (from NIPALS).
```{r , eval=0}
v[,1:2]
p[,1:2]

The environment coordinates are the first two columns of `V` (from the SVD) or `P` (from NIPALS).

```{r , eval=FALSE}
V[ , 1:2]
P[ , 1:2]
```

## Biplot with environment focus

For an *environment-focused* biplot, a little more effort is needed as the eigenvalues from NIPALS are also required. The square root of the NIPALS eigenvalues are the same as the SVD singular values.
To obtain an *environment-focused* biplot the eigenvalues are associated with `V`.

The genotype coordinates are the first two columns of `U` (from SVD) or `T` (from NIPALS).

The genotype coordinates are the first two columns of
$\bf G_{ef} = U$ (from SVD) or
$\bf G_{ef} = T \Lambda^{-1/2}$ from NIPALS, where
$\bf \Lambda$ is a diagonal matrix of the eigenvalues.
```{r , eval=0}
u[,1:2]
sv <- sqrt(Xc.pca$eig)
(t %*% diag(1/sv))[,1:2]
```{r , eval=FALSE}
U[ , 1:2]
T[ , 1:2]
```
The environment coordinates are
$\bf E_{ef} = V$ (from SVD) or
$\bf E_{ef} = P \Lambda^{1/2}$ (from NIPALS):
```{r , eval=0}
(v %*% s)[,1:2]
(p %*% diag(sv))[,1:2]

The environment coordinates are `S*V` (from SVD) or `Lam*P` (from NIPALS).

```{r , eval=FALSE}
(S %*% V)[ , 1:2]
(Lam %*% P)[ , 1:2]
```

## Comments on biplots

Note that GGE biplots are environment-focused. In particular, this provides the interpretation that the correlation of genotype performance in two environments is approximated by the cosine of the angle between the vectors for those two environments.

The SVD and NIPALS methods provide the same principal components for complete-data, except that a principal component from SVD and the corresponding principal component from NIPALS might point in opposite directions (differ by a factor of $-1$) as in some of the examples above. The corresponding biplots would therefore be mirror-reversed along that component. For biplots from SVD and NIPALS that are visually consistent, each principal component can be directed to point in a direction that is positively correlated with the overall genotype means. In other words, if the correlation of the genotype means and the ordinate of the genotypes along the principal component is negative, the principal component is multiplied by $-1$.
The SVD and NIPALS methods provide the same principal components for complete-data, except that a principal component from SVD and the corresponding principal component from NIPALS might point in opposite directions (differ by a factor of `-1` as in some of the examples above. The corresponding biplots would therefore be mirror-reversed along that component. For biplots from SVD and NIPALS that are visually consistent, each principal component can be directed to point in a direction that is positively correlated with the overall genotype means. In other words, if the correlation of the genotype means and the ordinate of the genotypes along the principal component is negative, the principal component is multiplied by `-1`.

As with all biplots, the environment vectors can be arbitrarily scaled so that the genotypes and environments uses a similar amount of area on the plot. The algorithm that physically centers the biplot and scales it on the page is not perfect and has opportunities for improvement.

Expand Down

0 comments on commit 6a7d28a

Please sign in to comment.