gpt4 book ai didi

r - 在 ezANOVA 函数中动态定义因变量和自变量

转载 作者:行者123 更新时间:2023-12-03 15:52:59 25 4
gpt4 key购买 nike

我想运行一个 ezANOVA来自 ez在循环中打包多个因变量并将结果保存到多个变量中。每个因变量位于同一数据框的单独列中。

all.dependent.variables <- c("dv1", "dv2")

for(dependent.variable in all.dependent.variables){
assign(paste(dependent.variable, ".aov.results", sep = ""),
ezANOVA(aov.data,
dv = dependent.variable,
wid = subject,
within = .(factor1, factor2),
return_aov = TRUE))
}

这是一个示例数据框:
aov.data <- structure(list(subject = structure(c(10L, 11L, 12L, 1L, 2L, 3L, 
4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L, 6L,
7L, 8L, 9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L,
10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L,
12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 1L, 2L,
3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L,
6L, 7L, 8L, 9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L,
9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L,
12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 1L, 2L,
3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L,
6L, 7L, 8L, 9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L,
9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L,
12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11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L, 4L, 5L,
6L, 7L, 8L, 9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L,
9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L,
12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 1L, 2L,
3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L,
6L, 7L, 8L, 9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L,
9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L,
12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L), .Label = c("1", "2",
"3", "4", "5", "6", "7", "8", "9", "10", "11", "12"), class = "factor"),
dv1 = c(650.2, 773.7, 686.4, 436.2, 625.3, 714.2, 892.6, 921.5,
711.2, 670.2, 725.8, 592.8, 672.7, 731.1, 707.2, 475.1, 645.4,
786.7, 949.5, 925.8, 715.5, 745.4, 750.8, 579.1, 683.3, 707.6,
693.7, 492.4, 698.8, 666.9, 914.4, 853.8, 724.4, 718.8, 872.9,
616.9, 706.4, 766.2, 676.2, 500, 753.8, 712.7, 1012.2, 947.8,
695.3, 735.6, 843.7, 596.1, 738.3, 705.2, 718.2, 534.1, 805.3,
814.1, 969.4, 1010.7, -999, 714.4, 815.4, 645.4, 835.4, 830.7,
776.7, 543.7, 757.2, 841.5, 1107.8, 915.8, -999, 707.4, 809.7,
671.1, 638.1, 726.7, 660.2, 455.7, 623.5, 716.1, 922.1, 804.5,
718.2, 674.6, 797.4, 572, 676.7, 726.6, 690.7, 498.8, 624.3,
764.1, 889.5, 823.4, 672.9, 701.8, 750.4, 557.2, 656.1, 701,
655.1, 472.7, 658.8, 660.6, 860.9, 811.3, 672.5, 681.7, 849.6,
571.2, 694, 777.5, 661.3, 488, 670.4, 725.3, 938.1, 862.7,
616.4, 732.2, 845.9, 582.4, 694.2, 694.6, 743.8, 480.5, 736.7,
740.9, 988.1, 827.5, 812.4, 725.5, 844.2, 628, 779.3, 770.3,
686.9, 494.3, 681.5, 850.5, 990.7, 810.1, 692.3, 779.7, 779.8,
590.4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
618.6, 713.9, 609.6, 468.6, 554.3, 580.8, 864.1, 843.3, 662.8,
645.5, 714.6, 555.5, 670.7, 759.3, 652.2, 468.1, 613.5, 712.3,
910.7, 782.4, 723.3, 742.8, 775.5, 553.2, 695.3, 726.2, 591.2,
479.2, 626.1, 643.3, 821.5, 753.9, 818.2, 655.8, 754.4, 592.9,
703.5, 792.5, 635, 485.3, 644.1, 667.9, 891.3, 780.9, 699.1,
725.1, 716, 587.2, 706.5, 754.6, 694.3, 485.5, 745.5, 649.3,
808.4, 780.5, 773.8, 676.3, 687.5, 685.3, 910.4, 821.5, 738.5,
525, 689.6, 758.4, 1021.5, 792, 789.3, 740.5, 722.8, 717.1,
653.3, 743.6, 620.3, 460.1, 575.3, 647.1, 849.3, 647, 691.2,
596.4, 714.6, 531.6, 678.7, 754.7, 600.4, 463.8, 560.8, 636.6,
844.3, 766.6, 725.3, 628.7, 784.4, 547.9, 630.3, 656.7, 705.3,
443.3, 607, 630.7, 861.5, 754.4, 770.8, 664.5, 728.3, 546.4,
741.5, 694, 620.4, 459.3, 587.9, 626.2, 893.8, 756.1, 731.8,
680.2, 836.4, 566.7, 619.4, 686.4, 704, 445.3, 652.7, 735.3,
839.4, 833.4, 763.7, 614.5, 794.4, 562.5, 713.2, 735.4, 655.4,
501.1, 635.6, 661.2, 880.6, 747.8, 807.8, 757.7, 772.4, 560.1,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 662.7,
682.5, 590.1, 443.6, 623.2, 656.6, 852.6, 676.8, 646.6, 646,
677.6, 518, 664, 665.4, 609.8, 464.2, 696.5, 661, 894.7,
661.1, 659.6, 657.8, 713.4, 531.5, 739.5, 695.1, 656.5, 498.4,
648.1, 710, 897.8, 685, 671.3, 657, 767.5, 545.3, 808.6,
697.5, 667.2, 463.4, 695.3, 652.4, 857.2, 690.3, 766.1, 696.1,
690.5, 558.8, 746, 708.4, 690, 515.5, 788.8, 929.6, 802.1,
619.5, 510.8, 654.1, 811.8, 706.5, 977.8, 697.9, 700.9, 497.9,
700.9, 811.5, 969.3, 723, 886, 815.7, 757.5, 639.5, 688.4,
704, 617.8, 435.2, 628.8, 603.3, 865.3, 661.6, 645.9, 598.1,
646.8, 477.2, 646.8, 760.8, 634.3, 452.2, 600.1, 648.2, 923.8,
625.5, 676.9, 647.3, 688.6, 513.2, 591.9, 641.6, 632.6, 469.6,
606.4, 610.9, 835.1, 667.8, 599.7, 581.2, 704.4, 502.9, 746.9,
684.1, 689.3, 475.9, 692, 689, 824.9, 625.9, 696.4, 706.3,
715.3, 510.9, 650.9, 640.1, 663.5, 471.6, 682.3, 683.2, 831.9,
702, 685, 624.6, 698.2, 521.6, 759.8, 730.6, 661.1, 473.2,
644.4, 738.7, 932.5, 685.1, 816, 722.1, 783.3, 526.2, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), dv2 = c(2.941,
2.941, 5.882, 0, 0, 2.941, 8.824, 23.529, 35.294, 8.824,
17.647, 5.882, 2.941, 2.941, 2.941, 0, 0, 8.824, 8.824, 44.118,
29.412, 8.824, 2.941, 5.882, 5.882, 0, 5.882, 5.882, 0, 2.941,
23.529, 20.588, 17.647, 8.824, 8.824, 11.765, 2.941, 2.941,
8.824, 17.647, 0, 5.882, 26.471, 14.706, 47.059, 0, 17.647,
14.706, 23.529, 0, 23.529, 38.235, 17.647, 52.941, 61.765,
55.882, 94.118, 5.882, 41.176, 55.882, 17.647, 23.529, 35.294,
32.353, 20.588, 44.118, 55.882, 44.118, 85.294, 17.647, 41.176,
55.882, 0, 0, 0, 0, 0, 5.882, 5.882, 0, 29.412, 0, 0, 0,
0, 0, 0, 0, 0, 0, 5.882, 0, 32.353, 0, 5.882, 0, 0, 0, 0,
0, 0, 2.941, 5.882, 0, 20.588, 0, 0, 0, 2.941, 0, 0, 0, 0,
0, 11.765, 2.941, 35.294, 0, 0, 0, 2.941, 0, 5.882, 0, 0,
20.588, 29.412, 8.824, 55.882, 0, 2.941, 5.882, 0, 0, 5.882,
2.941, 2.941, 2.941, 14.706, 0, 52.941, 0, 11.765, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2.941,
0, 0, 5.882, 5.882, 29.412, 32.353, 5.882, 5.882, 0, 2.941,
0, 5.882, 0, 0, 0, 11.765, 41.176, 23.529, 5.882, 5.882,
0, 17.647, 5.882, 17.647, 2.941, 2.941, 8.824, 26.471, 26.471,
44.118, 11.765, 11.765, 26.471, 2.941, 0, 5.882, 0, 0, 8.824,
17.647, 23.529, 44.118, 2.941, 5.882, 11.765, 20.588, 5.882,
17.647, 26.471, 17.647, 55.882, 47.059, 55.882, 61.765, 5.882,
32.353, 55.882, 41.176, 2.941, 38.235, 35.294, 0, 76.471,
50, 67.647, 76.471, 14.706, 55.882, 55.882, 5.882, 2.941,
0, 0, 0, 0, 2.941, 0, 35.294, 0, 2.941, 0, 5.882, 0, 0, 0,
0, 8.824, 8.824, 2.941, 20.588, 0, 0, 0, 5.882, 2.941, 0,
0, 0, 0, 2.941, 0, 35.294, 2.941, 0, 0, 0, 0, 2.941, 0, 0,
2.941, 0, 0, 38.235, 0, 2.941, 0, 8.824, 2.941, 0, 0, 0,
32.353, 26.471, 17.647, 41.176, 2.941, 0, 0, 2.941, 2.941,
5.882, 0, 0, 11.765, 8.824, 0, 55.882, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2.941, 0, 5.882,
0, 0, 0, 5.882, 11.765, 26.471, 8.824, 2.941, 2.941, 2.941,
0, 8.824, 0, 0, 0, 11.765, 2.941, 11.765, 0, 8.824, 0, 8.824,
2.941, 11.765, 5.882, 2.941, 2.941, 26.471, 20.588, 26.471,
0, 2.941, 17.647, 11.765, 0, 2.941, 0, 2.941, 17.647, 20.588,
20.588, 26.471, 8.824, 5.882, 11.765, 35.294, 14.706, 32.353,
41.176, 5.882, 44.118, 52.941, 47.059, 73.529, 17.647, 50,
47.059, 35.294, 11.765, 32.353, 50, 8.824, 73.529, 76.471,
47.059, 82.353, 14.706, 47.059, 41.176, 0, 0, 0, 2.941, 0,
0, 14.706, 2.941, 8.824, 0, 0, 0, 8.824, 2.941, 0, 0, 0,
5.882, 0, 2.941, 2.941, 0, 5.882, 0, 8.824, 0, 2.941, 0,
0, 2.941, 2.941, 2.941, 11.765, 5.882, 0, 0, 2.941, 0, 2.941,
0, 0, 2.941, 2.941, 0, 17.647, 5.882, 2.941, 0, 5.882, 5.882,
11.765, 0, 0, 8.824, 32.353, 0, 44.118, 2.941, 5.882, 0,
2.941, 5.882, 11.765, 0, 0, 8.824, 17.647, 2.941, 50, 8.824,
5.882, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0), factor1 = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1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, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("level1", "level2", "level3"
), class = "factor")), .Names = c("subject", "dv1", "dv2",
"factor1", "factor2"), row.names = c(NA, 540L), class = "data.frame")

这种方法的问题在于 R 解释了索引 dependent.variable作为数据框中列的说明符 aov.data因此返回以下错误:

"dependent.variable" is not a variable in the data frame provided.



我试过用 eval() 包装索引或 print()但无济于事。

最佳答案

另一个不好的解决方案:

lapply(all.dependent.variables, function(i) {
eval(parse(text=
paste0('ezANOVA(data=aov.data,
dv=', i,',
wid=subject,
between=.(factor1, factor2),
return_aov = TRUE)')
))
})

关于r - 在 ezANOVA 函数中动态定义因变量和自变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12516260/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com