Learn R Programming

pharmr is an R wrapper to Pharmpy: an open-source software package for pharmacometric modeling. It provides an R interface to all functions found in the modeling and tools modules (documented here). The documentation for each function is also available via the help-function (or ?).

For comprehensive information and documentation, see: https://pharmpy.github.io

Installation and setup

Install from CRAN

The latest stable version of pharmr is available via CRAN, and can be installed via:

install.packages("pharmr")

After installing pharmr, Pharmpy needs to be set up:

pharmr::install_pharmpy()

For a more comprehensive description of the process of setting up, see the following guide.

Install from GitHub

It is also possible to install the development version of pharmr from GitHub, with the following command:

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

Pharmpy can then be installed:

pharmr::install_pharmpy()

Using pharmr

>>> library(pharmr)
>>> model <- load_example_model("pheno")
>>> model$parameters
            value  lower upper    fix
POP_CL   0.004693   0.00     ∞  False
POP_VC   1.009160   0.00     ∞  False
COVAPGR  0.100000  -0.99     ∞  False
IIV_CL   0.030963   0.00     ∞  False
IIV_VC   0.031128   0.00     ∞  False
SIGMA    0.013086   0.00     ∞  False
>>> res <- load_example_modelfit_results("pheno")
>>> res$parameter_estimates
    POP_CL     POP_VC    COVAPGR     IIV_CL     IIV_VC      SIGMA 
0.00469555 0.98425800 0.15892000 0.02935080 0.02790600 0.01324100 
>>>

A simple example of reading a model, performing a simple transformation, and running the model in NONMEM. Note that you need NONMEM installed to be able to fit the model, see the following guide on how to set up the config file.

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

Copy Link

Version

Install

install.packages('pharmr')

Monthly Downloads

246

Version

1.4.0

License

LGPL (>= 3)

Issues

Pull Requests

Stars

Forks

Maintainer

Rikard Nordgren

Last Published

December 4th, 2024

Functions in pharmr (1.4.0)

add_iov

add_iov
add_lag_time

add_lag_time
add_predictions

add_predictions
add_peripheral_compartment

add_peripheral_compartment
add_metabolite

add_metabolite
add_population_parameter

add_population_parameter
add_individual_parameter

add_individual_parameter
add_parameter_uncertainty_step

add_parameter_uncertainty_step
add_pd_iiv

add_pd_iiv
add_pk_iiv

add_pk_iiv
calculate_bic

calculate_bic
add_residuals

add_residuals
calculate_cov_from_corrse

calculate_cov_from_corrse
calculate_corr_from_prec

calculate_corr_from_prec
add_time_after_dose

add_time_after_dose
bump_model_number

bump_model_number
calculate_pk_parameters_statistics

calculate_pk_parameters_statistics
calculate_parameters_from_ucp

calculate_parameters_from_ucp
calculate_aic

calculate_aic
bin_observations

bin_observations
calculate_eta_shrinkage

calculate_eta_shrinkage
calculate_cov_from_prec

calculate_cov_from_prec
append_estimation_step_options

append_estimation_step_options
calculate_individual_shrinkage

calculate_individual_shrinkage
calculate_individual_parameter_statistics

calculate_individual_parameter_statistics
calculate_corr_from_cov

calculate_corr_from_cov
calculate_eta_gradient_expression

calculate_eta_gradient_expression
calculate_epsilon_gradient_expression

calculate_epsilon_gradient_expression
calculate_prec_from_corrse

calculate_prec_from_corrse
convert_model

convert_model
check_pharmpy

Checks version of Pharmpy/pharmr
cleanup_model

cleanup_model
calculate_prec_from_cov

calculate_prec_from_cov
create_basic_pk_model

create_basic_pk_model
check_high_correlations

check_high_correlations
check_parameters_near_bounds

check_parameters_near_bounds
calculate_se_from_cov

calculate_se_from_cov
check_dataset

check_dataset
calculate_se_from_prec

calculate_se_from_prec
calculate_ucp_scale

calculate_ucp_scale
drop_dropped_columns

drop_dropped_columns
drop_columns

drop_columns
deidentify_data

deidentify_data
create_rng

create_rng
display_odes

display_odes
evaluate_expression

evaluate_expression
create_joint_distribution

create_joint_distribution
find_volume_parameters

find_volume_parameters
find_clearance_parameters

find_clearance_parameters
evaluate_individual_prediction

evaluate_individual_prediction
create_report

create_report
evaluate_population_prediction

evaluate_population_prediction
evaluate_weighted_residuals

evaluate_weighted_residuals
create_symbol

create_symbol
fix_parameters

fix_parameters
create_context

create_context
get_bioavailability

get_bioavailability
get_individual_prediction_expression

get_individual_prediction_expression
get_central_volume_and_clearance

get_central_volume_and_clearance
fit

fit
fix_parameters_to

fix_parameters_to
create_config_template

create_config_template
fix_or_unfix_parameters

fix_or_unfix_parameters
get_individual_parameters

get_individual_parameters
get_doseid

get_doseid
get_concentration_parameters_from_data

get_concentration_parameters_from_data
get_covariate_baselines

get_covariate_baselines
get_cmt

get_cmt
expand_additional_doses

expand_additional_doses
get_covariate_effects

get_covariate_effects
evaluate_eta_gradient

evaluate_eta_gradient
filter_dataset

filter_dataset
get_config_path

get_config_path
get_admid

get_admid
evaluate_epsilon_gradient

evaluate_epsilon_gradient
get_dv_symbol

get_dv_symbol
get_baselines

get_baselines
get_doses

get_doses
get_ids

get_ids
get_number_of_observations

get_number_of_observations
get_model_code

get_model_code
get_rv_parameters

get_rv_parameters
get_evid

get_evid
get_number_of_individuals

get_number_of_individuals
get_model_covariates

get_model_covariates
get_mdv

get_mdv
get_pd_parameters

get_pd_parameters
get_sigmas

get_sigmas
get_number_of_observations_per_individual

get_number_of_observations_per_individual
get_parameter_rv

get_parameter_rv
get_mu_connected_to_parameter

get_mu_connected_to_parameter
get_lag_times

get_lag_times
get_observations

get_observations
get_initial_conditions

get_initial_conditions
get_population_prediction_expression

get_population_prediction_expression
has_combined_error_model

has_combined_error_model
get_pk_parameters

get_pk_parameters
has_covariate_effect

has_covariate_effect
has_additive_error_model

has_additive_error_model
get_number_of_transit_compartments

get_number_of_transit_compartments
get_observation_expression

get_observation_expression
get_number_of_peripheral_compartments

get_number_of_peripheral_compartments
has_first_order_absorption

has_first_order_absorption
get_omegas

get_omegas
has_linear_odes

has_linear_odes
get_thetas

get_thetas
has_first_order_elimination

has_first_order_elimination
has_instantaneous_absorption

has_instantaneous_absorption
has_michaelis_menten_elimination

has_michaelis_menten_elimination
get_unit_of

get_unit_of
has_mu_reference

has_mu_reference
has_odes

has_odes
has_linear_odes_with_real_eigenvalues

has_linear_odes_with_real_eigenvalues
has_presystemic_metabolite

has_presystemic_metabolite
list_time_varying_covariates

list_time_varying_covariates
has_proportional_error_model

has_proportional_error_model
load_dataset

load_dataset
has_random_effect

has_random_effect
get_zero_order_inputs

get_zero_order_inputs
install_pharmpy

Install Pharmpy
has_mixed_mm_fo_elimination

has_mixed_mm_fo_elimination
has_zero_order_elimination

has_zero_order_elimination
greekify_model

greekify_model
has_seq_zo_fo_absorption

has_seq_zo_fo_absorption
is_real

is_real
is_strictness_fulfilled

is_strictness_fulfilled
has_weighted_error_model

has_weighted_error_model
make_declarative

make_declarative
is_linearized

is_linearized
install_pharmpy_devel

Install Pharmpy (with specified version)
plot_dv_vs_pred

plot_dv_vs_pred
plot_eta_distributions

plot_eta_distributions
mu_reference_model

mu_reference_model
plot_dv_vs_ipred

plot_dv_vs_ipred
plot_cwres_vs_idv

plot_cwres_vs_idv
load_example_modelfit_results

load_example_modelfit_results
load_example_model

load_example_model
print_log

print_log
has_zero_order_absorption

has_zero_order_absorption
predict_outliers

predict_outliers
print_fit_summary

print_fit_summary
plot_iofv_vs_iofv

plot_iofv_vs_iofv
plot_individual_predictions

plot_individual_predictions
print_model_code

print_model_code
remove_covariate_effect

remove_covariate_effect
predict_influential_individuals

predict_influential_individuals
remove_derivative

remove_derivative
predict_influential_outliers

predict_influential_outliers
print_pharmpy_version

Print pharmpy version
print_model_symbols

print_model_symbols
read_model

read_model
read_dataset_from_datainfo

read_dataset_from_datainfo
read_model_from_string

read_model_from_string
omit_data

omit_data
plot_transformed_eta_distributions

plot_transformed_eta_distributions
plot_abs_cwres_vs_ipred

plot_abs_cwres_vs_ipred
read_modelfit_results

read_modelfit_results
plot_vpc

plot_vpc
read_results

read_results
remove_parameter_uncertainty_step

remove_parameter_uncertainty_step
remove_peripheral_compartment

remove_peripheral_compartment
remove_bioavailability

remove_bioavailability
remove_estimation_step

remove_estimation_step
remove_predictions

remove_predictions
remove_loq_data

remove_loq_data
remove_residuals

remove_residuals
remove_error_model

remove_error_model
remove_lag_time

remove_lag_time
resample_data

resample_data
remove_unused_parameters_and_rvs

remove_unused_parameters_and_rvs
replace_fixed_thetas

replace_fixed_thetas
retrieve_model

retrieve_model
reset_indices_results

Reset result indices
retrieve_models

retrieve_models
retrieve_modelfit_results

retrieve_modelfit_results
remove_iiv

remove_iiv
remove_iov

remove_iov
replace_non_random_rvs

replace_non_random_rvs
rename_symbols

rename_symbols
run_estmethod

run_estmethod
run_allometry

run_allometry
run_bootstrap

run_bootstrap
run_iovsearch

run_iovsearch
reset_index

Reset index
run_amd

run_amd
run_linearize

run_linearize
run_modelfit

run_modelfit
run_modelsearch

run_modelsearch
sample_parameters_from_covariance_matrix

sample_parameters_from_covariance_matrix
run_iivsearch

run_iivsearch
set_baseline_effect

set_baseline_effect
sample_individual_estimates

sample_individual_estimates
sample_parameters_uniformly

sample_parameters_uniformly
run_tool

run_tool
set_additive_error_model

set_additive_error_model
run_retries

run_retries
run_ruvsearch

run_ruvsearch
set_dvid

set_dvid
set_direct_effect

set_direct_effect
set_combined_error_model

set_combined_error_model
set_dtbs_error_model

set_dtbs_error_model
set_dataset

set_dataset
set_covariates

set_covariates
set_estimation_step

set_estimation_step
set_description

set_description
run_structsearch

run_structsearch
run_covsearch

run_covsearch
run_simulation

run_simulation
set_first_order_absorption

set_first_order_absorption
set_lower_bounds

set_lower_bounds
set_evaluation_step

set_evaluation_step
set_instantaneous_absorption

set_instantaneous_absorption
set_lloq_data

set_lloq_data
set_mixed_mm_fo_elimination

set_mixed_mm_fo_elimination
set_name

set_name
set_first_order_elimination

set_first_order_elimination
set_iiv_on_ruv

set_iiv_on_ruv
set_initial_condition

set_initial_condition
set_michaelis_menten_elimination

set_michaelis_menten_elimination
set_initial_estimates

set_initial_estimates
set_tmdd

set_tmdd
set_reference_values

set_reference_values
set_proportional_error_model

set_proportional_error_model
set_ode_solver

set_ode_solver
set_seq_zo_fo_absorption

set_seq_zo_fo_absorption
set_peripheral_compartments

set_peripheral_compartments
set_simulation

set_simulation
set_time_varying_error_model

set_time_varying_error_model
set_transit_compartments

set_transit_compartments
set_power_on_ruv

set_power_on_ruv
solve_ode_system

solve_ode_system
summarize_modelfit_results

summarize_modelfit_results
set_upper_bounds

set_upper_bounds
set_zero_order_elimination

set_zero_order_elimination
transform_blq

transform_blq
simplify_expression

simplify_expression
split_joint_distribution

split_joint_distribution
set_weighted_error_model

set_weighted_error_model
set_zero_order_input

set_zero_order_input
set_zero_order_absorption

set_zero_order_absorption
transform_etas_john_draper

transform_etas_john_draper
transform_etas_boxcox

transform_etas_boxcox
unload_dataset

unload_dataset
undrop_columns

undrop_columns
unconstrain_parameters

unconstrain_parameters
translate_nmtran_time

translate_nmtran_time
transform_etas_tdist

transform_etas_tdist
unfix_parameters

unfix_parameters
use_thetas_for_error_stdev

use_thetas_for_error_stdev
write_results

write_results
update_initial_individual_estimates

update_initial_individual_estimates
write_csv

write_csv
unfix_parameters_to

unfix_parameters_to
write_model

write_model
add_admid

add_admid
add_derivative

add_derivative
add_covariate_effect

add_covariate_effect
add_allometry

add_allometry
add_bioavailability

add_bioavailability
add_iiv

add_iiv
add_effect_compartment

add_effect_compartment
add_indirect_effect

add_indirect_effect
add_estimation_step

add_estimation_step
add_cmt

add_cmt