简体   繁体   English

如何将多个线性回归斜率输出到新列表?

[英]How do I output multiple linear regression slopes to new list?

I have a data.frame and a list of observation http://imgur.com/7hL2bDC 我有一个data.frame和观察列表http://imgur.com/7hL2bDC

and a list of observation times http://imgur.com/w1P0qsg 以及观察时间列表http://imgur.com/w1P0qsg

and I want to create a list with the linear regression line slopes from each column of that data frame and the observation times. 我想创建一个列表,其中包含该数据帧各列的线性回归线斜率和观察时间。

If i was doing it all manually, I'd do: 如果我手动完成所有操作,则可以执行以下操作:

raw_slope <- lm(score1$AKR ~ obs) raw_slope <-lm(score1 $ AKR〜obs)

slope <- raw_slope$coefficients[[2]] 斜率<-raw_slope $ coefficients [[2]]

and then "slope" is the value I want. 然后“坡度”就是我想要的值。 I'm trying to understand how i can run something and spit out the slope for each of the 19 company symbols in my data.frame. 我试图了解如何运行某些数据,并为data.frame中的19个公司符号中的每个符号吐出斜率。

I'm kind of a novice at R but I'm trying to learn it, I appreciate any help pointing me in the right direction. 我是R的新手,但我正在尝试学习它,我感谢为我指明正确方向的任何帮助。

EDIT2: I ran lm(score1$... ~ obs) for each of the rows manually so i know the calculations should all work out. EDIT2:我为每行手动运行了lm(score1 $ ...〜obs),所以我知道计算应该全部解决。

EDIT: I tried the suggestion from the comments 编辑:我从评论中尝试了建议

listslope<-lapply(score1, function(x) coef(lm(x~obs))[2]) listlope <-lapply(分数1,函数(x)coef(lm(x〜obs))[2])

and am getting 越来越

Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : 0 (non-NA) cases lm.fit(x,y,offset = offset,singular.ok = singular.ok,...)中的错误:0(非NA)

I'm going to try and figure out what's causing the issue, but I wanted to update my post and say thanks. 我将尝试找出导致此问题的原因,但我想更新我的帖子并表示感谢。

lapply(score1, function(x) coef(lm(x~obs))[2])

Should give it to you in a list. 应该在列表中给您。

Use sapply if you'd prefer a vector. 如果您想使用向量,请使用sapply

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何找到多元回归的斜率? - How to find slopes of multiple regression? 如何将多个线性回归方程添加到 ggplot 的底部? - How do I add multiple linear regression equations to the bottom of a ggplot? 如何对在不同时间开始的列运行多个线性回归模型,新的 dataframe 为 output,在 R? - How to run multiple linear regression models for columns that start at different times, with a new dataframe as output, in R? R中多元线性回归的斜率比较 - Comparing slopes of multivariate linear regression in R 如何进行线性回归? - How to do this linear regression? 如何从简单线性回归 model 的模拟中生成 b1 系数列表? - How do I generate a list of b1 coefficients from simulations of a simple linear regression model? 如何使用向量作为我的预测变量来运行多元线性回归? - How do I run a multiple linear regression using a vector as my predictors? 在R中:如何在交互的预测变量上运行多元线性回归,而不对未交互的变量进行回归? - In R: How do I run a multiple linear regression on interacted predictors without regressing on the variables not interacted? 我如何解释这个 plot 和摘要(多元线性回归) - How do i interpret this plot and summary (multivariable linear regression) 如何在R中设置线性回归model中的权重? - How do I set the weighed in linear regression model in R?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM