Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Unexpected Behavior in Neonate Simulations #1

@schnebeni

Description

@schnebeni

I have the following code block, which simulates 2000 neonates and then ages them to 2 years of age. I plotted the growth curve of a sample of the simulated individuals using ggplot2. Attached is the resulting growth curves.

library(SimKid)
simpop<-sim_kid(2000,agemin=0,agemax=0,prob_female=0.5,age0isbirth=T,masterseed=123)
Y     <-grow_kid(data=simpop,grow_time=24,tstep=1,age0isbirth=T)

w<-unique(Y$ID)[1:20]
ggplot(Y[Y$ID%in%w,],aes(x=AGE,y=WTKG,col=factor(ID)))+
  geom_line()+
  theme(legend.position="none")+
  facet_wrap(~SEXF)+xlab("AGE")+ylab("WEIGHT")
Image

This doesn't look correct to me for simulations from the CDC growth curves. If I use the following code, which uses the wtage.xls and wtageinf.xls charts available at https://www.cdc.gov/growthcharts/cdc-data-files.htm, I get much smoother curves.

df <- dplyr::bind_rows(
  readxl::read_xls(here::here("data","source","wtage.xls")), 
  readxl::read_xls(here::here("data","source","wtageinf.xls"))
)
df <- df[order(df$Agemos,df$Sex),]
df <- df[!duplicated(df[,c("Agemos","Sex")]) & df$Agemos<=24,]

seed   = 123

N      = 1000

X   = rep(1:nrow(df), each=N)
SEX = df[X,][["Sex"]]
AGE = df[X,][["Agemos"]]
L   = df[X,][["L"]]
M   = df[X,][["M"]]
S   = df[X,][["S"]]

set.seed(seed)
Z   = rep(rnorm(n=N), nrow(df))

WEIGHT = M*((1+ L*S*Z)**(1/L))
Y      = data.frame(Z, SEX, AGE, WEIGHT)

library(ggplot2)

w<-unique(Y$Z)[1:9]
ggplot(Y[Y$Z%in%w,],aes(x=AGE,y=WEIGHT,col=factor(Z)))+
  geom_line()+
  theme(legend.position="none")+
  facet_wrap(~SEX)
Image

Do you know what is causing the discrepancy between the smoothness of these two curves?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions