无法从R循环中的lqmm函数提取p_value [英] cannot extract the p_value from lqmm function in R loop

查看:109
本文介绍了无法从R循环中的lqmm函数提取p_value的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用R中的lqmm函数通过循环运行多个模型,并且我想从每个模型中获取P值.这是一个包含两个因变量的简单数据集.

I am running multiple models via loop using lqmm function in R And I want to get the P-value from each models. Here is a simple data set contains two dependent variables.

data <- structure(list(y1 = c(1, 1, 4, 4, 5, 5, 7, 7), y2 = c(1, 2, 1, 2, 7, 8, 7, 8), x = c(1, 2, 3, 4, 5, 6, 7, 8), id = c(1L, 1L, 2L, 2L, 2L, 3L, 4L, 5L), weight = c(0.9401069, 1.2730856, 0.985858, 4.1602805, 1.6042408, 1.0452717, 0.9784276, 1.5199646)), class = "data.frame", row.names = c(NA,-8L))

首先,我运行一个模型,并使用以下代码提取P值:

First, I ran a single model and extracted the P-value using the following code:

model <- lqmm(fixed= y1 ~ x, random = ~1, tau=0.5, group=id,data=data,weights=data$weight,na.action=na.omit)
summary(model)$tTable[2,5]

效果很好.

由于我有多个因变量,因此需要使用循环函数来运行它们.这是我尝试自动运行的内容.

Since I have multiple dependent variables, I need to use loop function to run them. Here is what I tried to run them automatically.

for (j in 1:2) {
  form <- formula(paste(names(data)[j], "~ x" ))
  model <- lqmm(form, random=~1, group=id, weights=data$weight, data=data, tau=0.5, na.action=na.omit)
  print(summary(model)$tTable[2,5])
}

不幸的是,它没有用.错误为错误:'符号'类型的对象不可子集化".

Unfortunately, it didn't work. The error is "Error: object of type 'symbol' is not subsettable".

但是,如果我只打印两个系数,则下面的代码有效:

But If I just print the two coefficients, the code below worked:

for (j in 1:2) {
  form <- formula(paste(names(data)[j], "~ x" ))
  model <- lqmm(form, random=~1, group=id, weights=data$weight, data=data, tau=0.5, na.action=na.omit)
  print(coef(model))
}

但是我还需要的信息是P值.我在Google中找不到答案.有人可以帮我一个忙吗?

But the information that I also need is the P-values. I failed to find the answer in google. Could someone do me a favor?

非常感谢您的帮助.

推荐答案

form 周围添加 eval():

set.seed(1234)
for(j in 1:2) {
  form <- formula(paste(names(data)[j], "~ x" ))
  model <- lqmm(eval(form), random=~1, group=id, weights=data$weight, data=data, tau=0.5, na.action=na.omit)
  print(summary(model)$tTable[2,5])
}
#[1] 7.055214e-07
#[1] 0.06919567

这篇关于无法从R循环中的lqmm函数提取p_value的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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