在 80 个相关结果的同一个列表上运行多个自变量的回归模型的最有效方法? [英] Most efficient way to run regression models for multiple independent variables on the same list of 80 dependent outcomes?

查看:39
本文介绍了在 80 个相关结果的同一个列表上运行多个自变量的回归模型的最有效方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为 20 个自变量(例如遗传变异,这些遗传变异中的每一个都将单独测试)和 40 个因变量运行回归模型的最有效方法是什么?我是 R 的初学者!我找到了一个解决方案,但只有当我有 1 个自变量时它才有效.不知道如果我有很多 (http://techxhum.dk/loop-multiple-变量/)

What is the most efficient way to run regression models for a list of 20 independent variables (e.g. genetic variants, each of these genetic variants will be tested alone) and 40 dependent variables? I am a beginner to R! I found a solution but it would work only if I had 1 independent variable. Not sure how I would go about if I had many (http://techxhum.dk/loop-multiple-variables/)

感谢您的时间.

推荐答案

这是一个使用MESS 包中的mfastLmCpp() 函数的密集解决方案.它对多个工具运行简单的线性回归,我们只需将它包装在一个 apply() 调用中,以使其与多个因变量一起工作.

Here's a somewhat dense solution that uses the mfastLmCpp() function from the MESS package. It runs simple linear regression for multiple instruments and we just wrap it in an apply() call to get it to work with multiple dependent variables.

N <- 1000  # Number of observations
Nx <- 20   # Number of independent variables
Ny <- 80   # Number of dependent variables

# Simulate outcomes that are all standard Gaussians
Y <- matrix(rnorm(N*Ny), ncol=Ny)  
X <- matrix(rnorm(N*Nx), ncol=Nx)

# Now loop over each dependent variable and get a list of t test statistics
# for each independent variabel
apply(Y, 2, FUN=function(y) { MESS::mfastLmCpp(y=y, x=X) })

通过上述设置,在我的笔记本电脑上只需不到一秒钟的时间.

With the above setup it takes less than a second on my laptop.

更新:将功能添加到 MESS 包中的 plr 函数.

Update: Added the functionality to the plr function in the MESS package.

devtools::install_github('ekstroem/MESS')
plr(Y, X)

等等!

这篇关于在 80 个相关结果的同一个列表上运行多个自变量的回归模型的最有效方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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