R语言中介分析:解决'undefined columns selected'错误
在运行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)
原文地址: http://www.cveoy.top/t/topic/nOgO 著作权归作者所有。请勿转载和采集!