anova Interface

public interface anova

Performs an analysis of variance (ANOVA) on the supplied data set.

The following example illustrates a single-factor ANOVA on a data set.

program example
    use iso_fortran_env
    use fstats
    implicit none

    ! Local Variables
    character, parameter :: tab = achar(9)
    real(real64) :: x(10, 2)
    type(single_factor_anova_table) :: tbl

    ! Define the data
    x = reshape( &
        [ &
            3.086d3, 3.082d3, 3.069d3, 3.072d3, 3.045d3, 3.070d3, 3.079d3, &
            3.050d3, 3.062d3, 3.062d3, 3.075d3, 3.061d3, 3.063d3, 3.038d3, &
            3.070d3, 3.062d3, 3.070d3, 3.049d3, 3.042d3, 3.063d3 &
        ], &
        [10, 2] &
    )

    ! Perform the ANOVA
    tbl = anova(x)

    ! Print out the table
    print '(A)', "Description" // tab // "DOF" // tab // "Sum of Sq." // &
        tab // "Variance" // tab // "F-Stat" // tab // "P-Value"
    print '(AF2.0AF5.1AF5.1AF5.3AF5.3)', "Main Factor: " // tab, &
        tbl%main_factor%dof, tab, &
        tbl%main_factor%sum_of_squares, tab // tab, &
        tbl%main_factor%variance, tab // tab, &
        tbl%main_factor%f_statistic, tab, &
        tbl%main_factor%probability

    print '(AF3.0AF6.1AF5.1)', "Within: " // tab, &
        tbl%within_factor%dof, tab, &
        tbl%within_factor%sum_of_squares, tab // tab, &
        tbl%within_factor%variance

    print '(AF3.0AF6.1AF5.1)', "Total: " // tab // tab, &
        tbl%total_dof, tab, &
        tbl%total_sum_of_squares, tab // tab, &
        tbl%total_variance

    print '(AF6.1)', "Overall Mean: ", tbl%overall_mean
end program

The above program produces the following output.

Description     DOF     Sum of Sq.      Variance        F-Stat  P-Value
Main Factor:    1.      352.8           352.8           2.147   0.160
Within:         18.     2958.2          164.3
Total:          19.     3311.0          174.3
Overall Mean: 3063.5

See Also


Contents


Module Procedures

private function anova_1_factor(x) result(rst)

Performs an analysis of variance (ANOVA) on the supplied data set.

Arguments

Type IntentOptional Attributes Name
real(kind=real64), intent(in) :: x(:,:)

An M-by-N matrix containing the M replications of the N test points of interest.

Return Value type(single_factor_anova_table)

A single_factor_anova_table instance containing the ANOVA results.

private function anova_2_factor(x) result(rst)

Performs an analysis of variance (ANOVA) on the supplied data set.

Arguments

Type IntentOptional Attributes Name
real(kind=real64), intent(in) :: x(:,:,:)

An M-by-N-by-K array containing the M replications of the N first factor results, and the K second factor results.

Return Value type(two_factor_anova_table)

A two_factor_anova_table instance containing the ANOVA results.

private function anova_model_fit(nmodelparams, ymeas, ymod, err) result(rst)

Performs an analysis of variance (ANOVA) on the supplied data set.

Arguments

Type IntentOptional Attributes Name
integer(kind=int32), intent(in) :: nmodelparams

The number of model parameters.

real(kind=real64), intent(in) :: ymeas(:)

An N-element array containing the measured dependent variable data.

real(kind=real64), intent(in) :: ymod(:)

An N-element array containing the modeled dependent variable data.

class(errors), intent(inout), optional, target :: err

A mechanism for communicating errors and warnings to the caller. Possible warning and error codes are as follows. - FS_NO_ERROR: No errors encountered. - FS_ARRAY_SIZE_ERROR: Occurs if ymeas and ymod are not the same length. - FS_MEMORY_ERROR: Occurs if a memory error is encountered.

Return Value type(single_factor_anova_table)

A single_factor_anova_table instance containing the ANOVA results.