估算数据集列表的时滞分析 [英] Time lag analysis on list of imputed datasets

查看:123
本文介绍了估算数据集列表的时滞分析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题和数据与以下文章中的内容类似:

My question and data is similar to the post in: Loop Through Data with Sequential Time Lags output Linear Regression Coefficients

set.seed(242)
df<- data.frame(month=order(seq(1,248,1),decreasing=TRUE), 
psit=c(79,1, NA, 69, 66, 77, 76, 93,  NA, 65 ,NA ,3, 45, 64, 88, 88 
,76, NA, NA, 85,sample(1:10,228, replace=TRUE)),var=sample(1:10,248, 
replace=TRUE))

但是,我的数据集结构有所不同,因为我估算了psit的缺失值.现在,在使用mice()函数来插补值之后,现在psitmonthvar嵌套在列表tempdata中.现在,tempdata包括40个新的估算数据集.

However, the structure of my dataset differs because I have imputed missing values for psit. Now psit, month and var are now nested within a list tempdata after using the mice() function to impute values. Now tempdata includes 40 new imputed datasets.

tempdata<-mice(data = df, m = 40, method = "pmm", maxit 
 = 50, seed = 500)

我想获取40个估算的数据集,对每个估算的数据集运行相同的时滞分析(这与上面的文章(其中有一个数据集进行时滞分析)不同),并汇总每个R值例如所有估算数据集之间的时滞.

I want to take the 40 imputed datasets, run the same time lag analysis on each imputed dataset (this differs from the post above where there was one dataset to preform the time lag analysis) and pool the R-squared values of each like time lag among all imputed datasets.

mice上的帖子表明您可以使用以下方法来合并lm()的结果:

Posts on mice indicate you can pool the results of a lm() using:

modelFit1 <- with(tempdata,lm(psit~ month))
summary(pool(modelFit1))

但是,我想在所有40个估算数据集中将R平方的值合并起来,以用于类似时间滞后的情况.因此,我不确定如何在tempdata中的每个估算数据集上使用dyn$lm()函数,然后使用pool()函数汇总平方值的结果.

However, I want to pool the R-squared values for like time lags among all 40 imputed datasets. So I am unsure how to use the dyn$lm() function on each imputed dataset in tempdata and then use the pool() function to pool results for the squared values.

要获得该结果.我尝试了以下操作,但收到错误消息:

To achieve that result. I have tried the following but get an error:

modelFit1 <- with(tempData, lapply(1:236, function(i) dyn$lm(psit ~ 
             lag(var, -i),tail(z, 12+i))))
summary(pool(modelFit1),function(x) summary(x)$r.squared))

推荐答案

由于您使用的是鼠标包,因此"pool.r.squared"不能满足您的需求吗?

Since you are using mice package, wouldn't "pool.r.squared" works for your purpose?

pool.r.squared(modelFit1, adjusted = FALSE)
# est      lo 95    hi 95       fmi
# R^2 0.1345633 0.06061036 0.226836 0.1195257

这篇关于估算数据集列表的时滞分析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆