0

在我使用 进行多项逻辑回归后,我尝试计算边际效应mlogit

reg1 <- mlogit::mlogit(formula = value ~ 1 | ScoreEnvAtt, data = listDatasets[[2]])
reg1
summary(reg1)

z <- with(listDatasets[[2]], data.frame(ScoreEnvAtt = tapply(ScoreEnvAtt, index(reg1)$alt, mean)))

effects(reg1,covariate="ScoreEnvAtt",data=z)

但是在定义z.

    z <- with(listDatasets[[2]], data.frame(ScoreEnvAtt = tapply(ScoreEnvAtt, index(reg1)$alt, mean)))
Error in tapply(ScoreEnvAtt, index(reg1)$alt, mean) : 
  Argumente müssen die selbe Länge haben

(参数必须具有相同的长度)。而我就是无法解决。有人有想法吗?

head(listDatasets[[2]])
                 index Age ScoreEnvAtt MoneyInvested Gender Beliefs_eff_Green Beliefs_eff_ESG Beliefs_eff_Comp Beliefs_perf_ESG Beliefs_perf_Green Beliefs_perf_Comp Guilt Social.Altruistic Biospheric Egoistic DummyMedium
    1.SS_Green_1     1  26         4.2            13      2                 4               3                3                2                  3                 2    71          6.000000   6.000000        5           1
    1.SS_Green_2     1  26         4.2            13      2                 4               3                3                2                  3                 2    71          6.000000   6.000000        5           1
    1.SS_Green_3     1  26         4.2            13      2                 4               3                3                2                  3                 2    71          6.000000   6.000000        5           1
    1.SS_Green_4     1  26         4.2            13      2                 4               3                3                2                  3                 2    71          6.000000   6.000000        5           1
    2.SS_Green_1     2  30         4.8             2      2                 4               3                4                2                  3                 3    26          6.666667   5.333333        5           1
    2.SS_Green_2     2  30         4.8             2      2                 4               3                4                2                  3                 3    26          6.666667   5.333333        5           1
                 DummyHigh CompensationGroup Past_compensation Knowledge_CO2   variable value price
    1.SS_Green_1         0            Group1                 2             1 SS_Green_1 FALSE   1.5
    1.SS_Green_2         0            Group1                 2             1 SS_Green_2 FALSE   1.5
    1.SS_Green_3         0            Group1                 2             1 SS_Green_3 FALSE   1.5
    1.SS_Green_4         0            Group1                 2             1 SS_Green_4  TRUE   1.3
    2.SS_Green_1         0            Group2                 2             2 SS_Green_1 FALSE   1.5
    2.SS_Green_2         0            Group2                 2             2 SS_Green_2 FALSE   1.5

编辑:

> dput(head(listDatasets[[2]]))
structure(list(index = c(`1.SS_Green_1` = 1, `1.SS_Green_2` = 1, 
`1.SS_Green_3` = 1, `1.SS_Green_4` = 1, `2.SS_Green_1` = 2, `2.SS_Green_2` = 2
), Age = c(`1.SS_Green_1` = 26, `1.SS_Green_2` = 26, `1.SS_Green_3` = 26, 
`1.SS_Green_4` = 26, `2.SS_Green_1` = 30, `2.SS_Green_2` = 30
), ScoreEnvAtt = c(`1.SS_Green_1` = 4.2, `1.SS_Green_2` = 4.2, 
`1.SS_Green_3` = 4.2, `1.SS_Green_4` = 4.2, `2.SS_Green_1` = 4.8, 
`2.SS_Green_2` = 4.8), MoneyInvested = c(`1.SS_Green_1` = 13, 
`1.SS_Green_2` = 13, `1.SS_Green_3` = 13, `1.SS_Green_4` = 13, 
`2.SS_Green_1` = 2, `2.SS_Green_2` = 2), Gender = c(`1.SS_Green_1` = 2, 
`1.SS_Green_2` = 2, `1.SS_Green_3` = 2, `1.SS_Green_4` = 2, `2.SS_Green_1` = 2, 
`2.SS_Green_2` = 2), Beliefs_eff_Green = c(`1.SS_Green_1` = 4, 
`1.SS_Green_2` = 4, `1.SS_Green_3` = 4, `1.SS_Green_4` = 4, `2.SS_Green_1` = 4, 
`2.SS_Green_2` = 4), Beliefs_eff_ESG = c(`1.SS_Green_1` = 3, 
`1.SS_Green_2` = 3, `1.SS_Green_3` = 3, `1.SS_Green_4` = 3, `2.SS_Green_1` = 3, 
`2.SS_Green_2` = 3), Beliefs_eff_Comp = c(`1.SS_Green_1` = 3, 
`1.SS_Green_2` = 3, `1.SS_Green_3` = 3, `1.SS_Green_4` = 3, `2.SS_Green_1` = 4, 
`2.SS_Green_2` = 4), Beliefs_perf_ESG = c(`1.SS_Green_1` = 2, 
`1.SS_Green_2` = 2, `1.SS_Green_3` = 2, `1.SS_Green_4` = 2, `2.SS_Green_1` = 2, 
`2.SS_Green_2` = 2), Beliefs_perf_Green = c(`1.SS_Green_1` = 3, 
`1.SS_Green_2` = 3, `1.SS_Green_3` = 3, `1.SS_Green_4` = 3, `2.SS_Green_1` = 3, 
`2.SS_Green_2` = 3), Beliefs_perf_Comp = c(`1.SS_Green_1` = 2, 
`1.SS_Green_2` = 2, `1.SS_Green_3` = 2, `1.SS_Green_4` = 2, `2.SS_Green_1` = 3, 
`2.SS_Green_2` = 3), Guilt = c(`1.SS_Green_1` = 71, `1.SS_Green_2` = 71, 
`1.SS_Green_3` = 71, `1.SS_Green_4` = 71, `2.SS_Green_1` = 26, 
`2.SS_Green_2` = 26), Social.Altruistic = c(`1.SS_Green_1` = 6, 
`1.SS_Green_2` = 6, `1.SS_Green_3` = 6, `1.SS_Green_4` = 6, `2.SS_Green_1` = 6.66666666666667, 
`2.SS_Green_2` = 6.66666666666667), Biospheric = c(`1.SS_Green_1` = 6, 
`1.SS_Green_2` = 6, `1.SS_Green_3` = 6, `1.SS_Green_4` = 6, `2.SS_Green_1` = 5.33333333333333, 
`2.SS_Green_2` = 5.33333333333333), Egoistic = c(`1.SS_Green_1` = 5, 
`1.SS_Green_2` = 5, `1.SS_Green_3` = 5, `1.SS_Green_4` = 5, `2.SS_Green_1` = 5, 
`2.SS_Green_2` = 5), DummyMedium = structure(c(`1.SS_Green_1` = 2L, 
`1.SS_Green_2` = 2L, `1.SS_Green_3` = 2L, `1.SS_Green_4` = 2L, 
`2.SS_Green_1` = 2L, `2.SS_Green_2` = 2L), .Label = c("0", "1"
), class = c("pseries", "factor")), DummyHigh = structure(c(`1.SS_Green_1` = 1L, 
`1.SS_Green_2` = 1L, `1.SS_Green_3` = 1L, `1.SS_Green_4` = 1L, 
`2.SS_Green_1` = 1L, `2.SS_Green_2` = 1L), .Label = c("0", "1"
), class = c("pseries", "factor")), CompensationGroup = structure(c(`1.SS_Green_1` = 1L, 
`1.SS_Green_2` = 1L, `1.SS_Green_3` = 1L, `1.SS_Green_4` = 1L, 
`2.SS_Green_1` = 2L, `2.SS_Green_2` = 2L), .Label = c("Group1", 
"Group2", "Group3"), class = c("pseries", "factor")), Past_compensation = c(`1.SS_Green_1` = 2, 
`1.SS_Green_2` = 2, `1.SS_Green_3` = 2, `1.SS_Green_4` = 2, `2.SS_Green_1` = 2, 
`2.SS_Green_2` = 2), Knowledge_CO2 = c(`1.SS_Green_1` = 1, `1.SS_Green_2` = 1, 
`1.SS_Green_3` = 1, `1.SS_Green_4` = 1, `2.SS_Green_1` = 2, `2.SS_Green_2` = 2
), variable = structure(c(`1.SS_Green_1` = 1L, `1.SS_Green_2` = 2L, 
`1.SS_Green_3` = 3L, `1.SS_Green_4` = 4L, `2.SS_Green_1` = 1L, 
`2.SS_Green_2` = 2L), .Label = c("SS_Green_1", "SS_Green_2", 
"SS_Green_3", "SS_Green_4"), class = c("pseries", "factor")), 
    value = c(`1.SS_Green_1` = FALSE, `1.SS_Green_2` = FALSE, 
    `1.SS_Green_3` = FALSE, `1.SS_Green_4` = TRUE, `2.SS_Green_1` = FALSE, 
    `2.SS_Green_2` = FALSE), price = c(`1.SS_Green_1` = 1.5, 
    `1.SS_Green_2` = 1.5, `1.SS_Green_3` = 1.5, `1.SS_Green_4` = 1.3, 
    `2.SS_Green_1` = 1.5, `2.SS_Green_2` = 1.5)), index = structure(list(
    chid = structure(c(1L, 1L, 1L, 1L, 2L, 2L), .Label = c("1", 
    "2"), class = "factor"), alt = structure(c(1L, 2L, 3L, 4L, 
    1L, 2L), .Label = c("SS_Green_1", "SS_Green_2", "SS_Green_3", 
    "SS_Green_4"), class = "factor")), class = "data.frame", row.names = c("1.SS_Green_1", 
"1.SS_Green_2", "1.SS_Green_3", "1.SS_Green_4", "2.SS_Green_1", 
"2.SS_Green_2")), choice = "value", row.names = c("1.SS_Green_1", 
"1.SS_Green_2", "1.SS_Green_3", "1.SS_Green_4", "2.SS_Green_1", 
"2.SS_Green_2"), class = c("mlogit.data", "data.frame"))
4

0 回答 0