-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
C
and R
engine results differ for rate model
#71
Comments
Description To reproduce (after the previous one) First test with glm1. we get the preprocessed stats for a simple modelFormulaSimple <- callsDependent ~ 1 + indeg(friendshipNetwork) 2. we calculate the exposure timesand the stats for each dependent eventNdep <- length(prepData$intervals) we only need to calculate the update of the friendship net between the first and second eventupdates_T1 <- prepData$dependentStatsChange[[2]][[1]] times <- rep(0,(Ndep+Nexo)*Na ) dep or exo?isdep <- prepData$orderEvents[e] == 1 3. check glm resultsdf <- data.frame(times, logtimes = log(times), indegs_friend, outcomes) 4. check previous modelsmod04RateCSimple <- estimate( mod04RateRSimple <- estimate( coef(mod04RateCSimple) - coef(mod04RateRSimple) # 0.0061807584 -0.0009279592 Second test with glm1. we get the preprocessed stats for another simple model with time windowsFormulaSimple2 <- callsDependent ~ 1 + indeg(callNetwork, window = 300) 2. we calculate the exposure times and the stats for each dependent eventNexo2 <- length(prepData2$rightCensoredIntervals) this time we need to calculate window updatestimes2 <- rep(0,(Ndep+Nexo2)*Na ) updates_dep <- prepData2$dependentStatsChange dep or exo?isdep <- prepData2$orderEvents[e] == 1 3. check glm resultsdf2 <- data.frame(times = times2, logtimes = log(times2), indegs_window, outcomes = outcomes2) 4. check previous modelsmod04RateCSimple2 <- estimate( mod04RateRSimple2 <- estimate( coef(mod04RateCSimple2) - coef(mod04RateRSimple2) # 0.1557715 -0.9546496 ` |
Hopefully, this simulation helps with the discussion @stadtfeldethz and @marion-hoffman. It only has one exogenous event. ### small simulation
actDf <- data.frame(
label = LETTERS,
xVar = rbinom(length(LETTERS), 1, 0.2)
)
xVarChange <- rbinom(length(LETTERS), 1, 0.7)
X <- cbind(1, actDf$xVar)
endTime <- 30
exEventTime <- 15
parms <- c(log(1000 / endTime / length(LETTERS)), 1 )
expXb <- exp(X %*% parms)
sumRate <- sum(expXb)
time <- 0
events <- NULL
dfglm <- NULL
first <- TRUE
while (time < endTime) {
# cat("Time:", time, "\n")
timeEvent <- rexp(1, sumRate)
if (first && time + timeEvent > exEventTime) {
dfglm <- rbind(
dfglm,
data.frame(
time = time,
diffTime = exEventTime - time,
xVar = X[, 2],
outcomes = 0
)
)
X <- cbind(1, xVarChange)
expXb <- exp(X %*% parms)
sumRate <- sum(expXb)
time <- exEventTime
first <- FALSE
} else {
time <- time + timeEvent
sender <- sample(LETTERS, 1, prob = expXb)
receiver <- sample(LETTERS[sender != LETTERS], 1)
events <- rbind(
events,
data.frame(
time = time,
sender = sender,
receiver = receiver,
increment = 1
)
)
dfglm <- rbind(
dfglm,
data.frame(
time = time,
diffTime = timeEvent,
xVar = X[, 2],
outcomes = 1 * (LETTERS == sender)
)
)
}
}
changeAttr <- data.frame(
time = exEventTime,
node = LETTERS,
replace = xVarChange
)
actDf <- defineNodes(actDf) |>
linkEvents(changeEvents = changeAttr, attribute = "xVar")
netEvents <- defineNetwork(nodes = actDf) |>
linkEvents(changeEvents = events, nodes = actDf)
depEvents <- defineDependentEvents(events, nodes = actDf,
defaultNetwork = netEvents)
# model exclude last event
preproTest <- estimate(depEvents ~ 1 + ego(actDf$xVar),
model = "DyNAM", subModel = "rate",
estimationInit = list(startTime = 0, endTime = 30))
summary(modTest)
confint(modTest)
# model exclude last event
dfglm$logtimes <- log(dfglm$diffTime)
modTestGLM <- glm(outcomes ~ offset(logtimes) + xVar,
family = poisson(link = "log"),
data = dfglm[seq.int(1, (nrow(events)) * length(LETTERS)), ])
summary(modTestGLM)
confint(modTestGLM)
library(broom)
library(pixiedust)
tidy(modTestGLM, conf.int = TRUE)
tidy(modTest, conf.int = TRUE)
From one run > library(broom)
> library(pixiedust)
> parms
[1] 0.2484614 1.0000000
> tidy(modTestGLM, conf.int = TRUE) |>
+ dust() |>
+ sprinkle(col = c(2:4, 6:7), round = 6) |>
+ sprinkle(col = 5, fn = quote(pvalString(value)))
term estimate std.error statistic p.value conf.low conf.high
1 (Intercept) 0.224695 0.045268 4.963687 < 0.001 0.134638 0.312124
2 xVar 1.011514 0.052867 19.133289 < 0.001 0.908709 1.115992
> tidy(modTest, conf.int = TRUE) |>
+ dust() |>
+ sprinkle(col = c(2:4, 6:7), round = 6) |>
+ sprinkle(col = 5, fn = quote(pvalString(value)))
term estimate std.error statistic p.value conf.low conf.high
1 Intercept 0.224695 0.045268 4.963685 < 0.001 0.135972 0.313419
2 actDf xVar ego 1.011514 0.052867 19.133283 < 0.001 0.907897 1.115131
> coef(modTestGLM) - coef(modTest)
(Intercept) xVar
-3.640075e-10 3.640201e-10 Seems like the last time interval during preprocessing is calculated wrong and produce the differences between glm and goldfish estimations. |
- Style C++ code to 80 columns - Debug wrong update in compositional change second mode
Describe the bug
Default
C
engine gives different result asR
version when windows effects are used.To Reproduce
Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: