fs_lmm Creates a data.frame of subsetted row and formatted columns ready for use in Freesurfers (6.0) linear mixed models. Design matrices are created for the grouping.var factors, and numeric variables are z-transformed.

fs_lmm(
  data,
  formula,
  site_var,
  folder_var,
  numeric_transform = "delete",
  ...,
  file = NULL,
  concat_list = NULL
)

Arguments

data

data extracted from the NOAS

formula

right-hand formula for your model. (ex. ~ visit_age * sex)

site_var

column name with the site information

folder_var

unqoted column name with folder-information of MRI data from the 'mri_info' table.

numeric_transform

Action to take on numeric_transform data that are numeric

...

other arguments to utils{model.matrix}

file

Optional string specifying file name to be saved

concat_list

character vector of fsid's that you want the data matched to. Used if the data is already concatenated and you wish to add more variables to your models.

Value

a data frame ready for Freesurfer LMM use.

Details

Available options for 'numeric_transform' are:

  • "delete"delete observations with any numeric_transform numeric.vars

  • "mean_na"replace numeric_transform with mean for that participant

  • "mean_all"replace all values with the mean for that participant

  • "first"replace all values with the first observation for that participant

Examples

# attach built-in noas example data to test dt <- noas_example fs_lmm(dt, ~ visit_age * sex * cog, site_var = site_name, folder_var = mri_info_folder )
#> Warning: Some data have been removed. #> # A tibble: 2 x 8 #> subject_id project_id wave_code site_name mri_info_folder visit_age sex #> <chr> <chr> <dbl> <chr> <chr> <dbl> <chr> #> 1 1000000 MemP 3 ousSkyra 1000000_4 14 female #> 2 1000010 MemC 3 ousSkyra 1000010_3 33 male #> # … with 1 more variable: cog <dbl>
#> # A tibble: 8 x 13 #> fsid `fsid-base` visit_age sex cog intercept visit_age_z sexmale cog_z #> <chr> <chr> <dbl> <chr> <dbl> <int> <dbl> <int> <dbl> #> 1 10000… base_10000… 8 fema… 16 1 -1.14 0 0.957 #> 2 10000… base_10000… 10 fema… 14 1 -0.950 0 -0.0638 #> 3 10000… base_10000… 14 fema… 16 1 -0.565 0 0.957 #> 4 10000… base_10000… 17 fema… 15 1 -0.276 0 0.447 #> 5 10000… base_10000… 20 fema… 15 1 0.0120 0 0.447 #> 6 10000… base_10000… 22 male 14 1 0.204 1 -0.0638 #> 7 10000… base_10000… 28 male 13 1 0.781 1 -0.574 #> 8 10000… base_10000… 40 male 10 1 1.94 1 -2.11 #> # … with 4 more variables: visit_age:sexmale_z <dbl>, visit_age:cog_z <dbl>, #> # sexmale:cog_z <dbl>, visit_age:sexmale:cog_z <dbl>
# replace NA values in numeric with # mean values for the participant fs_lmm(dt, ~ visit_age * sex * cog, numeric_transform = "mean_na", site_var = site_name, folder_var = mri_info_folder )
#> # A tibble: 10 x 13 #> fsid `fsid-base` visit_age sex cog intercept visit_age_z sexmale cog_z #> <chr> <chr> <dbl> <chr> <dbl> <int> <dbl> <int> <dbl> #> 1 1000… base_10000… 8 fema… 16 1 -1.22 0 1.05 #> 2 1000… base_10000… 10 fema… 14 1 -1.03 0 -0.0286 #> 3 1000… base_10000… 14 fema… 16 1 -0.640 0 1.05 #> 4 1000… base_10000… 14 fema… 15.2 1 -0.640 0 0.616 #> 5 1000… base_10000… 17 fema… 15 1 -0.349 0 0.509 #> 6 1000… base_10000… 20 fema… 15 1 -0.0581 0 0.509 #> 7 1000… base_10000… 22 male 14 1 0.136 1 -0.0286 #> 8 1000… base_10000… 28 male 13 1 0.717 1 -0.566 #> 9 1000… base_10000… 33 male 12.3 1 1.20 1 -0.924 #> 10 1000… base_10000… 40 male 10 1 1.88 1 -2.18 #> # … with 4 more variables: visit_age:sexmale_z <dbl>, visit_age:cog_z <dbl>, #> # sexmale:cog_z <dbl>, visit_age:sexmale:cog_z <dbl>
# replace all numeric values with # mean values for the participant fs_lmm(dt, ~ visit_age * sex * cog, numeric_transform = "mean_na", site_var = site_name, folder_var = mri_info_folder )
#> # A tibble: 10 x 13 #> fsid `fsid-base` visit_age sex cog intercept visit_age_z sexmale cog_z #> <chr> <chr> <dbl> <chr> <dbl> <int> <dbl> <int> <dbl> #> 1 1000… base_10000… 8 fema… 16 1 -1.22 0 1.05 #> 2 1000… base_10000… 10 fema… 14 1 -1.03 0 -0.0286 #> 3 1000… base_10000… 14 fema… 16 1 -0.640 0 1.05 #> 4 1000… base_10000… 14 fema… 15.2 1 -0.640 0 0.616 #> 5 1000… base_10000… 17 fema… 15 1 -0.349 0 0.509 #> 6 1000… base_10000… 20 fema… 15 1 -0.0581 0 0.509 #> 7 1000… base_10000… 22 male 14 1 0.136 1 -0.0286 #> 8 1000… base_10000… 28 male 13 1 0.717 1 -0.566 #> 9 1000… base_10000… 33 male 12.3 1 1.20 1 -0.924 #> 10 1000… base_10000… 40 male 10 1 1.88 1 -2.18 #> # … with 4 more variables: visit_age:sexmale_z <dbl>, visit_age:cog_z <dbl>, #> # sexmale:cog_z <dbl>, visit_age:sexmale:cog_z <dbl>
# replace all numeric values with # first for the participant fs_lmm(dt, ~ visit_age * cog, site_var = site_name, folder_var = mri_info_folder )
#> Warning: Some data have been removed. #> # A tibble: 2 x 7 #> subject_id project_id wave_code site_name mri_info_folder visit_age cog #> <chr> <chr> <dbl> <chr> <chr> <dbl> <dbl> #> 1 1000000 MemP 3 ousSkyra 1000000_4 14 NA #> 2 1000010 MemC 3 ousSkyra 1000010_3 33 NA
#> # A tibble: 8 x 8 #> fsid `fsid-base` visit_age cog intercept visit_age_z cog_z #> <chr> <chr> <dbl> <dbl> <int> <dbl> <dbl> #> 1 1000000_1 base_1000000_11 8 16 1 -1.14 0.957 #> 2 1000000_2 base_1000000_11 10 14 1 -0.950 -0.0638 #> 3 1000000_3 base_1000000_11 14 16 1 -0.565 0.957 #> 4 1000000_5 base_1000000_12 17 15 1 -0.276 0.447 #> 5 1000000_6 base_1000000_12 20 15 1 0.0120 0.447 #> 6 1000010_1 base_1000010_12 22 14 1 0.204 -0.0638 #> 7 1000010_2 base_1000010_12 28 13 1 0.781 -0.574 #> 8 1000010_4 base_1000010_12 40 10 1 1.94 -2.11 #> # … with 1 more variable: visit_age:cog_z <dbl>
# Provide a vector of fsid to reduce the data to # pre-existing concatenated imaging data. fs_lmm(noas_example, ~ visit_age, site_var = site_name, folder_var = mri_info_folder, concat_list = c("1000000_1", "1000000_3", "1000000_5") )
#> # A tibble: 3 x 5 #> fsid `fsid-base` visit_age intercept visit_age_z #> <chr> <chr> <dbl> <int> <dbl> #> 1 1000000_1 base_1000000_11 8 1 -1.09 #> 2 1000000_3 base_1000000_11 14 1 0.218 #> 3 1000000_5 base_1000000_12 17 1 0.873