r - Extract error matrix from manova analysis in r
问题描述
I used car
package to perform anova analysis. Here I got sum of squares for error and factor (=Site) in the form of matrix. Code is here
library(car)
## One-Way MANOVA
anv<-summary(Anova(lm(cbind(Al, Fe, Mg, Ca, Na) ~ Site, data=Pottery)))
anv
Now I want to extract these two matrices from this result for next analysis. My desired output is like this-
>err_ss
Al Fe Mg Ca Na
Al 48.2881429 7.08007143 0.60801429 0.10647143 0.58895714
Fe 7.0800714 10.95084571 0.52705714 -0.15519429 0.06675857
Mg 0.6080143 0.52705714 15.42961143 0.43537714 0.02761571
Ca 0.1064714 -0.15519429 0.43537714 0.05148571 0.01007857
Na 0.5889571 0.06675857 0.02761571 0.01007857 0.19929286
>Site_ss
Al Fe Mg Ca Na
Al 175.610319 -149.295533 -130.809707 -5.8891637 -5.3722648
Fe -149.295533 134.221616 117.745035 4.8217866 5.3259491
Mg -130.809707 117.745035 103.350527 4.2091613 4.7105458
Ca -5.889164 4.821787 4.209161 0.2047027 0.1547830
Na -5.372265 5.325949 4.710546 0.1547830 0.2582456
After using the following code I got the result of error matrix but I failed to extract the last one.
str(anv)
err_ss<-anv$"SSPE"
> err_ss
Al Fe Mg Ca Na
Al 48.2881429 7.08007143 0.60801429 0.10647143 0.58895714
Fe 7.0800714 10.95084571 0.52705714 -0.15519429 0.06675857
Mg 0.6080143 0.52705714 15.42961143 0.43537714 0.02761571
Ca 0.1064714 -0.15519429 0.43537714 0.05148571 0.01007857
Na 0.5889571 0.06675857 0.02761571 0.01007857 0.19929286
Could anyone please help me to do it? Thanks in advance.
解决方案
我们需要根据结构进行提取。如果我们看str(anv)
,它是list
7 个元素中的一个。“SSPE”、“SSPH”元素位于“multivariate.tests”的“Site”元素下。所以用其中一个提取它们,$
然后[[
得到两个矩阵
out <- anv$multivariate.tests$Site[c("SSPE", "SSPH")]
out
#$SSPE
# Al Fe Mg Ca Na
#Al 48.2881429 7.08007143 0.60801429 0.10647143 0.58895714
#Fe 7.0800714 10.95084571 0.52705714 -0.15519429 0.06675857
#Mg 0.6080143 0.52705714 15.42961143 0.43537714 0.02761571
#Ca 0.1064714 -0.15519429 0.43537714 0.05148571 0.01007857
#Na 0.5889571 0.06675857 0.02761571 0.01007857 0.19929286
#$SSPH
# Al Fe Mg Ca Na
#Al 175.610319 -149.295533 -130.809707 -5.8891637 -5.3722648
#Fe -149.295533 134.221616 117.745035 4.8217866 5.3259491
#Mg -130.809707 117.745035 103.350527 4.2091613 4.7105458
#Ca -5.889164 4.821787 4.209161 0.2047027 0.1547830
#Na -5.372265 5.325949 4.710546 0.1547830 0.2582456
最好将其保存在 alist
中,而不是拥有多个对象。
推荐阅读
- flutter - 如何在颤振小部件测试中捕获来自未来的错误?
- ios - 使用空缓冲区调用 AudioQueueInputCallback
- python - pyqtgraph中填充图的透明度
- rx-java2 - 发出并行流但始终包含所有流的最后一个发射的可观察对象或运算符
- python - Django:按月聚合超过十二个月的问题
- c# - 如何处理连续的 GET 请求?
- python - 在 re.sub 中使用变量名
- powershell - 在复制到某个文件夹之前重命名文件
- android - action_send Intent 后退按钮需要按两次才能关闭活动
- spring-boot - 具有多个相同类型 bean 的自定义自动配置