Learn R Programming

datana (version 1.0.6)

contrast: 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
)

Value

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

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.

Author

Christian Salas-Eljatib

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.

References

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

Examples

Run this code

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)

Run the code above in your browser using DataLab