有谁知道如何解决这个问题附着在两行代码?我相信as.matrix会创建一个矩阵,X
,然后使用X %*% X
,t(X)
和solve(X)
来获得答案。但是,它似乎并没有工作。任何答案都会有所帮助,谢谢。
Q
计算系数
-3
A
回答
1
我会建议使用read.csv
代替read.table
这将是有益的,你走过去的两个功能在这个线程的区别:基于@kon_u的答案read.csv vs. read.table
df <- read.csv("http://pengstats.macssa.com/download/rcc/lmdata.csv")
model1 <- lm(y ~ x1 + x2, data = df)
coefficients(model1) # get the coefficients of your regression model1
summary(model1) # get the summary of model1
0
,这里是一个用手做的例子:
df <- read.csv("http://pengstats.macssa.com/download/rcc/lmdata.csv")
model1 <- lm(y ~ x1 + x2, data = df)
coefficients(model1) # get the coefficients of your regression model1
summary(model1) # get the summary of model1
### Based on the formula
X <- cbind(1, df$x1, df$x2) # the column of 1 is to consider the intercept
Y <- df$y
bhat <- solve(t(X) %*% X) %*% t(X) %*% Y # coefficients
bhat # Note that we got the same coefficients with the lm function
+0
请注意,此公式允许您也计算多元线性回归的系数。 – ANG
相关问题
- 1. 计算Tanimoto系数
- 2. 计算FFT相关系数
- 3. 计算聚类系数
- 4. 计算二项式系数的算法
- 5. 计算传递函数系数
- 6. 计算一系列
- 7. DAX计算关系
- 8. 计算android系统
- 9. 计算机I/O-计算机系统和体系结构
- 10. 产品排序计算系数
- 11. scipy计算的多项系数
- 12. 序言 - 计算世代数的关系
- 13. 计算机代数系统介绍?
- 14. 并行计算二项式系数
- 15. SPARQL一次计算关系数
- 16. 从频率响应计算FIR系数
- 17. 计算iir滤波器的w系数
- 18. 使用PostgreSQL计算相关系数?
- 19. 在Python中计算确定系数
- 20. Pearson相关系数计算阵列
- 21. 如何计算rsa私钥的系数?
- 22. 计算数学系列PostgreSQL的
- 23. Python - 如何使用计算系数
- 24. 计算穿越系列或数据帧
- 25. 高效纵列相关系数计算
- 26. 计算每年2%的折扣系数
- 27. 与GGPLOT2计算相关系数R中
- 28. 构建计算机代数系统
- 29. 需要使用MATLAB计算Pearson系数
- 30. 如何计算Neo4j中的关系数
请告诉我们你到目前为止试过的东西。这将有助于您生成[可重现的示例](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) –