[R] Dimensions on svychisq on svydesign

Thomas Lumley tlumley at u.washington.edu
Mon May 10 21:17:26 CEST 2010



I think your problem is that HL07 is not a data frame but a list.  read.spss() produces a list rather than a data frame by default, and svydesign() requires a data frame.  You can use as.data.frame() to turn HL07 into a data.frame.

The weights also look a bit strange -- you have sampling probabilities ranging from 0.27 to 3 -- this isn't necessarily wrong but is unusual.

    -thomas

On Sun, 9 May 2010, Stefán Jónsson wrote:

> Dear Forum
>
> I a running  svychisq from the survey package and get errors with the number
> of dimensions,
> errors that I do not understand and do not know how to fix.
>
> I ask you kindly to help me out.
>
> The eror message follows with some information below. I hope there are
> enough information to help me to fix the problem if not please let me know
> what is needed
>
> Best
> Stefan Hrafn Jonsson
>
>> QHISQ2 <- svychisq(~S73 + S36 , design = HL7design , statistic  = "Chisq")
> Error in design$variables[, as.character(rows)] :
>  incorrect number of dimensions
>
>
>
>
> HL07 <- read.spss("C:/Users/Stefan/Desktop/export1.por", use.value.labels =
> FALSE)
>
> HL7design <-svydesign(id=~ID2,strata=~STRATA, weights=~VIGT2, data=HL07 )
>
> summary(HL7design)
>
>
>
>> summary(HL7design)
> Stratified Independent Sampling design (with replacement)
> svydesign(id = ~ID2, strata = ~STRATA, weights = ~VIGT2, data = HL07)
> Probabilities:
>   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
> 0.3779  0.6933  1.2880  1.3270  1.6970  3.0980
> Stratum Sizes:
>             1   2   3   4   5   6  11  12  13  14  15  16
> obs        414 403 447 479 501 464 364 453 514 540 534 521
> design.PSU 414 403 447 479 501 464 364 453 514 540 534 521
> actual.PSU 414 403 447 479 501 464 364 453 514 540 534 521
> Data variables:
> NULL
>>
>
>
>
>
>
> xtabs(~HL07$S73 + HL07$S36 )
>        HL07$S36
> HL07$S73   1   2   3   4   5   6   7   8   9
>       1 199 248 517 707 736 156  57  10   2
>       2 458 294 636 992 543  55  18   3   3
>
>
>> QHISQ2 <- svychisq(~HL07$S73 + HL07$S36 , design = HL7design , statistic
> = "Chisq")
> Error in design$variables[, as.character(rows)] :
>  incorrect number of dimensions
>
>
>
>> QHISQ2 <- svychisq(~S73 + S36 , design = HL7design , statistic  = "Chisq")
> Error in design$variables[, as.character(rows)] :
>  incorrect number of dimensions
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

Thomas Lumley			Assoc. Professor, Biostatistics
tlumley at u.washington.edu	University of Washington, Seattle


More information about the R-help mailing list