将两个矩阵相乘(多个函数的相乘)-以获得Fisher判别线性函数分数
我有一组Fisher判别线性函数,需要与一些测试数据相乘。两个数据文件都是两个矩阵的形式(变量排列以匹配变量顺序),因此我需要将它们相乘。将两个矩阵相乘(多个函数的相乘)-以获得Fisher判别线性函数分数,r,R,我有一组Fisher判别线性函数,需要与一些测试数据相乘。两个数据文件都是两个矩阵的形式(变量排列以匹配变量顺序),因此我需要将它们相乘。 这里是一些示例测试数据,我添加了一个常量=1变量(当我们得到系数时,您将看到原因) 这有点像是每行系数的和积,每一个函数的时间是3。 因此,当将相同数量的行与3个函数得分变量相乘时,df/矩阵应该是这样的 > df_result Function1 Function2 Function3 row1
这里是一些示例测试数据,我添加了一个常量=1变量(当我们得到系数时,您将看到原因) 这有点像是每行系数的和积,每一个函数的时间是3。 因此,当将相同数量的行与3个函数得分变量相乘时,df/矩阵应该是这样的
> df_result
Function1 Function2 Function3
row1 53.24 54.33 44.99
row2
不太理想,但我会把数据拿出来做excel。如果这是可能的,任何帮助都将不胜感激。非常感谢您只是在寻找内部产品吗
testdata <- cbind(constant=1,mtcars[ 1:6 ,c("mpg","disp","hp") ])
coefs <- data.frame(constant = c(-67.67, -59.46, -89.70),
mpg = c(4.01,3.49,3.69),
disp = c(0.14,0.15,0.22),
hp = c(0.13,0.15,0.20))
rownames(coefs) <- c("Function1","Function2","Function3")
as.matrix(testdata) %*% t(as.matrix(coefs))
# Function1 Function2 Function3
# Mazda RX4 53.240 54.330 44.990
# Mazda RX4 Wag 53.240 54.330 44.990
# Datsun 710 50.968 50.262 36.792
# Hornet 4 Drive 68.564 70.426 68.026
# Hornet Sportabout 80.467 86.053 93.503
# Valiant 50.061 53.209 47.589
testdata
for the first row, Function1 = 1*(-67.67)+21*(4.01)+160*(0.14)+110*(0.13)
for the first row, Function2 = 1*(-59.46)+21*(3.49)+160*(0.15)+110*(0.15)
for the first row, Function3 = 1*(-89.70)+21*(3.69)+160*(0.22)+110*(0.20)
> df_result
Function1 Function2 Function3
row1 53.24 54.33 44.99
row2
testdata <- cbind(constant=1,mtcars[ 1:6 ,c("mpg","disp","hp") ])
coefs <- data.frame(constant = c(-67.67, -59.46, -89.70),
mpg = c(4.01,3.49,3.69),
disp = c(0.14,0.15,0.22),
hp = c(0.13,0.15,0.20))
rownames(coefs) <- c("Function1","Function2","Function3")
as.matrix(testdata) %*% t(as.matrix(coefs))
# Function1 Function2 Function3
# Mazda RX4 53.240 54.330 44.990
# Mazda RX4 Wag 53.240 54.330 44.990
# Datsun 710 50.968 50.262 36.792
# Hornet 4 Drive 68.564 70.426 68.026
# Hornet Sportabout 80.467 86.053 93.503
# Valiant 50.061 53.209 47.589