首页 > 解决方案 > 摘要错误(testMCFG1[[i]])$coefficients[12, 1] : 下标越界

问题描述

我必须对我的模型 testMCFG1 进行相同的 1104 线性回归。我有 11 个不变的独立变量要考虑。我的因变量是 1104。我想计算所有系数(包括截距)+ tstats 或 p 值的列表。我的代码如下。

我试图找出我的错误到底在哪里,但我找不到。你能帮我吗 ?我不明白如何修复这些错误消息:

  1. 摘要错误(testMCFG1[[i]])$coefficients[12, 1] : 下标越界
    摘要错误(testMCFG1[[i]])$coefficients[11, 1] : 下标越界

  2. 摘要错误(testMCFG1[[i]])$coefficients[12, 3] : 下标越界
    摘要错误(testMCFG1[[i]])$coefficients[11, 3] : 下标越界

  3. cbind 中的错误(coefcontexte,coefrm_contexte,coefrm_zdfy,coefrm_ztms,:找不到对象“coefcontexte”
    as.data.frame(MCFG1)中的错误:找不到对象“MCFG1”
    平均值错误(coefcontexte):找不到对象“coefcontexte”
    错误平均(coefrm_contexte):找不到对象“coefrm_contexte”

  4. 均值错误(tstatcontexte):未找到对象“tstatcontexte”
    均值错误(tstatrm_contexte):未找到对象“tstatrm_contexte”

  5. 打印错误(result.mean.coefcontexte):找不到对象“result.mean.coefcontexte”
    打印错误(result.mean.coefrm_contexte):找不到对象“result.mean.coefrm_contexte”

  6. 打印错误(result.mean.tstatcontexte):找不到对象“result.mean.tstatcontexte”
    打印错误(result.mean.tstatrm_contexte):找不到对象“result.mean.tstatrm_contexte”

> library(readxl)
> recexp <- read_excel(".../recexp.xlsx")
> View(recexp)                                                                                              
> # MCFG1: rm zdy ztbl ztms zdfy rm_zdy rm_ztbl rm_ztms rm_zdfy contexte rm_contexte
> recexp<-as.data.frame(recexp)
> 
> testMCFG1 <- lapply(101:1204, function(i) lm(recexp[,i]~recexp[,"rm"] + recexp[,"zdy"] + recexp[,"ztbl"] + recexp[,"ztms"] + recexp[,"zdfy"] + recexp[,"rm_zdy"] + recexp[,"rm_ztbl"] + recexp[,"rm_ztms"] + recexp[,"rm_zdfy"] + recexp[,"contexte"] + recexp[,"rm_contexte"]))
> 
> #betas
> coefrm_contexte <- sapply(1:length(testMCFG1),function(i)summary(testMCFG1[[i]])$coefficients[12,1])
Error in summary(testMCFG1[[i]])$coefficients[12, 1] : 
  subscript out of bounds
> coefcontexte <- sapply(1:length(testMCFG1),function(i)summary(testMCFG1[[i]])$coefficients[11,1])
Error in summary(testMCFG1[[i]])$coefficients[11, 1] : 
  subscript out of bounds
> coefrm_zdfy <- sapply(1:length(testMCFG1),function(i)summary(testMCFG1[[i]])$coefficients[10,1])
> coefrm_ztms <- sapply(1:length(testMCFG1),function(i)summary(testMCFG1[[i]])$coefficients[9,1])
> coefrm_ztbl <- sapply(1:length(testMCFG1),function(i)summary(testMCFG1[[i]])$coefficients[8,1])
> coefrm_zdy <- sapply(1:length(testMCFG1),function(i)summary(testMCFG1[[i]])$coefficients[7,1])
> coefzdfy <- sapply(1:length(testMCFG1),function(i)summary(testMCFG1[[i]])$coefficients[6,1])
> coefztms <- sapply(1:length(testMCFG1),function(i)summary(testMCFG1[[i]])$coefficients[5,1])
> coefztbl <- sapply(1:length(testMCFG1),function(i)summary(testMCFG1[[i]])$coefficients[4,1])
> coefzdy <- sapply(1:length(testMCFG1),function(i)summary(testMCFG1[[i]])$coefficients[3,1])
> coefrm <- sapply(1:length(testMCFG1),function(i)summary(testMCFG1[[i]])$coefficients[2,1])
> intercept <- sapply(1:length(testMCFG1),function(i)summary(testMCFG1[[i]])$coefficients[1,1])
> 
> 
> tstatrm_contexte <- sapply(1:length(testMCFG1),function(i)  summary(testMCFG1[[i]])$coefficients[12,3])
Error in summary(testMCFG1[[i]])$coefficients[12, 3] : 
  subscript out of bounds
> tstatcontexte <- sapply(1:length(testMCFG1),function(i)  summary(testMCFG1[[i]])$coefficients[11,3])
Error in summary(testMCFG1[[i]])$coefficients[11, 3] : 
  subscript out of bounds
> tstatrm_zdfy <- sapply(1:length(testMCFG1),function(i)  summary(testMCFG1[[i]])$coefficients[10,3])
> tstatrm_ztms <- sapply(1:length(testMCFG1),function(i)  summary(testMCFG1[[i]])$coefficients[9,3])
> tstatrm_ztbl <- sapply(1:length(testMCFG1),function(i)  summary(testMCFG1[[i]])$coefficients[8,3])
> tstatrm_zdy <- sapply(1:length(testMCFG1),function(i)  summary(testMCFG1[[i]])$coefficients[7,3])
> tstatzdfy <- sapply(1:length(testMCFG1),function(i)  summary(testMCFG1[[i]])$coefficients[6,3])
> tstatztms <- sapply(1:length(testMCFG1),function(i)  summary(testMCFG1[[i]])$coefficients[5,3])
> tstatztbl <- sapply(1:length(testMCFG1),function(i)  summary(testMCFG1[[i]])$coefficients[4,3])
> tstatzdy <- sapply(1:length(testMCFG1),function(i)  summary(testMCFG1[[i]])$coefficients[3,3])
> tstatrm <- sapply(1:length(testMCFG1),function(i)  summary(testMCFG1[[i]])$coefficients[2,3])
> tstatint <- sapply(1:length(testMCFG1),function(i)  summary(testMCFG1[[i]])$coefficients[1,3])
> #tstat
> 
> MCFG1 <- cbind(coefcontexte,coefrm_contexte,coefrm_zdfy,coefrm_ztms,coefrm_ztbl,coefrm_zdy,coefzdfy,coefztms,coefztbl,coefzdy,coefrm,intercept,
+                tstatcontexte,tstatrm_contexte,tstatrm_zdfy,tstatrm_ztms,tstatrm_ztbl,tstatrm_zdy,tstatzdfy,tstatztms,tstatztbl,tstatzdy,
+                tstatrm,tstatint)
Error in cbind(coefcontexte, coefrm_contexte, coefrm_zdfy, coefrm_ztms,  : 
  object 'coefcontexte' not found
> 
> resultsMCFG1 <- as.data.frame(MCFG1)
Error in as.data.frame(MCFG1) : object 'MCFG1' not found
> 
> result.mean.coefcontexte <-  mean(coefcontexte)
Error in mean(coefcontexte) : object 'coefcontexte' not found
> result.mean.coefrm_contexte <-  mean(coefrm_contexte)
Error in mean(coefrm_contexte) : object 'coefrm_contexte' not found
> result.mean.coefrm_zdfy <-  mean(coefrm_zdfy)
> result.mean.coefrm_ztms <-  mean(coefrm_ztms)
> result.mean.coefrm_ztbl<-  mean(coefrm_ztbl)
> result.mean.coefrm_zdy<-  mean(coefrm_zdy)
> result.mean.coefzdfy <-  mean(coefzdfy)
> result.mean.coefztms <-  mean(coefztms)
> result.mean.coefztbl<-  mean(coefztbl)
> result.mean.coefzdy<-  mean(coefzdy)
> result.mean.coefrm <-  mean(coefrm)
> result.mean.intercept <-  mean(intercept)
> 
> result.mean.tstatcontexte<-  mean(tstatcontexte)
Error in mean(tstatcontexte) : object 'tstatcontexte' not found
> result.mean.tstatrm_contexte<-  mean(tstatrm_contexte)
Error in mean(tstatrm_contexte) : object 'tstatrm_contexte' not found
> result.mean.tstatrm_zdfy<-  mean(tstatrm_zdfy)
> result.mean.tstatrm_ztms<-  mean(tstatrm_ztms)
> result.mean.tstatrm_ztbl <-  mean(tstatrm_ztbl)
> result.mean.tstatrm_zdy <-  mean(tstatrm_zdy)
> result.mean.tstatzdfy<-  mean(tstatzdfy)
> result.mean.tstatztms<-  mean(tstatztms)
> result.mean.tstatztbl <-  mean(tstatztbl)
> result.mean.tstatzdy <-  mean(tstatzdy)
> result.mean.tstatrm<-  mean(tstatrm)
> result.mean.tstatint<-  mean(tstatint)
> 
> print(result.mean.coefcontexte)
Error in print(result.mean.coefcontexte) : 
  object 'result.mean.coefcontexte' not found
> print(result.mean.coefrm_contexte)
Error in print(result.mean.coefrm_contexte) : 
  object 'result.mean.coefrm_contexte' not found
> print(result.mean.coefrm_zdfy)
[1] -9.820681
> print(result.mean.coefrm_ztms)
[1] 1.038875
> print(result.mean.coefrm_ztbl)
[1] -2.525717
> print(result.mean.coefrm_zdy)
[1] 0.4957833
> print(result.mean.coefzdfy)
[1] 0.9269268
> print(result.mean.coefztms)
[1] 0.1445151
> print(result.mean.coefztbl)
[1] 0.1769413
> print(result.mean.coefzdy)
[1] -0.02545432
> print(result.mean.coefrm)
[1] 0.5789277
> print(result.mean.intercept)
[1] -0.0005573808
> 
> print(result.mean.tstatcontexte)
Error in print(result.mean.tstatcontexte) : 
  object 'result.mean.tstatcontexte' not found
> print(result.mean.tstatrm_contexte)
Error in print(result.mean.tstatrm_contexte) : 
  object 'result.mean.tstatrm_contexte' not found
> print(result.mean.tstatrm_zdfy)
[1] -0.7366906
> print(result.mean.tstatrm_ztms)
[1] 0.1881266
> print(result.mean.tstatrm_ztbl)
[1] -0.1456472
> print(result.mean.tstatrm_zdy)
[1] 0.5544259
> print(result.mean.tstatzdfy)
[1] 1.33759
> print(result.mean.tstatztms)
[1] 0.6126419
> print(result.mean.tstatztbl)
[1] 0.1922559
> print(result.mean.tstatzdy)
[1] -0.5078214
> print(result.mean.tstatrm)
[1] 4.448027
> print(result.mean.tstatint)
[1] 0.04738022

标签: rsyntax-errorregression

解决方案


推荐阅读