This function is meant as a userfriendly wrapper to approximate the way analysis of variance is done in SPSS.

fanova(
  data,
  y,
  between = NULL,
  covar = NULL,
  withinReference = 1,
  betweenReference = NULL,
  withinNames = NULL,
  plot = FALSE,
  levene = FALSE,
  digits = 2,
  contrast = NULL
)

# S3 method for fanova
print(x, digits = x$input$digits, ...)

Arguments

data

The dataset containing the variables to analyse.

y

The dependent variable. For oneway anova, factorial anova, or ancova, this is the name of a variable in dataframe data. For repeated measures anova, this is a vector with the names of all variable names in dataframe data, e.g. c('t0_value', 't1_value', 't2_value').

between

A vector with the variables name(s) of the between subjects factor(s).

covar

A vector with the variables name(s) of the covariate(s).

withinReference

Number of reference category (variable) for within subjects treatment contrast (dummy).

betweenReference

Name of reference category for between subject factor in RM anova.

withinNames

Names of within subjects categories (dependent variables).

plot

Whether to produce a plot. Note that a plot is only produced for oneway and twoway anova and oneway repeated measures designs: if covariates or more than two between-subjects factors are specified, not plot is produced. For twoway anova designs, the second predictor is plotted as moderator (and the first predictor is plotted on the x axis).

levene

Whether to show Levene's test for equality of variances (using car's leveneTest function but specifying mean as function to compute the center of each group).

digits

Number of digits (actually: decimals) to use when printing results. The p-value is printed with one extra digit.

contrast

This functionality has been implemented for repeated measures only.

x

The object to print (i.e. as produced by regr).

...

Any additional arguments are ignored.

Value

Mainly, this function prints its results, but it also returns them in an object containing three lists:

input

The arguments specified when calling the function

intermediate

Intermediat objects and values

output

The results such as the plot.

Details

This wrapper uses oneway and lm and lmer in combination with car's Anova function to conduct the analysis of variance.

See also

regr and logRegr for similar functions for linear and logistic regression and oneway, lm, lmer and Anova for the functions used behind the scenes.

Author

Gjalt-Jorn Peters and Peter Verboon

Maintainer: Gjalt-Jorn Peters gjalt-jorn@userfriendlyscience.com

Examples


### Oneway anova with a plot
fanova(dat=mtcars, y='mpg', between='cyl', plot=TRUE);
#> Between-subjects factor cyl does not have class 'factor' in dataframe 'mtcars'. Converting it now.
#> Flexible Analysis of Variance was called with:
#> 
#>   Dependent variable: mpg
#>   Factors: cyl
#> 
#> 

#> 
#> Anova table with effect sizes 
#> 
#> term      | df |   sumsq |  meansq | statistic | p.value | partial.etasq | omegasq
#> ----------------------------------------------------------------------------------
#> cyl       |  2 | 824.785 | 412.392 |    39.698 |  < .001 |         0.732 |   0.707
#> Residuals | 29 | 301.263 |  10.388 |           |         |               |        

### Factorial anova
fanova(dat=mtcars, y='mpg', between=c('vs', 'am'), plot=TRUE);
#> Between-subjects factor vs does not have class 'factor' in dataframe 'mtcars'. Converting it now.
#> Between-subjects factor am does not have class 'factor' in dataframe 'mtcars'. Converting it now.
#> Flexible Analysis of Variance was called with:
#> 
#>   Dependent variable: mpg
#>   Factors: vs & am
#> 
#> 

#> 
#> Anova table with effect sizes 
#> 
#> term      | df |   sumsq |  meansq | statistic | p.value | partial.etasq | omegasq
#> ----------------------------------------------------------------------------------
#> vs        |  1 | 496.528 | 496.528 |    41.196 |  < .001 |         0.595 |   0.426
#> am        |  1 | 276.033 | 276.033 |    22.902 |  < .001 |         0.450 |   0.232
#> vs:am     |  1 |  16.010 |  16.010 |     1.328 |   0.259 |         0.045 |   0.003
#> Residuals | 28 | 337.476 |  12.053 |           |         |               |        

### Ancova
fanova(dat=mtcars, y='mpg', between=c('vs', 'am'), covar='hp');
#> Between-subjects factor vs does not have class 'factor' in dataframe 'mtcars'. Converting it now.
#> Between-subjects factor am does not have class 'factor' in dataframe 'mtcars'. Converting it now.
#> Flexible Analysis of Variance was called with:
#> 
#>   Dependent variable: mpg
#>   Factors: vs & am
#>   Covariates: hp
#> 
#> 
#> 
#> Anova table with effect sizes 
#> 
#> term      | df |   sumsq |  meansq | statistic | p.value | partial.etasq | omegasq
#> ----------------------------------------------------------------------------------
#> vs        |  1 | 496.528 | 496.528 |    64.883 |  < .001 |         0.706 |   0.431
#> am        |  1 | 276.033 | 276.033 |    36.070 |  < .001 |         0.572 |   0.237
#> hp        |  1 | 134.606 | 134.606 |    17.589 |  < .001 |         0.394 |   0.112
#> vs:am     |  1 |  12.258 |  12.258 |     1.602 |   0.216 |         0.056 |   0.004
#> Residuals | 27 | 206.621 |   7.653 |           |         |               |        

### Don't run these examples to not take too much time during testing
### for CRAN
if (FALSE) {
### Repeated measures anova; first generate datafile
dat <- mtcars[, c('am', 'drat', 'wt')];
names(dat) <- c('factor', 't0_dependentVar' ,'t1_dependentVar');
dat$factor <- factor(dat$factor);

### Then do the repeated measures anova
fanova(dat, y=c('t0_dependentVar' ,'t1_dependentVar'),
       between='factor', plot=TRUE);
}