[R] Error in svychisq and svyttest with svrepdesign

Anthony Damico ajdamico at gmail.com
Tue Mar 10 16:22:11 CET 2015


hi anabela, please provide a complete reproducible example.  you need to
use ?dput  -- we are not able to import "dadosSPSS.sav" so we cannot
recreate your problem in order to help you.  thanks!

http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example



On Tue, Mar 10, 2015 at 9:31 AM, Anabela Afonso <afaafonso at gmail.com> wrote:

> Dear Forum,
>
> I’m working with a complex sample and with replication weights. I defined
> my design svrepdesign function. I’m trying to run svychisq and
> svyttest function
> from the survey package and I get the error:
>
>
>
> Error in crossprod(x, y) :
>
>   requires numeric/complex matrix/vector arguments
>
>
>
> I can’t understand this error. I kindly ask if someone can help me out.
>
>
>
> Thanks in advance,
>
>
>
>
> Here is my code and some output:
>
> > library(foreign); library(survey)
>
> > dados<-read.spss("dadosSPSS.sav", use.value.labels=T, to.data.frame=T)
>
> > class(dados)
>
> [1] "data.frame"
>
> > str(dados)
>
> 'data.frame':    7624 obs. of  4 variables:
>
>  $ Sex     : Factor w/ 2 levels "Male","Female": 1 1 1 1 1 1 1 1 1 1 ...
>
>  $ Computer: Factor w/ 2 levels "Yes","NO": 1 1 2 1 1 1 1 1 1 2 ...
>
>  $ Color   : Factor w/ 3 levels "Red","Green",..: 1 1 1 1 1 1 1 1 1 1 ...
>
>  $ Number  : num  2 1 0 2 1 2 1 2 1 0 ...
>
>  $ final.w : num  1267 596 1143 1069 542 ...
>
> # Note: Variable Color with NA
>
> > repdes<-svrepdesign(data=dados, repweights=rep.w, scale=1, rscales=r.sc,
> type="JKn", weights=~final.w, combined.weights=F)
>
> > summary(repdes)
>
> Call: svrepdesign.default(data = dados, repweights = rep.w, scale = 1,
>
>     rscales = r.sc, type = "JKn", weights = ~final.w, combined.weights =
> F)
>
> Stratified cluster jackknife (JKn) with 428 replicates.
>
> Variables:
>
> [1] "Sex"      "Computer" "Color"    "Number"   "final.w"
>
>
>
> > svytable(~Sex+Computer, repdes)
>
>         Computer
>
> Sex            Yes        NO
>
>   Male   1501598.7 1063055.3
>
>   Female 1485933.1  810557.9
>
>
>
> > svytable(~Sex+Color, repdes)  # NA are ignored
>
>         Color
>
> Sex            Red     Green    Yellow
>
>   Male   2060708.5  219678.4  286038.6
>
>   Female 1840511.7  229763.8  224444.0
>
>
>
> > svychisq(~Sex+Computer, repdes)
>
> Error in crossprod(x, y) :
>
>   requires numeric/complex matrix/vector arguments
>
>
>
> > svychisq(~Sex+Color, repdes)
>
> Error in crossprod(x, y) :
>
>   requires numeric/complex matrix/vector arguments
>
>
>
> > svyttest(Number ~Sex, repdes)
>
> Error in crossprod(x, y) :
>
>   requires numeric/complex matrix/vector arguments
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

	[[alternative HTML version deleted]]



More information about the R-help mailing list