Search code examples
rcausalitycausal-inference

R console could not find function "get_type_prob"


I am working through the book Integrated Inferences which uses the R library CausalQueries to perform example calculations.

As the title describes, a number of other CausalQueries functions are working well, but I get an error that says "could not find function "get_type_prob."

I installed R 4.4 for windows yesterday and installed the CausalQueries library in a user-specific folder (because the R package manager couldn't add it to the system installation. I load it into the workspace with library(CausalQueries), verify it appears in search() results, and the first few function calls to other library functions work.

Working through this example, pasting it in an expression at a time:

`model <- make_model("X -> M -> Y") |>
         set_restrictions("X[]==0") |>
         set_restrictions("M[X=1] < M[X=0]") |>
         set_restrictions("Y[M=1] < Y[M=0]")   

q1 <- "Y[X = 1] > Y[X = 0]"
q2 <- "X == 1 & Y == 1"

df <- data.frame(
  a1 = get_query_types(model, q1)$types,
  a2 = get_query_types(model, q2)$types,
  p  = get_type_prob(model))`

I expected this to work and give the data that informs the table in the CausalQueries docs.
Full session:

> library(CausalQueries)
Loading required package: dplyr

Attaching package: ‘dplyr’

The following objects are masked from ‘package:stats’:

    filter, lag

The following objects are masked from ‘package:base’:

    intersect, setdiff, setequal, union

Loading required package: Rcpp
> model <- make_model("X -> M -> Y") |>
+          set_restrictions("X[]==0") |>
+          set_restrictions("M[X=1] < M[X=0]") |>
+          set_restrictions("Y[M=1] < Y[M=0]")   
> 
> q1 <- "Y[X = 1] > Y[X = 0]"
> q2 <- "X == 1 & Y == 1"
> 
> df <- data.frame(
+   a1 = get_query_types(model, q1)$types,
+   a2 = get_query_types(model, q2)$types,
+   p  = get_type_prob(model))
Error in get_type_prob(model) : could not find function "get_type_prob"

> ls("package:CausalQueries")
 [1] "collapse_data"           "complements"            
 [3] "data_type_names"         "decreasing"             
 [5] "democracy_data"          "draw_causal_type"       
 [7] "expand_data"             "expand_wildcard"        
 [9] "get_all_data_types"      "get_event_probabilities"
[11] "get_query_types"         "grab"                   
[13] "increasing"              "institutions_data"      
[15] "interacts"               "interpret_type"         
[17] "lipids_data"             "make_data"              
[19] "make_events"             "make_model"             
[21] "make_parameters"         "make_parameters_df"     
[23] "make_prior_distribution" "make_priors"            
[25] "non_decreasing"          "non_increasing"         
[27] "observe_data"            "plot_model"             
[29] "query_distribution"      "query_model"            
[31] "realise_outcomes"        "set_confound"           
[33] "set_parameter_matrix"    "set_parameters"         
[35] "set_prior_distribution"  "set_priors"             
[37] "set_restrictions"        "simulate_data"          
[39] "substitutes"             "te"                     
[41] "update_model"

Solution

  • Looks like get_type_prob is not an exported function. Probably the package was updated after the book was written and no automatic checks were performed.

    What is strange is that the manual on CRAN still contains all the internal functions. That typically shouldn't happen. CRAN should complain when you try to make documentation for internal functions, and when you mark Roxygen2 comments with @internal, the man files for that function should not be created.

    See: https://github.com/integrated-inferences/CausalQueries/blob/master/R/get_type_prob.R#L9

    I see that you have already asked on git. Good job!