我使用的是人口统计和健康调查数据。我的最终目标是运行多元逻辑回归。由于我使用的是复杂数据,所以我将数据从宽转换为长。我继续进行分析,并进行卡方检验。我使用两个变量成功地运行了这段代码。因为我想使用四个变量来运行分析,这些变量描述了四个孩子的相同营养不良指标,并将其与城市和农村变量交叉,因此我运行了另一个卡方,考虑到我的数据已正确地从宽转换为长。不幸的是,这次我得到了一个错误。请注意,我正在运行针对调查设计的分析调整。下面的代码和数据输出。你能为我提供正确的代码来运行从宽到长的正确转换,以及正确运行卡方测试的代码吗?
`library(haven)`
`HNIR62FL_data_2 <- readta that has been converted from wide to long?_sav("~/DHS/HNIR62SV/HNIR62FL_data_2.SAV")`
`View(HNIR62FL_data_2)`
`obsHNIR62FL_data_2 <- subset(HNIR62FL_data_2, !is.na(V021) & !is.na(V022) & !is.na(D005))`
`myvars <- c("CASEID", "V013", "V021", "V022", "V025", "V106", "V137", "V190", "V714", "D005", "D104", "D106", "D107", "D108","v1014", "v1016", "v1021", "v1023", "v1038", "v1039", "v1045", "v1113", "V701", "v1007_1", "v1007_2", "v1007_3", "v1007_4", "v1008_1", "v1008_2", "v1008_3", "v1008_4", "v1009_1", "v1009_2", "v1009_3", "v1009_4", "v1010_1", "v1010_2", "v1010_3", "v1010_4", "v1020_1", "v1020_2", "v1020_3", "v1020_4", "v1071_1", "v1071_2", "v1071_3", "v1071_4", "v1088_1", "v1088_2", "v1088_3", "v1088_4", "v1096_1", "v1096_2", "v1096_3", "v1096_4", "v1104_1", "v1104_2", "v1104_3", "v1104_4", "v1111_1", "v1111_2", "v1111_3", "v1111_4", "v1112_1", "v1112_2", "v1112_3", "v1112_4")`
`newobsHNIR62FL_data_2 <- obsHNIR62FL_data_2[myvars]`
`dhsdesign <- svydesign(newobsHNIR62FL_data_2$V021, strata = newobsHNIR62FL_data_2$V022, weights = newobsHNIR62FL_data_2$D005/1000000, data = newobsHNIR62FL_data_2)`
`newobsHNIR62FL_data_2 %>% mutate(across(starts_with(c("V", "v")), as.double)) %>% pivot_longer(cols=starts_with(c("V", "v")), names_to = c("name", "id"), values_to = "value", names_sep = "_")`
`A tibble: 379,237 x 9
CASEID D005 D104 D106 D107 D108 name id value
<chr> <dbl> <dbl+lb> <dbl+lb> <dbl+l> <dbl+l> <chr> <chr> <dbl>
1 " 564 9~ 1758042 0 [No] 0 [No] 0 [No] 0 [No] V013 NA 2
2 " 564 9~ 1758042 0 [No] 0 [No] 0 [No] 0 [No] V021 NA 564
3 " 564 9~ 1758042 0 [No] 0 [No] 0 [No] 0 [No] V022 NA 16
4 " 564 9~ 1758042 0 [No] 0 [No] 0 [No] 0 [No] V025 NA 1
5 " 564 9~ 1758042 0 [No] 0 [No] 0 [No] 0 [No] V106 NA 1
6 " 564 9~ 1758042 0 [No] 0 [No] 0 [No] 0 [No] V137 NA 2
7 " 564 9~ 1758042 0 [No] 0 [No] 0 [No] 0 [No] V190 NA 3
8 " 564 9~ 1758042 0 [No] 0 [No] 0 [No] 0 [No] V714 NA 0
9 " 564 9~ 1758042 0 [No] 0 [No] 0 [No] 0 [No] v1014 NA 2
10 " 564 9~ 1758042 0 [No] 0 [No] 0 [No] 0 [No] v1016 NA 1
# ... with 379,227 more rows`警告消息:
应为2件。
`summary(svytable(~v1113+v1039, dhsdesign))`v1039
v1113 1 2 3 4
0 1087 934 626 6461 462 518 388 359Pearson's X^2: Rao & Scott adjustment数据: svychisq(~v1113 + v1039,设计= dhsdesign,统计= "F")
F= 5.4626,ndf = 2.9836,ddf = 3243.1635,p-value =0.0009852
`summary(svytable(~v1007_1 + v1007_2+ v1007_3 + v1007_4 + V025, dhsdesign))`Svychisq.survey.design出错(~v1007_1+ v1007_2 + v1007_3 + v1007_4 +:
目前只有双向表格
`dput(head(newobsHNIR62FL_data_2))``结构(列表(CASEID=结构(c(“564 - 91 2",”198 - 61 - 2",
“267 21 1",”1089 81 2",“583 61 8",”989101 2“
),label =“案例识别”,format.spss = "A15",display_width = 17L),
V013 = structure(c(2, 4, 4, 4, 6, 3), label = "Age in 5-year groups", format.spss = "F1.0", display_width = 6L, labels = c(`15-19` = 1, `20-24` = 2, `25-29` = 3, `30-34` = 4, `35-39` = 5, `40-44` = 6, `45-49` = 7), class = c("haven_labelled", "vctrs_vctr", "double")), V021 = structure(c(564, 198, 267, 1089, 583, 989), label = "Primary sampling unit", format.spss = "F4.0", display_width = 6L), V022 = structure(c(16, 8, 9, 37, 17, 33), label = "Sample strata for sampling errors", format.spss = "F4.0", display_width = 6L, labels = c(`Atlántida Urbano` = 1, `Atlántida Rural` = 2, `Colón Urbano` = 3, `Colón Rural` = 4, `Comayagua Urbano` = 5, `Comayagua Rural` = 6, `Copán Urbano` = 7, `Copán Rural` = 8, `San Pedro Sula Urbano` = 9, `Cortés Resto Urbano` = 10, `Cortés Resto Rural` = 11, `Choluteca Urbano` = 12, `Choluteca Rural` = 13, `El Paraíso Urbano` = 14, `El Paraíso Rural` = 15, `Tegucigalpa Urbano` = 16, `Morazán Resto Urbano` = 17, `Morazán Resto Rural` = 18, `Gracias a Dios Urbano` = 19, `Gracias a Dios Rural` = 20, `Intibucá Urbano` = 21, `Intibucá Rural` = 22, `Islas de Bahía Urbano` = 23, `Islas de Bahía Rural` = 24, `La Paz Urbano` = 25, `La Paz Rural` = 26, `Lempira Urbano` = 27, `Lempira Rural` = 28, `Ocotepeque Urbano` = 29, `Ocotepeque Rural` = 30, `Olancho Urbano` = 31, `Olancho Rural` = 32, `Santa Bárbara Urbano` = 33, `Santa Bárbara Rural` = 34, `Valle Urbano` = 35, `Valle Rural` = 36, `Yoro Urbano` = 37, `Yoro Rural` = 38), class = c("haven_labelled", "vctrs_vctr", "double")), V025 = structure(c(1, 2, 1, 1, 1, 1), label = "Type of place of residence", format.spss = "F1.0", display_width = 6L, labels = c(Urban = 1, Rural = 2), class = c("haven_labelled", "vctrs_vctr", "double")), V106 = structure(c(1, 0, 1, 1, 1, 2), label = "Highest educational level", format.spss = "F1.0", display_width = 6L, labels = c(`No education` = 0, Primary = 1, Secondary = 2, Higher = 3), class = c("haven_labelled", "vctrs_vctr", "double")), V137 = structure(c(2, 2, 2, 1, 0, 1), label = "Number of children 5 and under in household (de jure)", format.spss = "F2.0", display_width = 6L), V190 = structure(c(3, 1, 2, 4, 2, 4), label = "Wealth index", format.spss = "F1.0", display_width = 6L, labels = c(Poorest = 1, Poorer = 2, Middle = 3, Richer = 4, Richest = 5), class = c("haven_labelled", "vctrs_vctr", "double")), V714 = structure(c(0, 0, 1, 1, 0, 0), label = "Respondent currently working", format.spss = "F1.0", display_width = 6L, labels = c(No = 0, Yes = 1), class = c("haven_labelled", "vctrs_vctr", "double")), D005 = structure(c(1758042, 927099, 1296895, 1087346, 1005935, 1112882), label = "Weight for Domestic Violence (6 decimals)", format.spss = "F8.0", display_width = 10L), D104 = structure(c(0, 0, 0, 0, 0, 0), label = "Experienced any emotional violence", format.spss = "F1.0", display_width = 6L, labels = c(No = 0, Yes = 1), class = c("haven_labelled", "vctrs_vctr", "double")), D106 = structure(c(0, 0, 0, 0, 0, 0), label = "Experienced any less severe violence (D105A-C,J) by husband/partner", format.spss = "F1.0", display_width = 6L, labels = c(No = 0, `Yes (D105A-D)` = 1), class = c("haven_labelled", "vctrs_vctr", "double")), D107 = structure(c(0, 0, 0, 0, 0, 0), label = "Experienced any severe violence (D105D-F) by husband/partner", format.spss = "F1.0", display_width = 6L, labels = c(No = 0, `Yes (D105E-G)` = 1), class = c("haven_labelled", "vctrs_vctr", "double")), D108 = structure(c(0, 0, 0, 0, 0, 0), label = "Experienced any sexual violence (D105H-I,K) by husband/partner", format.spss = "F1.0", display_width = 6L, labels = c(No = 0, `Yes (D105H-I)` = 1), class = c("haven_labelled", "vctrs_vctr", "double")), v1014 = structure(c(2, 2, 2, 4, 2, 4), label = "women BMI category", format.spss = "F8.0", labels = c(underweight = 1, `normal weight` = 2, overweight = 3, obese = 4), class = c("haven_labelled", "vctrs_vctr", "double")), v1016 = structure(c(1, 0, 0, 1, 0, 1), label = "women height category", format.spss = "F8.0", labels = c(`woman height <150 cm` = 0, `woman height 150 cm or more ` = 1), class = c("haven_labelled", "vctrs_vctr", "double")), v1021 = structure(c(4, 3, 1, 1, 4, 3), label = "region category", format.spss = "F8.0", labels = c(Northern = 1, Southern = 2, Western = 3, Central = 4, Eastern = 5), class = c("haven_labelled", "vctrs_vctr", "double")), v1023 = structure(c(2, 5, 3, 2, 4, 1), label = "parity", format.spss = "F8.0", labels = c(`0` = 0, `1` = 1, `2` = 2, `3` = 3, `4` = 4, `5 or more` = 5), class = c("haven_labelled", "vctrs_vctr", "double")), v1038 = structure(c(2, 1, 3, 2, 2, 2), label = "marital status", format.spss = "F8.0", labels = c(`Never in union` = 0, Married = 1, `Living with partner ` = 2, `Divorced, widowed or separated/no longer living together` = 3), class = c("haven_labelled", "vctrs_vctr", "double")), v1039 = structure(c(2, 4, 3, 2, 3, 1), label = "marital duration", format.spss = "F8.0", labels = c(`Never in a union` = 0, `0-4 years` = 1, `5-9 years` = 2, `10-14 years` = 3, `15 years or more` = 4), class = c("haven_labelled", "vctrs_vctr", "double")), v1045 = structure(c(4, 4, NA, 3, 1, 4), label = "Women decision making scale", format.spss = "F8.0", labels = c(`No decision making skills` = 0, `Respondent alone/respondent and husband/partner decide on one issue` = 1, `Respondent alone/respondent and husband/partner decide on two issues` = 2, `Respondent alone/respondent and husband/partner decide on three issues` = 3, `Respondent alone/respondent and husband/partner decide on four issues` = 4), class = c("haven_labelled", "vctrs_vctr", "double")), v1113 = structure(c(0, 0, 0, 0, 0, 0), label = "Any intimate partner violence", format.spss = "F8.0", labels = c(`Has not experienced any form of intimate partner violence` = 0, `Has experienced any form of intimate partner violence` = 1), class = c("haven_labelled", "vctrs_vctr", "double")), V701 = structure(c(2, 1, 1, 2, 2, 2), label = "Husband/partner's education level", format.spss = "F1.0", display_width = 6L, labels = c(`No education` = 0, Primary = 1, Secondary = 2, Higher = 3, `Don't know` = 8), class = c("haven_labelled", "vctrs_vctr", "double")), v1007_1 = structure(c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), label = "youngest child stunting category", format.spss = "F8.0", labels = c(`stunted child ` = 0, `not stunted child` = 1), class = c("haven_labelled", "vctrs_vctr", "double")), v1007_2 = structure(c(1, 0, 0, NA, NA, NA), label = "stunting category (second to youngest child)", format.spss = "F8.0", labels = c(stunted = 0, `not stunted` = 1), class = c("haven_labelled", "vctrs_vctr", "double")), v1007_3 = structure(c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), label = "stunting category (third to youngest child)", format.spss = "F8.0", labels = c(stunted = 0, `not stunted` = 1), class = c("haven_labelled", "vctrs_vctr", "double")), v1007_4 = structure(c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), label = "stunting category (fourth to youngest child)", format.spss = "F8.0", labels = c(stunted = 0, `not stunted` = 1), class = c("haven_labelled", "vctrs_vctr", "double")), v1008_1 = structure(c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), label = "youngest child underweight category", format.spss = "F8.0", labels = c(`underweight child` = 0, `not underweight child` = 1), class = c("haven_labelled", "vctrs_vctr", "double")), v1008_2 = structure(c(1, 1, 0, NA, NA, NA), label = "underweight category (second to youngest child)", format.spss = "F8.0", labels = c(underweight = 0, `not underweight` = 1), class = c("haven_labelled", "vctrs_vctr", "double")), v1008_3 = structure(c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), label = "underweight category (third to youngest child)", format.spss = "F8.0", labels = c(underweight = 0, `not underweight` = 1), class = c("haven_labelled", "vctrs_vctr", "double")), v1008_4 = structure(c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), label = "underweight category (fourth to youngest child)", format.spss = "F8.0", labels = c(underweight = 0, `not underweight` = 1), class = c("haven_labelled", "vctrs_vctr", "double")), v1009_1 = structure(c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), label = "youngest child wasting category", format.spss = "F8.0", labels = c(`wasted child` = 0, `not wasted child ` = 1), class = c("haven_labelled", "vctrs_vctr", "double")), v1009_2 = structure(c(1, 1, 1, NA, NA, NA), label = "wasting category (second to youngest child)", format.spss = "F8.0", labels = c(wasted = 0, `not wasted` = 1), class = c("haven_labelled", "vctrs_vctr", "double")), v1009_3 = structure(c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), label = "wasting category (third to youngest child)", format.spss = "F8.0", labels = c(wasted = 0, `not wasted ` = 1), class = c("haven_labelled", "vctrs_vctr", "double")), v1009_4 = structure(c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), label = "wasting category (fourth to youngest child)", format.spss = "F8.0", labels = c(wasted = 0, `not wasted` = 1), class = c("haven_labelled", "vctrs_vctr", "double")), v1010_1 = structure(c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), label = "youngest child overweight category", format.spss = "F8.0", labels = c(`overweight child` = 0, `not overweight child ` = 1), class = c("haven_labelled", "vctrs_vctr", "double")), v1010_2 = structure(c(1, 1, 1, NA, NA, NA), label = "overweight category (second to youngest child)", format.spss = "F8.0", labels = c(overweight = 0, `not overweight` = 1), class = c("haven_labelled", "vctrs_vctr", "double")), v1010_3 = structure(c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), label = "overweight category (third to youngest child)", format.spss = "F8.0", labels = c(overweight = 0, `not overweight` = 1), class = c("haven_labelled", "vctrs_vctr", "double")), v1010_4 = structure(c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), label = "overweight category (fourth to youngest child)", format.spss = "F8.0", labels = c(overweight = 0, `not overweight` = 1), class = c("haven_labelled", "vctrs_vctr", "double")), v1020_1 = structure(c(1, 0, 1, 0, 1, 0), label = "youngest child morbidity category", format.spss = "F8.0", labels = c(`youngest child with no morbidity` = 0, `youngest child with morbidity ` = 1), class = c("haven_labelled", "vctrs_vctr", "double")), v1020_2 = structure(c(1, 0, 1, NA, NA, NA), label = "Morbidity category (second to youngest child)", format.spss = "F8.0", labels = c(`youngest child with no morbidity` = 0, `youngest child with morbidity` = 1), class = c("haven_labelled", "vctrs_vctr", "double")), v1020_3 = structure(c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), label = "Morbidity category (third to youngest child)", format.spss = "F8.0", labels = c(`youngest child with no morbidity` = 0, `youngest child with morbidity` = 1), class = c("haven_labelled", "vctrs_vctr", "double")), v1020_4 = structure(c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), label = "Morbidity category (fourth to youngest child)", format.spss = "F8.0", labels = c(`youngest child with no morbidity` = 0, `youngest child with morbidity` = 1), class = c("haven_labelled", "vctrs_vctr", "double")), v1071_1 = structure(c(0, NA, 1, 1, 1, 1), label = "anemia category (youngest child)", format.spss = "F8.0", labels = c(anemic = 0, `not anemic` = 1), class = c("haven_labelled", "vctrs_vctr", "double")), v1071_2 = structure(c(1, 1, 0, NA, NA, NA), label = "anemia category (second to youngest child)", format.spss = "F8.0", labels = c(anemic = 0, `not anemic` = 1), class = c("haven_labelled", "vctrs_vctr", "double")), v1071_3 = structure(c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), label = "anemia category (third to youngest child)", format.spss = "F8.0", labels = c(anemic = 0, `not anemic` = 1), class = c("haven_labelled", "vctrs_vctr", "double")), v1071_4 = structure(c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), label = "anemia category (fourth to youngest child)", format.spss = "F8.0", labels = c(anemic = 0, `not anemic` = 1), class = c("haven_labelled", "vctrs_vctr", "double")), v1088_1 = structure(c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), label = "youngest child stunting + overweight category", format.spss = "F8.0", labels = c(`stunted and overweight child` = 0, `not stunted and overweight child` = 1), class = c("haven_labelled", "vctrs_vctr", "double")), v1088_2 = structure(c(1, 1, NA, NA, NA, NA), label = "second to youngest child stunting + overweight category", format.spss = "F8.0", labels = c(`stunted and overweight child` = 0, `not stunted and overweight child` = 1), class = c("haven_labelled", "vctrs_vctr", "double")), v1088_3 = structure(c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), label = "third to youngest child stunting + overweight category", format.spss = "F8.0", labels = c(`stunted and overweight child ` = 0, `not stunted and overweight child` = 1), class = c("haven_labelled", "vctrs_vctr", "double")), v1088_4 = structure(c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), label = "fourth to youngest child stunting + overweight category", format.spss = "F8.0", labels = c(`stunted and overweight child ` = 0, `not stunted and overweight child` = 1), class = c("haven_labelled", "vctrs_vctr", "double")), v1096_1 = structure(c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), label = "youngest child anemic + overweight category", format.spss = "F8.0", labels = c(`anemic and overweight child ` = 0, `not anemic and overweight child` = 1), class = c("haven_labelled", "vctrs_vctr", "double")), v1096_2 = structure(c(1, 1, 1, NA, NA, NA), label = "second to youngest child anemic + overweight category", format.spss = "F8.0", labels = c(`anemic and overweight child ` = 0, `not anemic and overweight child ` = 1), class = c("haven_labelled", "vctrs_vctr", "double")), v1096_3 = structure(c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), label = "third to youngest child anemic + overweight category", format.spss = "F8.0", labels = c(`anemic and overweight child ` = 0, `not anemic and overweight child ` = 1), class = c("haven_labelled", "vctrs_vctr", "double")), v1096_4 = structure(c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), label = "fourth to youngest child anemic + overweight category", format.spss = "F8.0", labels = c(`anemic and overweight child ` = 0, `not anemic and overweight child` = 1), class = c("haven_labelled", "vctrs_vctr", "double")), v1104_1 = structure(c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), label = "youngest child anemic + stunted category", format.spss = "F8.0", labels = c(`anemic and stunted child` = 0, `not anemic and not stunted child ` = 1), class = c("haven_labelled", "vctrs_vctr", "double")), v1104_2 = structure(c(1, 1, NA, NA, NA, NA), label = "second to youngest child anemic + stunted category", format.spss = "F8.0", labels = c(`anemic and stunted child ` = 0, `not anemic and stunted child ` = 1), class = c("haven_labelled", "vctrs_vctr", "double")), v1104_3 = structure(c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), label = "third to youngest child anemic + stunted category", format.spss = "F8.0", labels = c(`anemic and stunted child ` = 0, `not anemic and stunted child ` = 1), class = c("haven_labelled", "vctrs_vctr", "double")), v1104_4 = structure(c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), label = "fourth to youngest child anemic + stunted category", format.spss = "F8.0", labels = c(`stunted and anemic child` = 0, `not stunted and anemic child` = 1), class = c("haven_labelled", "vctrs_vctr", "double")), v1111_1 = structure(c(3, 1, 4, 4, 5, 6), label = "Child age (youngest child)", format.spss = "F8.0", labels = c(`0-5 months` = 1, `6-11 months` = 2, `12-23 months` = 3, `24-35 months` = 4, `36-47 months` = 5, `48-59 months` = 6), class = c("haven_labelled", "vctrs_vctr", "double")), v1111_2 = structure(c(6, 5, 6, NA, NA, NA), label = "Child age (second to youngest)", format.spss = "F8.0", labels = c(`0-5 months` = 1, `6-11 months` = 2, `12-23 months` = 3, `24-35 months` = 4, `36-47 months` = 5, `48-59 months` = 6), class = c("haven_labelled", "vctrs_vctr", "double")), v1111_3 = structure(c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), label = "Child age (third to youngest)", format.spss = "F8.0", labels = c(`0-5 months` = 1, `6-11 months` = 2, `12-23 months` = 3, `24-35 months` = 4, `36-47 months` = 5, `48-59 months` = 6), class = c("haven_labelled", "vctrs_vctr", "double")), v1111_4 = structure(c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), label = "Child age (fourth to youngest)", format.spss = "F8.0", labels = c(`0-5 months` = 1, `6-11 months` = 2, `12-23 months` = 3, `24-35 months` = 4, `36-47 months` = 5, `48-59 months` = 6), class = c("haven_labelled", "vctrs_vctr", "double")), v1112_1 = structure(c(2, 2, 1, 1, 1, 1), label = "Sex of child", format.spss = "F1.0", display_width = 7L, labels = c(Male = 1, Female = 2), class = c("haven_labelled", "vctrs_vctr", "double")), v1112_2 = structure(c(1, 2, 1, 2, 1, NA), label = "Sex of child", format.spss = "F1.0", display_width = 7L, labels = c(Male = 1, Female = 2), class = c("haven_labelled", "vctrs_vctr", "double")), v1112_3 = structure(c(NA, 2, 1, NA, 2, NA), label = "Sex of child", format.spss = "F1.0", display_width = 7L, labels = c(Male = 1, Female = 2), class = c("haven_labelled", "vctrs_vctr", "double")), v1112_4 = structure(c(NA, 2, NA, NA, 1, NA), label = "Sex of child", format.spss = "F1.0", display_width = 7L, labels = c(Male = 1, Female = 2), class = c("haven_labelled", "vctrs_vctr", "double"))), row.names = c(NA, -6L), class = c("tbl_df", "tbl", "data.frame"))`
发布于 2020-07-12 15:33:22
正如错误消息所说,svychisq()只做双向表。您可以使用svyloglin(),它执行Rao-Scott得分和似然比测试。Rao-Scott分数测试是svychisq()的默认测试,在双向表中,svychisq()和对数线性模型的结果将匹配
一个额外的复杂性是,您需要指定您想要测试的替代方案:您是希望与具有双向交互的模型进行比较,还是与具有所有可能交互的模型进行比较。当你只有两个变量时,只有双向交互,所以不会有歧义。
如果有帮助,Rao and Scott正在查看与完整模型的比较。
null_model<-svyloglin(~A+B+C+D,design)
twoway_model<-update(null_model,~.^2)
full_model <- update(null_model,~.^4)
anova(null_model, full_model)
anova(null_model, twoway_model)https://stackoverflow.com/questions/62805107
复制相似问题