% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/scan1gen.R
\name{scan1gen}
\alias{scan1gen}
\title{General genome scan with a single-QTL model}
\usage{
scan1gen(
  genoprobs,
  pheno,
  kinship = NULL,
  addcovar = NULL,
  Xcovar = NULL,
  intcovar = NULL,
  weights = NULL,
  func,
  vectorize_func = TRUE,
  cores = 1,
  ...
)
}
\arguments{
\item{genoprobs}{Genotype probabilities as calculated by
\code{\link[=calc_genoprob]{calc_genoprob()}}.}

\item{pheno}{A numeric matrix of phenotypes, individuals x phenotypes.}

\item{kinship}{Optional kinship matrix, or a list of kinship matrices (one
per chromosome), in order to use the LOCO (leave one chromosome
out) method.}

\item{addcovar}{An optional numeric matrix of additive covariates.}

\item{Xcovar}{An optional numeric matrix with additional additive covariates used for
null hypothesis when scanning the X chromosome.}

\item{intcovar}{An numeric optional matrix of interactive covariates.}

\item{weights}{An optional numeric vector of positive weights for the
individuals. As with the other inputs, it must have \code{names}
for individual identifiers.}

\item{func}{Function to calculate log10 likelihood. It is called as
\code{func(pr, pheno, kinship, addcovar, intcovar, weights, ...)}
where \code{pr} is for the genotype probabilities at a fixed
position. It will also be used to calculate the null log10
likelihood, with \code{pr} being NULL in that case.}

\item{vectorize_func}{If TRUE (the default), assume that \code{func}
takes only a single phenotype. If FALSE, assume \code{func} is able
to take a matrix of phenotypes and return a vector of log10
likelihood values.}

\item{cores}{Number of CPU cores to use, for parallel calculations.}

\item{...}{Additional arguments passed to \code{func()}.}
}
\value{
An object of class \code{"scan1"}: a matrix of LOD scores, positions x phenotypes.
}
\description{
General genome scan with a single-QTL model, with possible allowance for covariates
and a polygeneic effect, but taking a general function that calculates a LOD score
at a single position.
}
\examples{
# read data
iron <- read_cross2(system.file("extdata", "iron.zip", package="qtl2"))
\dontshow{iron <- iron[,c("19", "X")] # subset to chr 19 and X}

# insert pseudomarkers into map
map <- insert_pseudomarkers(iron$gmap, step=1)

# calculate genotype probabilities
probs <- calc_genoprob(iron, map, error_prob=0.002)

# covariates for X chr under null
Xcovar <- get_x_covar(iron)

# create binary trait
bin_pheno <- setNames(as.numeric(iron$pheno[,1] > median(iron$pheno[,1])),
                      rownames(iron$pheno))

ll_glm <-
   function(pr, pheno, addcovar=NULL, ...)
{
   formula <- ifelse(is.null(pr), "pheno ~ 1", "pheno ~ pr")
   if(!is.null(addcovar)) formula <- paste(formula, "+ addcovar")

    glm_out <- glm(as.formula(formula), family=binomial(link=probit))
    -glm_out$deviance/(2*log(10)) # log10 likelihood
}

# perform genome scan using glm() with probit link function
out <- scan1gen(probs, bin_pheno, Xcovar=Xcovar, func=ll_glm)

}
\seealso{
\code{\link[=scan1]{scan1()}}, \code{\link[=scan1perm]{scan1perm()}}, \code{\link[=scan1max]{scan1max()}}, \href{https://kbroman.org/qtl2/assets/vignettes/scan1gen.html}{scan1gen examples}
}
