johnfergusonNUIG / graphPAF

Other
2 stars 2 forks source link

Not calculating PAFs #2

Closed petermacp closed 4 months ago

petermacp commented 1 year ago

Many thanks for this package.

I can get the example in the package to run correctly, but whenever I attempt to run PAF_calc_discrete() with alternative datasets, I always get a PAF of 0.

Here is an example with the penguins dataset, and I get a similar result for our real data with a more complex model.

Any suggestions gratefully received.

library(tidyverse)
library(palmerpenguins)
library(broom)
library(graphPAF)

penguin_data <- penguins

penguin_data <- penguin_data %>%
  mutate(sex = case_when(
    sex=="male" ~ 1,
    sex=="female" ~0
  )) %>%
  drop_na() 

penguin_model <- glm(sex ~  species, data=penguin_data, family="binomial")

tidy(penguin_model, exponentiate = T, conf.int = T)
#> # A tibble: 3 × 7
#>   term             estimate std.error statistic p.value conf.low conf.high
#>   <chr>               <dbl>     <dbl>     <dbl>   <dbl>    <dbl>     <dbl>
#> 1 (Intercept)          1.00     0.166  5.15e-15   1.00     0.722      1.38
#> 2 speciesChinstrap     1        0.294 -1.18e-15   1.00     0.562      1.78
#> 3 speciesGentoo        1.05     0.247  2.04e- 1   0.838    0.648      1.71

PAF_calc_discrete(penguin_model, riskfactor = "species", refval="Adelie", data=penguin_data, calculation_method="D",ci=FALSE)
#> [1] 0

Created on 2022-10-12 with reprex v2.0.2

johnfergusonNUIG commented 1 year ago

Hi – thanks for bringing to my attention.

It’s actually because penguin_data is a tibble and not a data frame. Replacing the call below to PAF_calc_discrete with

PAF_calc_discrete(penguin_model, riskfactor = "species", refval="Adelie", data=as.data.frame(penguin_data), calculation_method="D",ci=FALSE)

will work.

John

From: petermacp @.> Date: Wednesday, 12 October 2022 at 11:19 To: johnfergusonNUIG/graphPAF @.> Cc: Subscribed @.***> Subject: [johnfergusonNUIG/graphPAF] Not calculating PAFs (Issue #2) EXTERNAL EMAIL: This email originated outside the University of Galway. Do not open attachments or click on links unless you believe the content is safe. RÍOMHPHOST SEACHTRACH: Níor tháinig an ríomhphost seo ó Ollscoil na Gaillimhe. Ná hoscail ceangaltáin agus ná cliceáil ar naisc mura gcreideann tú go bhfuil an t-ábhar sábháilte.

Many thanks for this package.

I can get the example in the package to run correctly, but whenever I attempt to run PAF_calc_discrete() with alternative datasets, I always get a PAF of 0.

Here is an example with the penguins dataset, and I get a similar result for our real data with a more complex model.

Any suggestions gratefully received.

library(tidyverse)

library(palmerpenguins)

library(broom)

library(graphPAF)

penguin_data <- penguins

penguin_data <- penguin_data %>%

mutate(sex = case_when(

sex=="male" ~ 1,

sex=="female" ~0

)) %>%

drop_na()

penguin_model <- glm(sex ~ species, data=penguin_data, family="binomial")

tidy(penguin_model, exponentiate = T, conf.int = T)

> # A tibble: 3 × 7

> term estimate std.error statistic p.value conf.low conf.high

>

> 1 (Intercept) 1.00 0.166 5.15e-15 1.00 0.722 1.38

> 2 speciesChinstrap 1 0.294 -1.18e-15 1.00 0.562 1.78

> 3 speciesGentoo 1.05 0.247 2.04e- 1 0.838 0.648 1.71

PAF_calc_discrete(penguin_model, riskfactor = "species", refval="Adelie", data=penguin_data, calculation_method="D",ci=FALSE)

> [1] 0

Created on 2022-10-12 with reprex v2.0.2https://reprex.tidyverse.org

— Reply to this email directly, view it on GitHubhttps://github.com/johnfergusonNUIG/graphPAF/issues/2, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AGHOLTJ2RQD26LMOMT5AJLDWC2GEDANCNFSM6AAAAAARDEKIQE. You are receiving this because you are subscribed to this thread.Message ID: @.***>

petermacp commented 1 year ago

Brilliant! That works. thank you