% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/methods.R, R/methods_SE.R
\docType{methods}
\name{test_differential_cellularity}
\alias{test_differential_cellularity}
\alias{test_differential_cellularity,spec_tbl_df-method}
\alias{test_differential_cellularity,tbl_df-method}
\alias{test_differential_cellularity,tidybulk-method}
\alias{test_differential_cellularity,SummarizedExperiment-method}
\alias{test_differential_cellularity,RangedSummarizedExperiment-method}
\title{Add differential tissue composition information to a tbl}
\usage{
test_differential_cellularity(
  .data,
  .formula,
  .sample = NULL,
  .transcript = NULL,
  .abundance = NULL,
  method = "cibersort",
  reference = X_cibersort,
  significance_threshold = 0.05,
  ...
)

\S4method{test_differential_cellularity}{spec_tbl_df}(
  .data,
  .formula,
  .sample = NULL,
  .transcript = NULL,
  .abundance = NULL,
  method = "cibersort",
  reference = X_cibersort,
  significance_threshold = 0.05,
  ...
)

\S4method{test_differential_cellularity}{tbl_df}(
  .data,
  .formula,
  .sample = NULL,
  .transcript = NULL,
  .abundance = NULL,
  method = "cibersort",
  reference = X_cibersort,
  significance_threshold = 0.05,
  ...
)

\S4method{test_differential_cellularity}{tidybulk}(
  .data,
  .formula,
  .sample = NULL,
  .transcript = NULL,
  .abundance = NULL,
  method = "cibersort",
  reference = X_cibersort,
  significance_threshold = 0.05,
  ...
)

\S4method{test_differential_cellularity}{SummarizedExperiment}(
  .data,
  .formula,
  .sample = NULL,
  .transcript = NULL,
  .abundance = NULL,
  method = "cibersort",
  reference = X_cibersort,
  significance_threshold = 0.05,
  ...
)

\S4method{test_differential_cellularity}{RangedSummarizedExperiment}(
  .data,
  .formula,
  .sample = NULL,
  .transcript = NULL,
  .abundance = NULL,
  method = "cibersort",
  reference = X_cibersort,
  significance_threshold = 0.05,
  ...
)
}
\arguments{
\item{.data}{A `tbl` (with at least three columns for sample, feature and transcript abundance) or `SummarizedExperiment` (more convenient if abstracted to tibble with library(tidySummarizedExperiment))}

\item{.formula}{A formula representing the desired linear model. The formula can be of two forms: multivariable (recommended) or univariable Respectively: \"factor_of_interest ~ .\" or \". ~ factor_of_interest\". The dot represents cell-type proportions, and it is mandatory. If censored regression is desired (coxph) the formula should be of the form \"survival::Surv\(y, dead\) ~ .\"}

\item{.sample}{The name of the sample column}

\item{.transcript}{The name of the transcript/gene column}

\item{.abundance}{The name of the transcript/gene abundance column}

\item{method}{A string character. Either \"cibersort\", \"epic\" or \"llsr\". The regression method will be chosen based on being multivariable: lm or cox-regression (both on logit-transformed proportions); or univariable: beta or cox-regression (on logit-transformed proportions). See .formula for multi- or univariable choice.}

\item{reference}{A data frame. The transcript/cell_type data frame of integer transcript abundance}

\item{significance_threshold}{A real between 0 and 1 (usually 0.05).}

\item{...}{Further parameters passed to the method deconvolve_cellularity}
}
\value{
A consistent object (to the input) with additional columns for the statistics from the hypothesis test (e.g.,  log fold change, p-value and false discovery rate).

A `SummarizedExperiment` object

A `SummarizedExperiment` object
}
\description{
test_differential_cellularity() takes as input A `tbl` (with at least three columns for sample, feature and transcript abundance) or `SummarizedExperiment` (more convenient if abstracted to tibble with library(tidySummarizedExperiment)) and returns a consistent object (to the input) with additional columns for the statistics from the hypothesis test.
}
\details{
`r lifecycle::badge("maturing")`

This routine applies a deconvolution method (e.g., Cibersort; DOI: 10.1038/nmeth.3337)
and passes the proportions inferred into a generalised linear model (DOI:dx.doi.org/10.1007/s11749-010-0189-z)
or a cox regression model (ISBN: 978-1-4757-3294-8)

Underlying method for the generalised linear model:
data |>
deconvolve_cellularity(
	!!.sample, !!.transcript, !!.abundance,
	method=method,
	reference = reference,
	action="get",
	...
)  %>%
	[..] %>%
	betareg::betareg(.my_formula, .)

Underlying method for the cox regression:
data |>
deconvolve_cellularity(
	!!.sample, !!.transcript, !!.abundance,
	method=method,
	reference = reference,
	action="get",
	...
)  %>%
	[..] %>%
	mutate(.proportion_0_corrected = .proportion_0_corrected  |> boot::logit()) %>%
	survival::coxph(.my_formula, .)
}
\examples{

 # Regular regression
	test_differential_cellularity(
	 tidybulk::se_mini ,
	    . ~ condition,
	    cores = 1
	)

	# Cox regression - multiple

tidybulk::se_mini |>

	# Test
	test_differential_cellularity(
	    survival::Surv(days, dead) ~ .,
	    cores = 1
	)



}