[R] Svyglm Error in Survey Package

Fox, John jfox at mcmaster.ca
Sun Sep 25 15:21:15 CEST 2016


Dear Courtney,

You're confusing a function call, na.action(na.omit), with an argument specification, na.action=na.omit  (and, in any event, there is no na.action() function). But you don't have to specify na.action=na.omit, because na.omit (which produces a complete-case analysis) is the default na.action. See ?glm for more information. 

If you haven't already done so, you might want to read something about how statistical modeling functions in R -- and possibly R more generally -- work. In the long run, that likely will save you some time.

I'm cc'ing this to the r-help email list, where you posed your original question. It's generally a good idea to keep responses on the list.

I hope this helps,
 John

> -----Original Message-----
> From: Courtney Benjamin [mailto:cbenjami at BTBOCES.ORG]
> Sent: September 24, 2016 10:55 PM
> To: Fox, John <jfox at mcmaster.ca>
> Subject: Re: Svyglm Error in Survey Package
> 
> Hello Dr. Fox,
> Thank you very much for your explanation; I am in better shape now with the
> subset argument and I am no longer getting the error.  Now I am not having
> success with specifying the na.action argument.  I would like to exclude NAs
> like I have done in other commands with na.rm=TRUE.
> The following are my attempts:
> >
> summary(svyglm(F3ATTAINMENT~F1PARED+F1SES2QU,design=elsq1ch_brr,su
> bset
> > =BYSCTRL==1 & G10COHRT==1,na.action))
> Error in glm(formula = F3ATTAINMENT ~ F1PARED + F1SES2QU, subset =
> BYSCTRL ==  :
>   argument "na.action" is missing, with no default
> 
> >
> summary(svyglm(F3ATTAINMENT~F1PARED+F1SES2QU,design=elsq1ch_brr,su
> bset
> > =BYSCTRL==1 & G10COHRT==1,na.action(na.omit))
> +
> Any guidance you would be willing to provide is greatly appreciated; I have
> only been using R for about 6 months.
> Sincerely
> Courtney
> 
> 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
> 607-763-8633
> 
> ________________________________________
> From: Fox, John <jfox at mcmaster.ca>
> Sent: Saturday, September 24, 2016 9:38 AM
> To: Courtney Benjamin
> Cc: r-help at r-project.org
> Subject: RE: Svyglm Error in Survey Package
> 
> Dear Courtney,
> 
> I think that you're confused about how to use the subset argument to svyglm()
> and about what the subset() function returns. The subset argument should be a
> logical expression, evaluating to TRUE or FALSE for each case; subset() returns
> a data set (e.g., a "survey.design" object).
> 
> Here's an example adapted from ?svyglm:
> 
> ------------------- snip-------------------
> data(api)
> dstrat<-svydesign(id=~1,strata=~stype, weights=~pw, data=apistrat, fpc=~fpc)
> summary(svyglm(api00~ell+meals+mobility, design=dstrat))
> summary(svyglm(api00~ell+meals+mobility, design=dstrat, subset = pcttest >
> 90)) summary(svyglm(api00~ell+meals+mobility, design=subset(dstrat, subset
> = pcttest > 90)))
> ------------------- snip-------------------
> 
> The last two commands produce the same results.
> 
> I hope this helps,
>  John
> 
> -----------------------------
> John Fox, Professor
> McMaster University
> Hamilton, Ontario
> Canada L8S 4M4
> Web: socserv.mcmaster.ca/jfox
> 
> 
> 
> > -----Original Message-----
> > From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of
> > Courtney Benjamin
> > Sent: September 23, 2016 11:01 PM
> > To: r-help at r-project.org
> > Subject: [R] Svyglm Error in Survey Package
> >
> > In attempting to use the svyglm call in the R Survey Package, I am
> > receiving the
> > error: Error in pwt[i] : invalid subscript type 'list'
> >
> > I have not been able to find a lot of information on how to resolve
> > the error; one source advised it was related to how the subsetting
> > command was executed.
> >
> > This was my initial attempt:
> >
> > mc1 <-
> >
> svyglm(F3ATTAINMENT~F1SES2QU+F1RGPP2,elsq1ch_brr,subset(elsq1ch_brr,
> > BYSCTRL==1 & G10COHRT==1),na.action)
> > summary(mc1)
> > This was my second approach trying to change up how I had subsetted
> > the
> > data:
> > summary(mc1)
> > samp1 <- subset(elsq1ch_brr,BYSCTRL==1 & G10COHRT==1)
> > dim(samp1)
> > mc1 <-
> >
> svyglm(F3ATTAINMENT~F1SES2QU+F1RGPP2,elsq1ch_brr,subset=samp1,na.ac
> > tion)
> > summary(mc1)?
> >
> > Both attempts resulted in the same error stated above.  Any advisement
> > in how to resolve this error would be greatly appreciated.
> > Sincerely,
> > Courtney Benjamin
> >
> > ?
> >
> >
> >
> > 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
> >
> >       [[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.



More information about the R-help mailing list