statnet / ergm.ego

Fit, Simulate and Diagnose Exponential-Family Random Graph Models to Egocentrically Sampled Network Data https://statnet.org
Other
14 stars 4 forks source link

Error in `[[<-.data.frame`(`*tmp*`, attrname, value = integer(0)) : replacement has 0 rows, data has 9338 #1

Closed dth2 closed 7 years ago

dth2 commented 7 years ago

I am generating a strange error about my attributes being integer. I have made sure that my attributes are charter but I am still getting the error. Code below and data attached.

Load required packages.

suppressPackageStartupMessages(library(EpiModelHIV))
suppressPackageStartupMessages(library(EpiModelHPC))
suppressPackageStartupMessages(library(ergm.ego))

Make the three ergm.ego objects.

ego.obj_m<-as.egodata(nsfg.egodata$egos,alters=nsfg.egodata$altersMain,egoIDcol="ego")
ego.obj_c<-as.egodata(nsfg.egodata$egos,alters=nsfg.egodata$altersCasual,egoIDcol="ego")
ego.obj_i<-as.egodata(nsfg.egodata$egos,alters=nsfg.egodata$altersOT,egoIDcol="ego")

Make sure the variables for casual and main are character.

ego.obj_m$egos$casual<-as.character(ego.obj_m$egos$casual)
ego.obj_m$egos$main<-as.character(ego.obj_m$egos$main)
ego.obj_c$egos$casual<-as.character(ego.obj_c$egos$casual)
ego.obj_c$egos$main<-as.character(ego.obj_c$egos$main)
ego.obj_i$egos$casual<-as.character(ego.obj_i$egos$casual)
ego.obj_i$egos$main<-as.character(ego.obj_i$egos$main)

Just to be sure make them n/y.

ego.obj_m$egos$casual<-ifelse(ego.obj_m$egos$casual=="0","n","y")
ego.obj_m$egos$main<-ifelse(ego.obj_m$egos$main=="0","n","y")
class(ego.obj_m$egos$casual)
[1] "character"
class(ego.obj_m$egos$main)
[1] "character"

This fits.

fit.m<-ergm.ego(ego.obj_m ~edges + nodefactor("sex",base=1)+nodefactor("race",base=1),
+                 control=control.ergm.ego(ppopsize=25000, stats.est="bootstrap"))
Constructing pseudopopulation network.
Note: Constructed network has size 20206, different from requested 25000. Estimation should not be meaningfully affected.
Unable to match target stats. Using MCMLE estimation.
Starting maximum likelihood estimation via MCMLE:
Iteration 1 of at most 20: 
The log-likelihood improved by 0.01582 
Step length converged once. Increasing MCMC sample size.
Iteration 2 of at most 20: 
The log-likelihood improved by 0.06599 
Step length converged twice. Stopping.

This model was fit using MCMC.  To examine model diagnostics and check for degeneracy, use the mcmc.diagnostics() function.

This does not. No idea what the difference is????

fit.m<-ergm.ego(ego.obj_m ~edges + nodefactor("casual",base=1)+nodefactor("race",base=1),
+                 control=control.ergm.ego(ppopsize=25000, stats.est="bootstrap"))
Constructing pseudopopulation network.
Note: Constructed network has size 20206, different from requested 25000. Estimation should not be meaningfully affected.
Error in `[[<-.data.frame`(`*tmp*`, attrname, value = integer(0)) : 
  replacement has 0 rows, data has 9338
Error in `[[<-.data.frame`(`*tmp*`, attrname, value = integer(0)) : 
  replacement has 0 rows, data has 9338
In addition: Warning message:
In ergm.ego(ego.obj_m ~ edges + nodefactor("casual", base = 1) +  :
  Non-scaling statistic detected when trying to fit a model: network-size invariant parametrization probably does not exist so pseudopopulation size should equal the population size.

nsfg.egodata.zip