[R] Significance of Svyrepdesign Object Warning
Courtney Benjamin
cbenjami at BTBOCES.ORG
Fri Oct 28 02:53:20 CEST 2016
Hello Mr. Dunlap,
I have gone back and re-read the responses to my question. I am interested in trying to apply your recommendation so I am doing things correctly; however I am not sure how to go about doing it within my code. It appears that you are digging quite deeply into R where I am not yet familiar. I am including a reproducible example; would you be willing to show an example of how it would be done? I greatly appreciate your advisement and time.
Sincerely,
Courtney
library(RCurl)
library(survey)
data <- getURL("https://raw.githubusercontent.com/cbenjamin1821/careertech-ed/master/elsq1adj.csv")
elsq1ch <- read.csv(text = data)
#Specifying the svyrepdesign object which applies the BRR weights
elsq1ch_brr<-svrepdesign(variables = elsq1ch[,1:16], repweights = elsq1ch[,18:217], weights = elsq1ch[,17], combined.weights = TRUE, type = "BRR")
elsq1ch_brr
#Logistic regression call which yields a warning regarding svyrepdesign object
allCC <-svyglm(formula=F3ATTAINB~F1PARED+BYINCOME+F1RACE+F1SEX+F1RGPP2+F1HIMATH+F1RTRCC,family="binomial",design=elsq1ch_brr,subset=BYSCTRL==1&G10COHRT==1,na.action=na.exclude)
summary(allCC)
Courtney Benjamin
Broome-Tioga BOCES
Automotive Technology II Teacher
Located at Gault Toyota
Doctoral Candidate-Educational Theory & Practice
State University of New York at Binghamton
cbenjami at btboces.org<mailto:cbenjami at btboces.org>
607-763-8633
________________________________
From: William Dunlap <wdunlap at tibco.com>
Sent: Sunday, October 23, 2016 2:24 PM
To: Anthony Damico
Cc: Courtney Benjamin; r-help at r-project.org; Thomas Lumley
Subject: Re: [R] Significance of Svyrepdesign Object Warning
The immediate problem could be solved by changing the following lines in survey:::summary.svrepglm from
presid <- resid(object, "pearson")
dispersion <- sum(object$survey.design$pweights * presid^2,
na.rm = TRUE)/sum(object$survey.design$pweights)
to
presid <- resid(object, "pearson")
pweights <- naresid(object$na.action, object$survey.design$pweights)
dispersion <- sum(pweights * presid^2, na.rm = TRUE)/sum(pweights,
na.rm = TRUE)
'naresid' uses the information from na.exclude to match up the residuals
with the row in the data that they correspond to. resid() calls it so it should
also be applied to pweights so they line up correctly.
Bill Dunlap
TIBCO Software
wdunlap tibco.com<http://tibco.com>
On Sun, Oct 23, 2016 at 11:17 AM, Anthony Damico <ajdamico at gmail.com<mailto:ajdamico at gmail.com>> wrote:
hi, great example. i am ccing survey package author/maintainer dr.
lumley. why do you have `na.action=na.exclude`? if you remove it, things
work as expected--
library(RCurl)
library(survey)
data <- getURL("
https://raw.githubusercontent.com/cbenjamin1821/careertech-ed/master/elsq1adj.csv
")
elsq1ch <- read.csv(text = data)
#Specifying the svyrepdesign object which applies the BRR weights
elsq1ch_brr<-svrepdesign(variables = elsq1ch[,1:16], repweights =
elsq1ch[,18:217], weights = elsq1ch[,17], combined.weights = TRUE, type =
"BRR")
elsq1ch_brr
#Logistic regression call which yields a warning regarding svyrepdesign
object
# your warning
a <-
svyglm(formula=F3ATTAINB~F1PARED+BYINCOME+F1RACE+F1SEX+F1RGPP2+F1HIMATH+F1RTRCC,family="binomial",design=elsq1ch_brr,subset=BYSCTRL==1&G10COHRT==1,na.action=na.exclude)
summary(a)
# works fine
a <-
svyglm(formula=F3ATTAINB~F1PARED+BYINCOME+F1RACE+F1SEX+F1RGPP2+F1HIMATH+F1RTRCC,family="binomial",design=elsq1ch_brr,subset=BYSCTRL==1&G10COHRT==1)
summary(a)
the mismatch of vectors generating that warning happens inside
debug(survey:::summary.svrepglm)
[..snip..]
Browse[2]> length(presid)
[1] 12614
Browse[2]> length(object$survey.design$pweights)
[1] 8397
and including vs excluding the na.action=na.exclude gives you a
slightly different dispersion parameter calculation
(Dispersion parameter for binomial family taken to be 0.7756235)
(Dispersion parameter for binomial family taken to be 0.7849244)
not sure if the two survey:::residuals.sv<http://residuals.sv>* methods should deal with the
na.action= parameter?
thanks
On Sun, Oct 23, 2016 at 11:56 AM, Courtney Benjamin <cbenjami at btboces.org<mailto:cbenjami at btboces.org>>
wrote:
> Hello R Users,
>
> I am using Lumley's Survey Package in R to analyze complex survey data
> that involves 200 balanced repeated replicate (BRR) weight variables. I
> have ensured that my svyrepdesign object that specifies the application of
> the BRR weights to the data set is accurate and I have matched the
> published standard errors of the data set.
>
> When doing a logistic regression through the svyglm call, I receive the
> following warning:
>
> In object$survey.design$pweights * presid^2 :
> longer object length is not a multiple of shorter object length?
> I have search around quite a bit online and have not been able to find any
> good interpretation of its meaning. I want to be sure that I am not making
> some type of mistake that is causing this warning to be produced. Any
> advisement is greatly appreciated.
> The following is an MRE that can be pasted into the R console:
> library(RCurl)
> library(survey)
> data <- getURL("https://raw.githubusercontent.com/
> cbenjamin1821/careertech-ed/master/elsq1adj.csv")
> elsq1ch <- read.csv(text = data)
> #Specifying the svyrepdesign object which applies the BRR weights
> elsq1ch_brr<-svrepdesign(variables = elsq1ch[,1:16], repweights =
> elsq1ch[,18:217], weights = elsq1ch[,17], combined.weights = TRUE, type =
> "BRR")
> elsq1ch_brr
> #Logistic regression call which yields a warning regarding svyrepdesign
> object
> svyglm(formula=F3ATTAINB~F1PARED+BYINCOME+F1RACE+F1SEX+
> F1RGPP2+F1HIMATH+F1RTRCC,family="binomial",design=
> elsq1ch_brr,subset=BYSCTRL==1&G10COHRT==1,na.action=na.exclude)
> allCC <- summary(svyglm(formula=F3ATTAINB~F1PARED+BYINCOME+
> F1RACE+F1SEX+F1RGPP2+F1HIMATH+F1RTRCC,family="binomial",
> design=elsq1ch_brr,subset=BYSCTRL==1&G10COHRT==1,na.action=na.exclude))
> allCC
>
> #Session Info
> #R version 3.3.1 (2016-06-21)
> #Platform: x86_64-w64-mingw32/x64 (64-bit)
> #Running under: Windows >= 8 x64 (build 9200)
>
> #locale:
> # [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United
> States.1252
> #[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
> #[5] LC_TIME=English_United States.1252
> #attached base packages:
> # [1] grid stats graphics grDevices utils datasets
> methods base
> #other attached packages:
> #[1] survey_3.31-2 survival_2.39-4 Matrix_1.2-6 RCurl_1.95-4.8
> bitops_1.0-6
> #loaded via a namespace (and not attached):
> #[1] tools_3.3.1 splines_3.3.1 knitr_1.14 lattice_0.20-33
>
>
> Courtney Benjamin
>
> Broome-Tioga BOCES
>
> Automotive Technology II Teacher
>
> Located at Gault Toyota
>
> Doctoral Candidate-Educational Theory & Practice
>
> State University of New York at Binghamton
>
> cbenjami at btboces.org<mailto:cbenjami at btboces.org><mailto:cbenjami at btboces.org<mailto:cbenjami at btboces.org>>
>
> 607-763-8633<tel:607-763-8633>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org<mailto: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]]
______________________________________________
R-help at r-project.org<mailto: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