Help defining discretized normal distribution?

23 views
Skip to first unread message

Gregory

unread,
Dec 15, 2021, 2:18:19 PM12/15/21
to nimble-users
Hello Nimble users,

I'd like to define a discretized version of a normal distribution, and I'm not at all sure how to go about it. In principal it seems pretty simple: take the normal pdf at the integers and integrate to 1. Unfortunately, I can't seem to figure out how to even get started coding that as an R or Nimble function. Would this be fairly straight-forward to implement, or should I look for another approach to the problem it would solve?

Cheers,
Gregory

Perry de Valpine

unread,
Dec 16, 2021, 9:04:34 PM12/16/21
to Gregory, nimble-users
Hi Gregory,

Here is one try, defining the discretized pdf as the area under the curve from x-0.5 to x+0.5.

ddiscnorm <- nimbleFunction(
 run = function(x = double(), mean = double(), sd = double(), log = integer(default = 0)) {
    ans <- pnorm(x + 0.5, mean = mean, sd = sd) - pnorm(x-0.5, mean = mean, sd = sd)
    if(log) return (log(ans))
    return(ans)
 returnType(double())
}
)

-Perry


--
You received this message because you are subscribed to the Google Groups "nimble-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nimble-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nimble-users/d575f32e-7749-426a-856d-d837d4bcbb62n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages