简体   繁体   English

R 中的 Tobit 回归,在循环回归时,我的数据没有使用 censReg 进行审查

[英]Tobit regression in R, while looping regressions my data is not censored using censReg

hive mind!蜂群思维!

I am looping regression analysis for multiple data sets (for each antibiotic and concentration).我正在对多个数据集(每种抗生素和浓度)进行循环回归分析。 Some of the data is censored at the lower limit of 3.912023.部分数据在 3.912023 的下限处截尾。 So I need to use censReg() instead of lm() in those cases.所以在这些情况下我需要使用 censReg() 而不是 lm() 。

Even though multiple subsets are including the lower limit the model output is the lm() for each regression.即使多个子集包括下限,模型输出也是每个回归的 lm()。

Any thoughts on what I am doing wrong here?关于我在这里做错了什么的任何想法?

model.summary<- tibble()

for(j in unique(myData$antibiotic)){
        abx<- filter(myData, antibiotic == j)
        for(i in unique(abx$concentration)){
            if (min(abx$datapoints) == 3.912023){
                conc<-filter(abx, concentration == i)
                model<-censReg(x ~ y, data = conc, left = 3) 
                model.coef<-coef(model)[2] 
                model.list<-c(j,i ,model.coef)
                model.summary<-bind_rows(model.summary, model.list)
} else {
                conc<-filter(abx, concentration == i)
                model<-lm(x ~ y, data = conc)
                model.coef<-coef(model)[2] 
                model.list<-c(j,i, model.coef)
                model.summary<-bind_rows(model.summary, model.list)
    }   

     }
}
antibiotic (chr)抗生素 (chr) conc (fct)浓 (fct) x (dbl) x (dbl) y (dbl) y (dbl)
B 2 2 0 0 14.1 14.1
B 2 2 0.167 0.167 12.0 12.0
B 2 2 0.5 0.5 9.58 9.58
B 2 2 1 1 8.40 8.40
B 2 2 2 2 6.29 6.29
B 2 2 5 5 3.91 3.91
B 4 4 0 0 14.1 14.1
B 4 4 0.167 0.167 4.61 4.61
B 4 4 0.5 0.5 3.91 3.91
B 4 4 1 1 3.91 3.91
B 4 4 2 2 3.91 3.91
B 4 4 5 5 3.91 3.91

I suggest that you figure out in which round of the loop the problem occurs.我建议您弄清楚问题发生在循环的哪一轮。 Then, you can investigate the regression analysis in this selected round of the loop and provide a minimal example that illustrates the problem.然后,您可以在选定的循环中研究回归分析,并提供一个说明问题的最小示例。 (Sorry that I cannot post my comment as a "comment" because I have not yet "50 reputation".) (抱歉,我不能将我的评论作为“评论”发表,因为我还没有“50 声望”。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM