how to calculate prevalence using sql code

前端 未结 3 497
伪装坚强ぢ
伪装坚强ぢ 2021-01-28 04:36

I am trying to calculate prevalence in sql. kind of stuck in writing the code. I want to make automative code.

I have check that I have 1453477 of sample size and numbe

3条回答
  •  情歌与酒
    2021-01-28 04:47

    I am pretty sure that the logic that you want is something like this:

    select avg( (condition_id = 12345)::int )
    from disease;
    

    Your version doesn't have the sample size, because you are filtering out people without the condition.

    If you have duplicate people in the data, then this is a little more complicated. One method is:

    select (count(distinct person_id) filter (where condition_id = 12345)::numeric /
            count(distinct person_id
           )
    from disease;
    

提交回复
热议问题