% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/DBV_SBV_crop_mix_infer.R
\name{fitDBVSBVinter}
\alias{fitDBVSBVinter}
\title{Fit DBV-SBV models for interspecific mixtures}
\usage{
fitDBVSBVinter(
  listY,
  listX,
  listZ,
  listVCov,
  REML = TRUE,
  lOptions = NULL,
  verbose = FALSE
)
}
\arguments{
\item{listY}{named list of response variables (a matrix Y_IC and, optionally, a vector y_SC_f and a vector y_SC_t)}

\item{listX}{named list of design matrices for the fixed-effect explanatory factors (a matrix X_IC and, optionally, a matrix X_SC_f and a matrix X_SC_t)}

\item{listZ}{named list of design matrices of random-effect explanatory factors}

\item{listVCov}{named list of square, symmetric matrices used, after re-scaling, as variance-covariance matrices for the random-effect factors; named "K" for the BVs (DBVs and SBVs) and "Kmixpair" for the DBVxSBVs; these matrices must have dimnames (both rows and columns) coherent with the column names of the design matrices in \code{listZ}}

\item{REML}{logical}

\item{lOptions}{named list of options (for experts)}

\item{verbose}{verbosity level}
}
\value{
list
}
\description{
Fits DBV-SBV models for interspecific mixtures.
}
\examples{
## simulate a data set with both sole crops and intercrops:
GRMs <- list("S1" = diag(100),
             "S2" = diag(2))
dimnames(GRMs$S1) <- list(paste0("gS1_", 1:100), paste0("gS1_", 1:100))
dimnames(GRMs$S2) <- list(paste0("gS2_", 1:2), paste0("gS2_", 1:2))
out <- simulDBVSBVinter(GRMs)
names(out)
datW <- out$datW
str(datW)

## fit the model using intercrops only:
idxIC <- which(!is.na(datW$geno_S1) & !is.na(datW$geno_S2))
datW_IC <- droplevels(datW[idxIC, ])
listY <- list(Y_IC = datW_IC[, c("yield_S1", "yield_S2")])
listX <- list(X_IC = model.matrix(~ 1 + block + geno_S2, datW_IC,
              contrasts.arg = list("block" = "contr.sum",
                                   "geno_S2" = "contr.sum")))
listZ <- list(Z_DS_f = model.matrix(~ 0 + geno_S1, datW_IC))
colnames(listZ$Z_DS_f) <- gsub("^geno_S1", "", colnames(listZ$Z_DS_f))
listVCov <- list(K = GRMs$S1[levels(datW_IC$geno_S1), levels(datW_IC$geno_S1)])
fitTmb <- fitDBVSBVinter(listY, listX, listZ, listVCov,
                         lOptions = list(iter.max = 20), REML = TRUE)
names(fitTmb)
fitTmb$sdr

## see the third vignette for more details
}
\seealso{
\code{\link{simulDBVSBVinter}}
}
\author{
Jemay Salomon, Timothee Flutre
}
