Calculate slopes by groups
get_slope_by_group(d, group, x, y)
d | wide,dataframe containing the |
---|---|
group | name of column |
x, y | names of column in |
a dataframe with two columns, one containing the group id and one containing the estimated slope for that group
sub02 %>% tidyr::pivot_wider(names_from = contrast, values_from = y) %>% get_slope_by_group(voxel, low, high)#> # A tibble: 187 x 2 #> voxel slope #> <fct> <dbl> #> 1 191852 1.31 #> 2 197706 1.05 #> 3 197769 0.889 #> 4 197842 0.823 #> 5 197906 1.21 #> 6 197907 2.23 #> 7 203688 0.878 #> 8 203689 0.730 #> 9 203690 -0.0269 #> 10 203753 1.25 #> # … with 177 more rows# create group with intersection of variables sub02 %>% tidyr::pivot_wider(names_from = contrast, values_from = y) %>% get_slope_by_group(c(voxel, sub), low, high)#> # A tibble: 187 x 3 #> voxel sub slope #> <fct> <fct> <dbl> #> 1 191852 2 1.31 #> 2 197706 2 1.05 #> 3 197769 2 0.889 #> 4 197842 2 0.823 #> 5 197906 2 1.21 #> 6 197907 2 2.23 #> 7 203688 2 0.878 #> 8 203689 2 0.730 #> 9 203690 2 -0.0269 #> 10 203753 2 1.25 #> # … with 177 more rows