Closed weisx2022 closed 8 months ago
@cyk0315 Please review the error
Can you give me some specific instructions? I think it's a file format problem. when I trace the error,
pv_anova <- anova(model.int, method = "Wald")
it shows the above code may be the source of the error. I think the format of model.int is wrong, but in the function environment the class of model.int is svyglm.
debug(TableSubgroupGLM) time.sub.res <- TableSubgroupGLM(dc ~ gender,var_subgroup = "bmi", data = nhanes.design, family = "binomial")
Browse[2]> class(model.int) [1] "svyglm" "glm" "lm"
Why is model.int considered a class of function ?
@weisx2022 Can you upload the data to reproduce?
@weisx2022 Can you upload the data to reproduce?
This is my test data test.csv Thank you for your attention
@weisx2022 Hello, I ran it with your data and found that the code below also has a problem. This was confirmed by the update function in the oneanova.svyglm function and the error in the update function I'm sorry I couldn't give you an exact answer
test<-read_csv("Downloads/test.csv")
df <- svydesign(data = test,
id = ~SDMVPSU,strata = ~SDMVSTRA,weights = ~weight,
nest = T)
model.int<-svyglm(dc ~ gender * bmi, design = df, family = quasibinomial())
anova(model.int, method = "Wald")
oneanova.svyglm<-function(object,test,method){
tt<-terms(object)
tlbls<-attr(tt,"term.labels")
nt<-length(tlbls)
if (nt<2) return(NULL)
seqtests<-vector("list",nt)
if(test=="F") ddf<-NULL else ddf<-Inf
thismodel<-object
if (!("formula") %in% names(thismodel$call))
names(thismodel$call)[[2]] <- "formula"
for(i in nt:1){
thisterm<-tlbls[i]
seqtests[[i]]<-regTermTest(thismodel,tlbls[i],method=method,df=ddf)
thisformula<-make.formula(thisterm)[[2]]
thismodel <- eval(bquote(update(thismodel, . ~ . - (.(thisformula)))))
}
class(seqtests)<-"seqanova.svyglm"
attr(seqtests,"method")<-method
attr(seqtests,"test")<-test
seqtests
}
@weisx2022 Hello, I ran it with your data and found that the code below also has a problem. This was confirmed by the update function in the oneanova.svyglm function and the error in the update function I'm sorry I couldn't give you an exact answer
test<-read_csv("Downloads/test.csv") df <- svydesign(data = test, id = ~SDMVPSU,strata = ~SDMVSTRA,weights = ~weight, nest = T) model.int<-svyglm(dc ~ gender * bmi, design = df, family = quasibinomial()) anova(model.int, method = "Wald")
oneanova.svyglm<-function(object,test,method){ tt<-terms(object) tlbls<-attr(tt,"term.labels") nt<-length(tlbls) if (nt<2) return(NULL) seqtests<-vector("list",nt) if(test=="F") ddf<-NULL else ddf<-Inf thismodel<-object if (!("formula") %in% names(thismodel$call)) names(thismodel$call)[[2]] <- "formula" for(i in nt:1){ thisterm<-tlbls[i] seqtests[[i]]<-regTermTest(thismodel,tlbls[i],method=method,df=ddf) thisformula<-make.formula(thisterm)[[2]] thismodel <- eval(bquote(update(thismodel, . ~ . - (.(thisformula))))) } class(seqtests)<-"seqanova.svyglm" attr(seqtests,"method")<-method attr(seqtests,"test")<-test seqtests }
thank you very much
@weisx2022 I fix the problem. If you install the latest version, it will work.
remotes::install_github("jinseob2kim/jstable")
When it comes to errors in the anova function, it seems better to define the variable name as something other than df. Below is an example
testdata<-read_csv("Downloads/test.csv")
data.design<- svydesign(data = testdata,
id = ~SDMVPSU,strata = ~SDMVSTRA,weights = ~weight,
nest = T)
TableSubgroupGLM(dc ~ gender,var_subgroup = "bmi", data = data.design, family = "binomial")
model.int<-svyglm(dc ~ gender * bmi, design = data.design, family = quasibinomial())
anova(model.int, method = "Wald")
Dear author.thanks for your excellent working, but i have some questions: I am analyzing weighted data from NHANES. I get such an error when I performed a subgroup analysis using weighted data by survey package.
But when I copy the code of TableSubgroupGLM to the external environment and it wroks fine. Could you please provide guidance or suggestions on how to resolve it? I appreciate your help!
This is my data: [Uploading test.csv…]()
This is my environment: