【发布时间】:2013-11-20 12:35:49
【问题描述】:
我在一个文件夹中有 3 个文件(200 列和 6 行的矩阵)
mat1 <- matrix(seq(1:1200), ncol = 200)
mat2 <- matrix(seq(1:1200), ncol = 200)
mat3 <- matrix(seq(1:1200), ncol = 200)
我在另一个文件夹中有另外 3 个文件(200 列和 6 行的矩阵)
at1 <- matrix(seq(1:1200), ncol = 200)
at2 <- matrix(seq(1:1200), ncol = 200)
at3 <- matrix(seq(1:1200), ncol = 200)
我想计算线性回归方程:
mat=a + b * at
例如,我们取第一个像素
mat1[1,1]........until mat3[1,1] and regress this with
at1[1,1]........until at3[1,1]
然后写输出(截距和b系数....)
做同样的事情:
mat1[1,2]........until mat3[1,2] and regress this with
at1[1,2]........until at3[1,2]
所以对于 mat1 中的每个像素,我将有截距和系数 b 最后会得到一个截距矩阵和一个b系数矩阵。
我知道我们只使用一个简单的矩阵:
model=lm(mat1~at1)
但对于时间数据,我不知道。有什么想法吗?
【问题讨论】:
-
您真的要计算 6*200 = 1200 个单独的线性回归吗?使用
sapply或for循环很容易,但这是一项奇怪的任务。请验证。 -
你昨天不是在这里问过同样的问题吗(现已删除)? stackoverflow.com/questions/20076785/…
标签: r linear-regression