Calculates an element-wise mean over a list of matrices or CompadreMat objects of constant dimension.
The difference between function mat_mean
) and (mpm_mean
is that
mat_mean
takes input as a list of matrices (e.g., a list of **A**
matrices) while mat_mean
takes input as a list of `CompadreMat` objects and
thus calculates the mean matrices for both the **A** matrix and its
submatrices (**U**, **F**, **C**).
Details
If na.rm == TRUE
, missing values are ignored in the calculation of the
mean matrix. If na.rm == TRUE
and a given element is NA
in
every matrix within x
, the value returned for that element will
be 0
.
See also
Other data management:
cdb_flatten()
,
cdb_id_stages()
,
cdb_id_studies()
,
cdb_id()
,
cdb_mean_matF()
,
cdb_rbind()
,
cdb_unflatten()
,
cdb_unnest()
,
mpm_elementwise_apply()
,
mpm_median()
,
mpm_sd()
,
string_representation
Examples
# there are four rows for species 'Haplopappus_radiatus' in Compadre
mpms <- Compadre$mat[Compadre$SpeciesAuthor == "Haplopappus_radiatus"]
#The object mpms is a list, containing compadre objects
class(mpms)
#> [1] "list"
class(mpms[[1]])
#> [1] "CompadreMat"
#> attr(,"package")
#> [1] "Rcompadre"
mpm_mean(mpms)
#> MatrixClassOrganized MatrixClassAuthor
#> 1 active Seedling
#> 2 active Small reproductive
#> 3 active Large reproductive
#> 4 active Reproductive
#>
#> matA:
#> 1 2 3 4
#> 1 0.00000 0.0000 0.00000 1.96575
#> 2 0.19725 0.4090 0.17650 0.15400
#> 3 0.03250 0.1605 0.38175 0.37500
#> 4 0.00000 0.1175 0.26100 0.37150
#>
#> matU:
#> 1 2 3 4
#> 1 0.00000 0.0000 0.00000 0.0000
#> 2 0.19725 0.4090 0.17650 0.1540
#> 3 0.03250 0.1605 0.38175 0.3750
#> 4 0.00000 0.1175 0.26100 0.3715
#>
#> matF:
#> 1 2 3 4
#> 1 0 0 0 1.96575
#> 2 0 0 0 0.00000
#> 3 0 0 0 0.00000
#> 4 0 0 0 0.00000
#>
#> matC:
#> 1 2 3 4
#> 1 0 0 0 0
#> 2 0 0 0 0
#> 3 0 0 0 0
#> 4 0 0 0 0
#>
# extract list of matA and take mean
mats <- matA(mpms)
mat_mean(mats)
#> A1 A2 A3 A4
#> A1 0.00000 0.0000 0.00000 1.96575
#> A2 0.19725 0.4090 0.17650 0.15400
#> A3 0.03250 0.1605 0.38175 0.37500
#> A4 0.00000 0.1175 0.26100 0.37150