create_data_matrices: Create data matrices for MegaLMM from a "tall" data.frame

View source: R/helper_functions.R

create_data_matricesR Documentation

Create data matrices for MegaLMM from a "tall" data.frame

Description

Often multi-trait data will be provided in tall format with a single value per row, and individuals represented on multiple rows. MegaLMM expects the data to be in wide format with all observations on the same individual in a row, and only one row per individual.

Usage

create_data_matrices(tall_data, id_cols, names_from, values_from, ...)

Arguments

tall_data

data.frame in the tall format

id_cols

vector of strings representing the set of columns of tall_data necessary to uniquely specify a single individual. See tidyr::pivot_wider.

names_from

vector of strings representing the set of columns of tall_data necessary to uniquely specify a single trait See tidyr::pivot_wider.

values_from

string giving the column of tall_data with the observations.

...

additional parameters passed to tidyr::pivot_wider.

Details

Specifically, the input to setup_model_MegaLMM expect Y, a nxp matrix for n individuals and p traits (Missing values coded as NA are fine in Y), and data, a data.frame with the variables used in formula. This function takes the tall format data and pivots it using the tidyr::pivot_wider function, returning the Y and data objects necessary to set up a MegaLMM model

Value

list with elements: * data a data.frame with the elements of id_cols * Y a numeric matrix of the traits * trait_info a data.frame with 1 row per trait and columns from names_from


deruncie/MegaLMM documentation built on June 10, 2025, 7:26 p.m.