Function to calculate deciles from components and coefficients

get_deciles_from_components(
  df,
  use_second_comp = TRUE,
  pc_loadings = pc_loading_matrix,
  center_and_scaler = pc_center_sd,
  features = c("d1", "d2", "d3", "d4", "d5", "d6", "d7", "d8", "d9", "d10"),
  category_col = "Category",
  input_df = Wider_data_full,
  value_col = "Income..net.",
  grouping_variables = c("country", "year")
)

Arguments

df

dataframe with decile data

use_second_comp

Use one component or use two. By default use two.

features

The categorical names of the features you want to extract.

category_col

column with categorical definitions for deciles

input_df

If user wants to calculate new centers and scalers, then they can pass an input df which will be used to calculate the new params.

value_col

Name of values to be output.

grouping_variables

variables to group by

center_and_scaler_data

The centers and SD for the data. This is pre-saved. But can be generated using `get_sd_center()` above.