I wish to run a "cost-sensitive" randomForest algorithm incorporating a "cost matrix" that reflects a custom loss function, with the option of minimizing the expected misclassification cost. I have read that R’s randomForest package doesn’t directly support multi-class or even binary cost-sensitive learning, but I have read that there are workarounds to incorporate cost sensitivity into randomForest such as:
(1) Modifying the sample weights during training based on the cost matrix.
(2) Adjusting the predicted probabilities to minimize expected cost based on the cost matrix. For example, after obtaining class probabilities, apply decision thresholds that minimize expected misclassification cost.
(3) Custom Splitting Criteria: Modifying the underlying decision tree base learner to use a cost-sensitive criterion rather than standard impurity measures (Gini or entropy).
(4) Using Weighted Subsampling: Performing bootstrap sampling with weights reflecting the cost matrix, effectively biasing the training process towards reducing high-cost errors.
I have also collected a sample R code (attached text file). However, since I don't code, I am unsure if it works.
Can you please provide an easy set of technical steps that need to be followed in Bluesky Statistics? Although, a google page provides some info as in the attached image, it is not perfectly clear.

Looking forward to hearing from you.
Best regards,
Parag J Dutta