从ezANOVA输出创建data.frame

时间:2019-04-20 20:30:04

标签: r anova

我刚刚使用ezANOVA运行了一个混合方差分析,我需要创建一个带有输出的数据框以提取到Rmd中,但是我找不到有关如何执行此操作的任何信息。

我以前使用过aov()broom::tidy(),但是tidy()无法格式化从ezANOVA获得的输出。我已经尝试过as.data.frame,但是结果是一个非常混乱的数据帧,所以我宁愿不使用它。有人知道一种类似于tidy()的易于读取的数据帧的解决方案吗?

我的方差分析:

library(ez)

aov <- b <- ezANOVA(data=exp1.long,
        dv=consensus,
        wid=participant_id,
        within=trait,
        between=age_group,
        type=3,
        detailed=T 
        )

2 个答案:

答案 0 :(得分:1)

您是否尝试过添加return_aov = TRUE

 b <- ezANOVA(data=exp1.long,
      dv=consensus,
      wid=participant_id,
      within=trait,
      between=age_group,
      type=3,
      detailed=T 
    return_aov = TRUE
    )

return_aov命令(如果在TRUE上进行了设置)将计算并返回与请求的aov相对应的ANOVA对象(用于计算事后对比)。

有关详细信息,请参阅: https://rdrr.io/cran/ez/man/ezANOVA.html

答案 1 :(得分:0)

诀窍是:

{
    "name": "srf",
    "version": "7.1.4",
    "private": true,
    "homepage": "/",
    "scripts": {
        "start": "react-scripts start -o",
        "build": "react-scripts --max_old_space_size=8192 build",
        "test": "react-scripts test",
        "citest": "CI=true react-scripts test",
        "eject": "react-scripts eject",
        "lint": "eslint src",
        "format": "prettier --write \"src/**/*.{js,css,scss,html}\"",
        "rtl": "webpack"
    },
    "eslintConfig": {
        "extends": "react-app"
    },
    "browserslist": {
        "production": [
            ">0.2%",
            "not dead",
            "not op_mini all",
            "ie 11"
        ],
        "development": [
            "last 1 chrome version",
            "last 1 firefox version",
            "last 1 safari version",
            "last 1 edge version",
            "IE 11"
        ]
    },
    "dependencies": {
        "@amcharts/amcharts4": "^4.10.16",
        "@date-io/date-fns": "1.3.13",
        "@formatjs/intl-pluralrules": "1.3.5",
        "@fortawesome/fontawesome-free": "5.13.0",
        "@manaflair/redux-batch": "1.0.0",
        "@material-ui/core": "4.9.14",
        "@material-ui/icons": "4.9.1",
        "@material-ui/lab": "4.0.0-alpha.53",
        "@material-ui/pickers": "3.2.10",
        "@material-ui/styles": "4.9.14",
        "@material/react-text-field": "^0.15.0",
        "@reduxjs/toolkit": "1.3.6",
        "@tanem/svg-injector": "8.0.50",
        "apexcharts": "3.25.0",
        "axios": "0.19.2",
        "axios-mock-adapter": "1.18.1",
        "bootstrap": "4.5.0",
        "clipboard-copy": "3.1.0",
        "clsx": "1.1.0",
        "cp-cli": "2.0.0",
        "css-mediaquery": "0.1.2",
        "date-fns": "2.8.1",
        "downshift": "3.4.2",
        "fg-loadcss": "2.1.0",
        "formik": "2.1.4",
        "ga-4-react": "^0.1.271",
        "jsencrypt": "^3.1.0",
        "json2mq": "0.2.0",
        "jss-rtl": "^0.3.0",
        "lodash": "4.17.15",
        "material-ui-popup-state": "1.4.1",
        "moment": "^2.29.1",
        "npm-lifecycle": "^3.1.5",
        "object-path": "0.11.4",
        "perfect-scrollbar": "1.5.0",
        "prop-types": "15.7.2",
        "react": "16.12.0",
        "react-bootstrap": "1.0.1",
        "react-bootstrap-table-next": "4.0.2",
        "react-bootstrap-table2-paginator": "2.1.2",
        "react-datepicker": "2.16.0",
        "react-dom": "16.12.0",
        "react-draggable": "4.4.2",
        "react-dropdown-tree-select": "^2.5.1",
        "react-ga": "^3.3.0",
        "react-google-login": "^5.2.2",
        "react-gtm-module": "^2.0.11",
        "react-inlinesvg": "1.2.0",
        "react-intl": "3.6.2",
        "react-is": "16.13.1",
        "react-moment": "^1.1.1",
        "react-multiselect-checkboxes": "^0.1.1",
        "react-perfect-scrollbar": "1.5.8",
        "react-portal": "4.2.0",
        "react-redux": "7.1.3",
        "react-responsive-modal": "^6.0.1",
        "react-router-dom": "5.1.2",
        "react-router-redux": "^4.0.8",
        "react-scripts": "4.0.2",
        "react-select": "3.1.0",
        "react-show-more-text": "^1.4.6",
        "react-swipeable-views": "0.13.9",
        "react-syntax-highlighter": "12.2.1",
        "react-transition-group": "^4.4.2",
        "react-window": "1.8.5",
        "redux": "4.0.5",
        "redux-persist": "6.0.0",
        "redux-saga": "1.1.3",
        "socicon": "3.0.5",
        "websocket": "^1.0.33",
        "yup": "0.29.0",
        "yup-phone-lite": "^1.0.4"
    },
    "devDependencies": {
        "@babel/core": "^7.12.16",
        "@testing-library/react": "^11.2.5",
        "@testing-library/user-event": "^12.7.1",
        "babel-jest": "^26.6.3",
        "copyfiles": "2.1.1",
        "jest": "^26.6.3",
        "jest-dom": "^4.0.0",
        "jest-watch-typeahead": "^0.6.1",
        "nock": "^13.0.7",
        "prettier": "1.19.1",
        "sass": "1.34.1",
        "serve": "11.2.0",
        "webpack-cli": "3.3.11",
        "webpack-messages": "2.0.4",
        "webpack-rtl-plugin": "2.0.0"
    }
}

然后我们可以检查生成的 df <- as.data.frame(print(aov)) 类以确认它正常工作:

df

并检查输出(注意:使用了我自己的数据):

class(df)
"data.frame"

说明: df ANOVA.Effect ANOVA.DFn ANOVA.DFd ANOVA.F ANOVA.p ANOVA.p..05 ANOVA.ges 2 COND1 1 53 4.1938628 0.01947959 * 0.0070548612 3 COND2 1 53 3.6018758 0.02962809 * 0.0040817987 4 COND1:COND2 1 53 0.8371797 0.24026453 0.0008646178 参数确实添加了一个 return_aov = TRUE 对象,当用作 aov 时可以提供类似的结果。但是,结果仍然不是数据帧,尝试 summary(aov$aov) 输出 as.data.frame(summary(aov$aov))

希望这能提供您想要的结果。