在运行result2 <- mediate(model.m2, model.y, treat = "log(spending)", mediator = "log(macro_ratio+1)", data = df)之前,需要先确认数据框df中是否存在名为macro_ratio+1的列。如果不存在,需要先计算这一列,例如:

df$macro_ratio_plus_1 <- log(df$macro_ratio+1)

然后在中介模型中使用macro_ratio_plus_1作为中介变量:

result2 <- mediate(model.m2, model.y, treat = "log(spending)", mediator = "macro_ratio_plus_1", data = df)
libraryreadxldf - read_excel3brandxlsx namesdf 1 rank brand brand_fans category beauty 6 country local_brand organic_p

原文地址: https://www.cveoy.top/t/topic/ebU1 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录