Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
424 views
in Technique[技术] by (71.8m points)

sampling - One-way ANOVA using weighted survey data in R

I have some survey data with sample weights, and I'm using the survey package in R to compare means between demographic groups. I've had no problems using svyttest for two-sample t-tests involving dichotomous independent variables (e.g., sex).

However, I'm having some issues with the anova.svglym function in the survey package. When the generalized linear model has two independent variables, it works fine. But when the GLM has only one polytomous independent variable, I get a NULL result.

Here's some example code comparing BMI to demographics to describe my problem

library(survey)

# Survey design
healthdsgn = svydesign(data = healthsvy, id = ~SVYPSU, strata = ~SVYSTRATA, weights = ~SVYWT, nest = TRUE)

# This has two independent variables
# Outputs a normal ANOVA table
race_sex_glm = svyglm(BMI~RACE+SEX, healthdsgn)
anova(race_sex_glm)

# This has one independent polytomous variable
# Does not output a normal ANOVA table. Returns NULL
race_glm = svyglm(BMI~RACE, healthdsgn)
anova(race_glm)

This problem doesn't occur when I use the aov function in R — both of these produce normal ANOVA output:

summary(aov(BMI~RACE+SEX, healthsvy))
summary(aov(BMI~RACE, healthsvy))

However, aov doesn't account for survey weights so the output would be incorrect.

What should I do to resolve this?

question from:https://stackoverflow.com/questions/65649070/one-way-anova-using-weighted-survey-data-in-r

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...