contrast: Function to compute the needed statistics for a given...

View source: R/contrast.r

contrastR Documentation

Function to compute the needed statistics for a given contrast

Description

The function computes the statistics for inference in a given contrast, subject to a given significance level. Those statistics are as follows: estimated contrast, standard error of the contrast, and the confidence interval of the contrast.

Usage

contrast(
  model = model,
  coef.cont = coef.cont,
  grp.m = grp.m,
  grp.n = grp.n,
  alpha = 0.05,
  full = TRUE
)

Arguments

model

object containing the fitted model

coef.cont

vector with the coefficients to establish the contrasts

grp.m

a vector having the sample mean per each group, or level of the factor under study.

grp.n

a vector having the sample size per each group, or level of the factor under study.

alpha

is the significance level for building the confidence intervals. Default value is 0.05, which is 95% confidence level.

full

FALSE if want short output, TRUE for longer (i.e. more details). Default is TRUE.

Details

The contrast is established based upon an already fitted statistical model that describe the relationship among variables. The significance level ('alpha') is defined by the user, although by default has been set to 0.05, that is to say, a 95% of statistical confidence.

Value

This function returns the above described statistics for a given contrast.

Author(s)

Christian Salas-Eljatib

References

  • Salas-Eljatib C. 2025. datana: Datasets and Functions to Accompany Análisis de Datos con R. R package version 1.0.7, \Sexpr[results=rd]{tools:::Rd_expr_doi("10.32614/CRAN.package.datana")}, https://CRAN.R-project.org/package=datana

Examples


data(fertiliza)
table(fertiliza$treat)
means.trt <- tapply(fertiliza$volume,fertiliza$treat,mean);means.trt
sds.trt <- tapply(fertiliza$volume,fertiliza$treat,sd);sds.trt
ns.trt <- tapply(fertiliza$volume,fertiliza$treat,length);ns.trt
m1 <- lm(volume ~ treat, data=fertiliza)
anova(m1)
## Coefficients to be used in the contrast
#c1: (tmoA1-A2) - (tmoA3-A4)
C1.coeff <- c(0,1,1,-1,-1)
contrast(model=m1,C1.coeff,grp.m=means.trt,grp.n=ns.trt,alpha=0.1,full=TRUE)
contrast(model=m1,C1.coeff,grp.m=means.trt,grp.n=ns.trt,alpha=0.1,full=FALSE)
contrast(m1,C1.coeff,grp.m=means.trt,grp.n=ns.trt,alpha=0.05,full=TRUE)
contrast(m1,C1.coeff,grp.m=means.trt,grp.n=ns.trt)


datana documentation built on June 13, 2025, 1:11 a.m.