---
title: "Data Analysis with selection.index"
author: "Zankrut Goyani"
date: "`r Sys.Date()`"
time: "`r Sys.time()`"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Data Analysis with selection.index}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
```

The aim of most plant breeding program is simultaneous improvement of several characters. An objective method involving simultaneous selection for several attributes then becomes necessary. It has been recognized that most rapid improvements in the economic value is expected from selection applied simultaneously to all the characters which determine the economic value of a plant, and appropriate assigned weights to each character according to their economic importance, heritability and correlations between characters. So the selection for economic value is a complex matter. If the component characters are combined together into an index in such a way that when selection is applied to the index, as if index is the character to be improved, most rapid improvement of economic value is excepted. Such an index was first proposed by Smith (1937) based on the Fisher's (1936) "discriminant function". In this package selection index is calculated based on the Smith (1937) selection index method (Dabholkar, 1999). For more information refer **Elements of Bio Metrical GENETICS by A. R. Dabholkar.**
```{r setup}
library(selection.index)
d<- seldata # Manually generated data for analysis which is included in package
```

```{r}
w<- weight # Weights assigned to the traits also include in package
```

As we discussed that selection index based on discriminant function. So we have required **genotypic & phenotypic variance-covariance matrix** for further analysis.

+ Genotypic variance-covariance matrix
```{r}
gmat<- gen.varcov(data = d[,3:9], genotypes = d$treat, replication = d$rep)
print(gmat)
```

+ Phenotypic variance-covariance matrix
```{r}
pmat<- phen.varcov(data = d[,3:9], genotypes = d$treat, replication = d$rep)
print(pmat)
```

Generally, **Percent Relative Efficiency (PRE)** of a selection index is calculated with reference to **Genetic Advance (GA) yield** of respective weight. So first we calculate the GA of yield for respective weights.
+ Genetic gain of Yield
```{r}
GAY<- gen.advance(phen_mat = pmat[1,1], gen_mat = gmat[1,1],
                  weight_mat = w[1,2])
print(GAY)
```
We use this GAY value for the construction, ranking of the other selection indices and stored them in a list "si".

## Selection score and Ranking of genotypes
Generally selection score is calculate based on top ranked selection index. So first we store the **discriminant coefficient** value into a variable **b**, and later that value we used for calculation of selection score and ranking of the genotypes.

## `comb.indices()` is used for construction of selection indices based on different combination of characters. 
```{r}
comb.indices(ncomb = 1, pmat = pmat, gmat = gmat, wmat = w[,-1], wcol = 1, GAY = GAY)
```

## `rcomb.indices()`` - remove trait from the construction of selection indices
```{r}
rcomb.indices(ncomb = 1, i = 1, pmat = pmat, gmat = gmat, wmat = w[,-1], wcol = 1, GAY = GAY)
```
