R错误(下标)逻辑下标太长

时间:2020-07-18 01:53:55

标签: r

我正在尝试通过运行以下代码来调整标准错误:

#################################################################################
# Metaregression -- Academic Model
#################################################################################

# save list of moderators to include
terms_1 <- c("Targeted_c",
           "MOOSES_Rating_5_c", "Middle_c","High_c")  

# Student_report_c is reference variable

# format moderators into formula (an R-specifc type)
formula_academic <- reformulate(termlabels = c(terms_1))
formula_academic


# estimate a covariance matrix
V_list_academic <- impute_covariance_matrix(vi = full_academic$variance,  #known correlation vector
                                   cluster = full_academic$Study_ID, #study ID
                                   r = 0.80) #assumed correlation 


MVfull_academic <- rma.mv(yi=ES_adjusted, #effect size
                 V = V_list_academic, #variance (ThIS IS WHAt CHANGES FROM HEmodel)
                 mods = formula_academic, #ADD COVS HERE
                 random = ~1 | Study_ID/ES_ID, #nesting structure
                 test= "t", #use t-tests
                 data=full_academic, #define data
                 method="REML") #estimate variances using REML
MVfull_academic
#t-tests of each covariate #
MVfull.coef_academic <- coef_test(MVfull_academic,#estimation model above
                         cluster=full_academic$Study_ID, #define cluster IDs
                         vcov = "CR2") #estimation method (CR2 is best)
MVfull.coef_academic

这是返回错误的部分:

MVfull_academic
#t-tests of each covariate #
MVfull.coef_academic <- coef_test(MVfull_academic,#estimation model above
                         cluster=full_academic$Study_ID, #define cluster IDs
                         vcov = "CR2") #estimation method (CR2 is best)
MVfull.coef_academic

错误如下:

Error in x[fac == f, fac == f, drop = FALSE] : 
  (subscript) logical subscript too long

听起来好像某些数据不适合我,但我不确定它可能是什么。看起来数据集中的所有内容都一样长。如何解决此错误?

这是我的数据:

structure(list(APA = structure(c("Barr et al. (2015)", "Blair & Ravor (2014)", 
"Bos et al. (2019)", "Bos et al. (2019)", "Conduct Problems Prevention Research Group (1999)", 
"Conduct Problems Prevention Research Group (1999)"), label = "APA", format.stata = "%215s"), 
    Intervention = structure(c("Facing History and Ourselves", 
    "Tools of the Mind", "BARR", "BARR", "Fast Track (Selective)", 
    "Fast Track (Selective)"), label = "Intervention", format.stata = "%74s"), 
    TxCluster = structure(c(32, 16, 1, 1, 27, 27), label = "Tx.\nCluster", format.stata = "%10.0g"), 
    ControlCluster = structure(c(30, 13, 1, 1, 27, 27), label = "Control.\nCluster", format.stata = "%10.0g"), 
    UnitofCluster = structure(c("schools", "schools", "", "", 
    "schools", "schools"), label = "Unit of Cluster", format.stata = "%10s"), 
    TxN = structure(c(587, 408, 1467, 1466, 419, 275), label = "Tx.N", format.stata = "%10.0g"), 
    ControlN = structure(c(700, 282, 1916, 1910, 418, 276), label = "Control.N", format.stata = "%10.0g"), 
    Total_N = structure(c(1287, 690, 3383, 3376, 837, 551), label = "Total_N", format.stata = "%10.0g"), 
    WebsiteCategoryacademicemot = structure(c("Academic", "Academic", 
    "Academic", "Academic", "Academic", "Academic"), label = "Website Category (academic, emotion, relations, problem behavior)", format.stata = "%20s"), 
    MOOSES = structure(c(4, 5, 5, 5, 5, 5), label = "MOOSES rating\n1= cognitive/lower level skills (e.g. emotional recog.; pencil tap", format.stata = "%10.0g"), 
    ES = structure(c(0.14, 0.13, 0.31, 0.11, -0.01, 0.17), label = "ES", format.stata = "%10.0g"), 
    TypeofMeasure = structure(c("student self-report", "Standardized assessment", 
    "school record", "school record", "official report", "standardized assessment"
    ), label = "Type of Measure", format.stata = "%23s"), ES_ID = structure(c(22, 
    41, 58, 59, 135, 138), format.stata = "%9.0g"), Study_ID = structure(c(5, 
    9, 11, 11, 19, 19), label = "group(APA)", format.stata = "%9.0g"), 
    Targeted = structure(c(0, 0, 0, 0, 0, 0), format.stata = "%9.0g"), 
    Primary = structure(c(0, 1, 0, 0, 1, 1), format.stata = "%9.0g"), 
    Middle = structure(c(0, 0, 0, 0, 0, 0), format.stata = "%9.0g"), 
    High = structure(c(1, 0, 1, 1, 0, 0), format.stata = "%9.0g"), 
    Significant = structure(c(1, 1, 1, 1, 1, 1), format.stata = "%9.0g"), 
    MOOSES_Rating_4 = structure(c(1, 0, 0, 0, 0, 0), format.stata = "%9.0g"), 
    MOOSES_Rating_5 = structure(c(0, 1, 1, 1, 1, 1), format.stata = "%9.0g"), 
    MOOSES_Rating_4_c = structure(c(0.295774638652802, -0.704225361347198, 
    -0.704225361347198, -0.704225361347198, -0.704225361347198, 
    -0.704225361347198), format.stata = "%9.0g"), MOOSES_Rating_5_c = structure(c(-0.253521114587784, 
    0.746478855609894, 0.746478855609894, 0.746478855609894, 
    0.746478855609894, 0.746478855609894), format.stata = "%9.0g"), 
    Targeted_c = structure(c(-0.239436626434326, -0.239436626434326, 
    -0.239436626434326, -0.239436626434326, -0.239436626434326, 
    -0.239436626434326), format.stata = "%9.0g"), Primary_c = structure(c(-0.718309879302979, 
    0.281690150499344, -0.718309879302979, -0.718309879302979, 
    0.281690150499344, 0.281690150499344), format.stata = "%9.0g"), 
    Middle_c = structure(c(-0.126760557293892, -0.126760557293892, 
    -0.126760557293892, -0.126760557293892, -0.126760557293892, 
    -0.126760557293892), format.stata = "%9.0g"), High_c = structure(c(0.845070421695709, 
    -0.154929578304291, 0.845070421695709, 0.845070421695709, 
    -0.154929578304291, -0.154929578304291), format.stata = "%9.0g"), 
    Full_Sample = structure(c(1287, 690, 3383, 3376, 837, 551
    ), format.stata = "%9.0g"), Clusters_Total = structure(c(62, 
    29, 2, 2, 54, 54), format.stata = "%9.0g"), ES_adjusted = structure(c(0.12521980702877, 
    0.116275534033775, 0.277272433042526, 0.0983869880437851, 
    -0.00894427206367254, 0.152052626013756), format.stata = "%9.0g"), 
    SE = structure(c(0.05644915625453, 0.0780460089445114, 0.0353467278182507, 
    0.0349567793309689, 0.0690869837999344, 0.0861022993922234
    ), format.stata = "%9.0g"), variance = structure(c(0.0439638122916222, 
    0.0306105446070433, 0.00127180037088692, 0.001214295392856, 
    0.02976069226861, 0.100570656359196), format.stata = "%9.0g")), row.names = c(NA, 
-6L), class = c("tbl_df", "tbl", "data.frame"))

1 个答案:

答案 0 :(得分:0)

我刚刚在数据中找到了NA,我想可能是这样!

相关问题