% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/pheno_stats.R
\name{pheno_stats}
\alias{pheno_stats}
\title{Statistical Analysis of Phenotype Data}
\usage{
pheno_stats(phenoData, defineForm = NULL, effNotation = "G")
}
\arguments{
\item{phenoData}{A data frame containing phenotype data with at least 5 columns.
The first 4 columns must be: Environment (E), Block (B), Repetition (R), and Genotype (G).
Additional columns contain trait measurements for statistical analysis.}

\item{defineForm}{Optional character vector of custom formula strings for statistical analysis.
If NULL, default formulas are automatically generated based on the data structure.}

\item{effNotation}{Character string specifying the effect notation for least squares means.
Default is "G" for genotype effect.}
}
\value{
A list containing comprehensive statistical analysis results for each trait:
  \item{normality_test}{Results of Shapiro-Wilk normality test}
  \item{formula}{Formula used for the statistical model}
  \item{ANOVA}{Complete analysis of variance results}
  \item{lsmeans}{Least squares means for genotypes with standard errors}
}
\description{
Performs comprehensive statistical analysis on phenotype data including normality tests, 
analysis of variance (ANOVA), and least squares means calculations for genetic studies.
}
\details{
This function performs a comprehensive statistical analysis pipeline:

\enumerate{
  \item \strong{Normality Test}: Uses Shapiro-Wilk test to assess normality of each trait
  \item \strong{Model Selection}: Automatically generates appropriate statistical models based on data structure
  \item \strong{ANOVA}: Performs analysis of variance to test significance of effects
  \item \strong{Least Squares Means}: Calculates adjusted means for genotypes
}

\strong{Automatic Model Generation:}
The function automatically generates appropriate formulas based on the experimental design:
\itemize{
  \item Multiple environments and blocks: \code{trait ~ E + G + E:G + B\%in\%E}
  \item Multiple environments only: \code{trait ~ E*G}
  \item Custom formulas: User-defined formulas when \code{defineForm} is provided
}

\strong{Data Requirements:}
The phenotype data must have the following structure:
\itemize{
  \item Column 1: Environment (E) - factor variable
  \item Column 2: Block (B) - factor variable  
  \item Column 3: Repetition (R) - factor variable
  \item Column 4: Genotype (G) - factor variable
  \item Columns 5+: Trait measurements - numeric variables
}
}
\examples{

# Example with multiple environments and blocks
pheno_data <- data.frame(
  E = rep(c("Env1", "Env2", "Env3"), each = 60),
  B = rep(c("Block1", "Block2"), each = 30, times = 3),
  R = rep(1:5, 36),
  G = rep(1:12, 15),
  Height = rnorm(180, 175, 8),
  Weight = rnorm(180, 75, 12)
)

# Perform statistical analysis with default formulas
results <- pheno_stats(pheno_data)

# View normality test results
results$Height$normality_test

# View ANOVA results
results$Height$ANOVA

# View least squares means
results$Height$lsmeans

# Example with custom formulas
custom_formulas <- c(
  "Height ~ E + G + E:G + B\%in\%E",
  "Weight ~ E + G + E:G"
)
results_custom <- pheno_stats(pheno_data, defineForm = custom_formulas)

}
\references{
Shapiro, S.S. and Wilk, M.B. (1965). An analysis of variance test for normality. 
Biometrika, 52(3-4), 591-611.
}
\seealso{
\code{\link{joint_map}} for joint mapping analysis
}
