Learn R Programming

⚠️There's a newer version (1.4.0) of this package.Take me there.

pharmr is an R package and toolkit for pharmacometrics. It consists of

  • A model abstraction as a foundation for higher level operations
  • Functions for
    • manipulation of models
    • extraction of model estimation results
    • manipulation of datasets
    • various calculations and evaluations
    • running models
    • running higher level workflows or tools

pharmr is implemented as an R wrapper to Pharmpy. It provides an R interface to all functions found in the modeling and tools modules (documented here). Each function is also available via the help-function (or ?).

Installation

Install from github

pharmr uses the package reticulate for calling Python from R. When installing pharmr, reticulate will give a prompt to set up the reticulate environment. In order to use pharmr, you need to have Python 3.9, 3.10 or 3.11.

To install pharmr and Pharmpy:

remotes::install_github("pharmpy/pharmr", ref="main")
pharmr::install_pharmpy()

Sometimes it is necessary to specify which version of Python to use. To make reticulate use Python 3.9 in its environment, run the following:

Sys.setenv(RETICULATE_MINICONDA_PYTHON_VERSION="3.9")

Install from CRAN

pharmr is available on CRAN and can be installed with

install.packages("pharmr")
pharmr::install_pharmpy()

Note that pharmr and Pharmpy are under rapid development and the version on github will be a much more up to date version than the version on CRAN. Check the badges above to see the version numbers for CRAN and github.

Using pharmr

>>> library(pharmr)
>>> res <- read_modelfit_results("run1.mod")
>>> res$parameter_estimates
  THETA(1)   THETA(2)   THETA(3) OMEGA(1,1) OMEGA(2,2) SIGMA(1,1)
0.00469555 0.98425800 0.15892000 0.02935080 0.02790600 0.01324100
>>> model <- read_model("run1.mod")
>>> model$parameters
       name     value  lower    upper    fix
   THETA(1)  0.004693   0.00  1000000  False
   THETA(2)  1.009160   0.00  1000000  False
   THETA(3)  0.100000  -0.99  1000000  False
 OMEGA(1,1)  0.030963   0.00       oo  False
 OMEGA(2,2)  0.031128   0.00       oo  False
 SIGMA(1,1)  0.013086   0.00       oo  False
>>>

A simple example of reading a model, performing a simple transformation, and running the model in NONMEM:

model <- load_example_model('pheno') %>%
  add_peripheral_compartment() %>%
  fit()

Copy Link

Version

Install

install.packages('pharmr')

Monthly Downloads

366

Version

0.96.0

License

BSD_2_clause + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Rikard Nordgren

Last Published

June 15th, 2023

Functions in pharmr (0.96.0)

calculate_pk_parameters_statistics

calculate_pk_parameters_statistics
bump_model_number

bump_model_number
add_population_parameter

add_population_parameter
calculate_eta_gradient_expression

calculate_eta_gradient_expression
append_estimation_step_options

append_estimation_step_options
check_parameters_near_bounds

check_parameters_near_bounds
create_config_template

create_config_template
check_high_correlations

check_high_correlations
deidentify_data

deidentify_data
display_odes

display_odes
create_joint_distribution

create_joint_distribution
calculate_prec_from_cov

calculate_prec_from_cov
calculate_prec_from_corrse

calculate_prec_from_corrse
evaluate_expression

evaluate_expression
evaluate_individual_prediction

evaluate_individual_prediction
calculate_bic

calculate_bic
expand_additional_doses

expand_additional_doses
find_clearance_parameters

find_clearance_parameters
get_concentration_parameters_from_data

get_concentration_parameters_from_data
calculate_cov_from_prec

calculate_cov_from_prec
calculate_corr_from_cov

calculate_corr_from_cov
cleanup_model

cleanup_model
check_pharmpy

Checks version of Pharmpy/pharmr
fix_parameters_to

fix_parameters_to
find_volume_parameters

find_volume_parameters
get_baselines

get_baselines
calculate_epsilon_gradient_expression

calculate_epsilon_gradient_expression
get_config_path

get_config_path
calculate_eta_shrinkage

calculate_eta_shrinkage
get_model_code

get_model_code
get_sigmas

get_sigmas
get_thetas

get_thetas
get_mdv

get_mdv
calculate_ucp_scale

calculate_ucp_scale
calculate_individual_shrinkage

calculate_individual_shrinkage
calculate_individual_parameter_statistics

calculate_individual_parameter_statistics
check_dataset

check_dataset
drop_columns

drop_columns
drop_dropped_columns

drop_dropped_columns
calculate_se_from_cov

calculate_se_from_cov
calculate_se_from_prec

calculate_se_from_prec
has_zero_order_absorption

has_zero_order_absorption
make_declarative

make_declarative
create_rng

create_rng
has_weighted_error_model

has_weighted_error_model
create_symbol

create_symbol
get_doses

get_doses
get_dv_symbol

get_dv_symbol
evaluate_population_prediction

evaluate_population_prediction
get_evid

get_evid
mu_reference_model

mu_reference_model
has_linear_odes

has_linear_odes
has_first_order_elimination

has_first_order_elimination
get_pk_parameters

get_pk_parameters
get_omegas

get_omegas
get_covariate_baselines

get_covariate_baselines
get_doseid

get_doseid
convert_model

convert_model
create_basic_pk_model

create_basic_pk_model
has_odes

has_odes
evaluate_weighted_residuals

evaluate_weighted_residuals
print_model_symbols

print_model_symbols
remove_unused_parameters_and_rvs

remove_unused_parameters_and_rvs
get_ids

get_ids
create_report

create_report
has_mixed_mm_fo_elimination

has_mixed_mm_fo_elimination
print_model_code

print_model_code
rename_symbols

rename_symbols
fix_or_unfix_parameters

fix_or_unfix_parameters
fit

fit
retrieve_final_model

retrieve_final_model
retrieve_models

retrieve_models
fix_parameters

fix_parameters
is_real

is_real
get_observation_expression

get_observation_expression
get_individual_parameters

get_individual_parameters
get_model_covariates

get_model_covariates
create_results

create_results
evaluate_epsilon_gradient

evaluate_epsilon_gradient
print_pharmpy_version

Print pharmpy version
get_individual_prediction_expression

get_individual_prediction_expression
get_number_of_individuals

get_number_of_individuals
set_iiv_on_ruv

set_iiv_on_ruv
get_observations

get_observations
run_tool

run_tool
sample_individual_estimates

sample_individual_estimates
list_time_varying_covariates

list_time_varying_covariates
has_covariate_effect

has_covariate_effect
has_combined_error_model

has_combined_error_model
read_model_from_string

read_model_from_string
omit_data

omit_data
plot_individual_predictions

plot_individual_predictions
rank_models

rank_models
evaluate_eta_gradient

evaluate_eta_gradient
remove_estimation_step

remove_estimation_step
remove_iiv

remove_iiv
read_modelfit_results

read_modelfit_results
reset_indices_results

Reset result indices
get_number_of_observations

get_number_of_observations
get_bioavailability

get_bioavailability
get_lag_times

get_lag_times
get_initial_conditions

get_initial_conditions
get_cmt

get_cmt
get_number_of_observations_per_individual

get_number_of_observations_per_individual
set_initial_condition

set_initial_condition
set_zero_order_elimination

set_zero_order_elimination
sample_parameters_uniformly

sample_parameters_uniformly
sample_parameters_from_covariance_matrix

sample_parameters_from_covariance_matrix
set_mixed_mm_fo_elimination

set_mixed_mm_fo_elimination
set_michaelis_menten_elimination

set_michaelis_menten_elimination
has_random_effect

has_random_effect
get_unit_of

get_unit_of
get_zero_order_inputs

get_zero_order_inputs
has_proportional_error_model

has_proportional_error_model
undrop_columns

undrop_columns
simplify_expression

simplify_expression
unconstrain_parameters

unconstrain_parameters
solve_ode_system

solve_ode_system
set_zero_order_input

set_zero_order_input
has_linear_odes_with_real_eigenvalues

has_linear_odes_with_real_eigenvalues
predict_influential_outliers

predict_influential_outliers
predict_influential_individuals

predict_influential_individuals
read_dataset_from_datainfo

read_dataset_from_datainfo
write_model

write_model
write_results

write_results
read_model

read_model
use_thetas_for_error_stdev

use_thetas_for_error_stdev
write_csv

write_csv
remove_iov

remove_iov
run_iovsearch

run_iovsearch
run_modelfit

run_modelfit
set_dvid

set_dvid
set_proportional_error_model

set_proportional_error_model
set_dtbs_error_model

set_dtbs_error_model
set_seq_zo_fo_absorption

set_seq_zo_fo_absorption
remove_lag_time

remove_lag_time
split_joint_distribution

split_joint_distribution
transform_etas_tdist

transform_etas_tdist
summarize_errors

summarize_errors
translate_nmtran_time

translate_nmtran_time
update_initial_individual_estimates

update_initial_individual_estimates
get_population_prediction_expression

get_population_prediction_expression
has_zero_order_elimination

has_zero_order_elimination
get_rv_parameters

get_rv_parameters
greekify_model

greekify_model
has_additive_error_model

has_additive_error_model
load_example_model

load_example_model
install_pharmpy

Install Pharmpy
update_inits

update_inits
load_example_modelfit_results

load_example_modelfit_results
has_michaelis_menten_elimination

has_michaelis_menten_elimination
run_allometry

run_allometry
resume_tool

resume_tool
install_pharmpy_devel

Install Pharmpy (with specified version)
run_ruvsearch

run_ruvsearch
set_first_order_absorption

set_first_order_absorption
run_amd

run_amd
run_modelsearch

run_modelsearch
set_first_order_elimination

set_first_order_elimination
plot_iofv_vs_iofv

plot_iofv_vs_iofv
remove_loq_data

remove_loq_data
plot_transformed_eta_distributions

plot_transformed_eta_distributions
remove_peripheral_compartment

remove_peripheral_compartment
remove_covariate_effect

remove_covariate_effect
is_linearized

is_linearized
remove_error_model

remove_error_model
print_fit_summary

print_fit_summary
read_results

read_results
predict_outliers

predict_outliers
run_bootstrap

run_bootstrap
remove_covariance_step

remove_covariance_step
set_bolus_absorption

set_bolus_absorption
run_covsearch

run_covsearch
set_additive_error_model

set_additive_error_model
set_estimation_step

set_estimation_step
reset_index

Reset index
set_combined_error_model

set_combined_error_model
resample_data

resample_data
run_estmethod

run_estmethod
run_iivsearch

run_iivsearch
set_time_varying_error_model

set_time_varying_error_model
set_initial_estimates

set_initial_estimates
set_peripheral_compartments

set_peripheral_compartments
set_covariates

set_covariates
set_evaluation_step

set_evaluation_step
set_ode_solver

set_ode_solver
set_name

set_name
set_transit_compartments

set_transit_compartments
set_upper_bounds

set_upper_bounds
set_lower_bounds

set_lower_bounds
summarize_individuals

summarize_individuals
set_tmdd

set_tmdd
summarize_individuals_count_table

summarize_individuals_count_table
set_power_on_ruv

set_power_on_ruv
set_zero_order_absorption

set_zero_order_absorption
set_weighted_error_model

set_weighted_error_model
transform_etas_boxcox

transform_etas_boxcox
transform_blq

transform_blq
summarize_modelfit_results

summarize_modelfit_results
transform_etas_john_draper

transform_etas_john_draper
unfix_parameters_to

unfix_parameters_to
unfix_parameters

unfix_parameters
add_metabolite

add_metabolite
add_lag_time

add_lag_time
add_peripheral_compartment

add_peripheral_compartment
add_individual_parameter

add_individual_parameter
add_iov

add_iov
add_allometry

add_allometry
add_iiv

add_iiv
add_estimation_step

add_estimation_step
add_covariate_effect

add_covariate_effect
add_covariance_step

add_covariance_step
add_time_after_dose

add_time_after_dose
add_pk_iiv

add_pk_iiv
calculate_corr_from_prec

calculate_corr_from_prec
calculate_cov_from_corrse

calculate_cov_from_corrse
calculate_aic

calculate_aic
calculate_parameters_from_ucp

calculate_parameters_from_ucp