You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The margins() function returns an error when a svyglm object has omitted observations from the original data due to missingness. It appears to have trouble reconciling the number of rows in the original data with the number of rows actually used.
## load package
library("margins")
# Create a survey design using the survey package vignette
library(survey)
data(api)
dstrat<- svydesign(id=~1,strata=~stype, data=apistrat, fpc=~fpc)
dclus2<-svydesign(id=~dnum+snum, fpc=~fpc1+fpc2, data=apiclus2)
# Run a regressionm1<- svyglm(api00~ell+meals+mobility, design=dclus2)
# So far so good, margins() works
margins(m1, design=dclus2)
# Now simulate what happens if values are missingapiclus2_modified<-apiclus2apiclus2_modified[1:10, "meals"] <-NA# Create survey design and run regressiondclus2_modified<-svydesign(id=~dnum+snum, fpc=~fpc1+fpc2, data=apiclus2_modified)
m2<- svyglm(api00~ell+meals+mobility, design=dclus2_modified)
# margins() fails
margins(m2, design=dclus2_modified)
## session info for your systemRversion3.6.1 (2019-07-05)
Platform:x86_64-apple-darwin15.6.0 (64-bit)
Runningunder:macOSMojave10.14.5Matrixproducts:defaultBLAS:/System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylibLAPACK:/Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dyliblocale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8attachedbasepackages:
[1] gridstatsgraphicsgrDevicesutilsdatasetsmethodsbaseotherattachedpackages:
[1] survey_4.0survival_3.1-12Matrix_1.2-18margins_0.3.26loadedviaa namespace (andnotattached):
[1] MASS_7.3-51.4compiler_3.6.1DBI_1.1.0tools_3.6.1
[5] splines_3.6.1data.table_1.13.4packrat_0.5.0lattice_0.20-38
[9] mitools_2.4prediction_0.3.14# Error message:Errorindata.frame(..., check.rows=FALSE, check.names=FALSE, fix.empty.names=FALSE, :argumentsimplydifferingnumberofrows:252, 232#Traceback: 13: stop(gettextf("arguments imply differing number of rows: %s",
paste(unique(nrows), collapse=", ")), domain=NA)
12:data.frame(..., check.rows=FALSE, check.names=FALSE, fix.empty.names=FALSE,
stringsAsFactors=FALSE)
11: make_data_frame(out, fitted= unclass(tmp), se.fitted= sqrt(unname(attributes(tmp)[["var"]])))
10: prediction.svyglm(model=model, data=data.table::rbindlist(list(d0,
d1)), type=type, calculate_se=FALSE, ...)
9: prediction(model=model, data=data.table::rbindlist(list(d0,
d1)), type=type, calculate_se=FALSE, ...)
8: dydx.default(X[[i]], ...)
7: FUN(X[[i]], ...)
6: lapply(c(varslist$nnames, varslist$lnames), dydx, data=data,
model=model, type=type, eps=eps, as.data.frame=as.data.frame,
...)
5: marginal_effects.glm(model=model, data=data, variables=variables,
type=type, eps=eps, varslist=varslist, ...)
4: marginal_effects(model=model, data=data, variables=variables,
type=type, eps=eps, varslist=varslist, ...)
3: build_margins(model=model, data=data_list[[i]], variables=variables,
type=type, vcov=vcov, vce=vce, iterations=iterations,
unit_ses=unit_ses, weights=wts, eps=eps, varslist=varslist,
...)
2: margins.svyglm(m2, design=dclus2_modified)
1: margins(m2, design=dclus2_modified)
The text was updated successfully, but these errors were encountered:
mattysimonson
changed the title
Error when svyglm drops observations due to missingness
Error when svyglm drops observations due to missingness [bug]
Jan 25, 2021
mattysimonson
changed the title
Error when svyglm drops observations due to missingness [bug]
Error when svyglm drops observations due to missingness
Jan 25, 2021
The margins() function returns an error when a
svyglm
object has omitted observations from the original data due to missingness. It appears to have trouble reconciling the number of rows in the original data with the number of rows actually used.The text was updated successfully, but these errors were encountered: