0

When I run a script in R, there is no error, and everything works.

    library(tweedie)
    data_tweedie <- glm(y ~ ., data = data, family = tweedie(var.power = data_tw$p.max, link.power = 0))

But when I knit the R markdown with the same r section, it gives me an Error

enter image description here

Is it some kind of a bug of the package?

here is a reproducible example

library(tweedie)
x <- seq(0,10,1)
y <- seq(0,20,2)
data <- as.data.frame(y, x)
Model <- glm(y ~ x, data = data, family = tweedie(var.power = 1.5, link.power = 0)) 

When I run it just in console of R studio, there is no problem. But when I include the same exact piece in the R markdown document, it gives an error

Yulia Kentieva
  • 641
  • 4
  • 13
  • Can you try `tweedie::tweedie` – akrun Mar 09 '22 at 20:06
  • Do you also have `library(tweedie)` in the rmarkdown document somewhere? Is it in a chunk that is being evaluated? It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) that we can run and test ourselves. – MrFlick Mar 09 '22 at 20:06
  • @akrun I tried doing tweedie::tweedie, it gives me 'tweedie' is not an exported object from 'namespace:tweedie' Error – Yulia Kentieva Mar 09 '22 at 22:16

1 Answers1

0

The issue seems to be that the package statmod is not loaded in the R markdown code, which is needed for the tweedie family object (it is not part of tweedie package: https://rdrr.io/cran/statmod/man/tweedie.html)

Adding

library(statmod) 

to the R markdown code, should solve the issue. I am assuming your R script works in the console, because statmod is loaded in the environment either directly or through a dependency. Adding the library solves the issue when I am trying to reproduce it.

ppeloton
  • 51
  • 4