Coder Social home page Coder Social logo

lme4cens's Introduction

lme4cens: Simple Linear Mixed Effect Models and Censoring

DOI

The R-package lme4cens builds on lme4 to fit simple random effects models with a censored response. It re-uses the formula-module from lme4 to facilitate model specification. The censoring information is encoded via survival's Surv-object that allows for a flexible specification of (a combination of) left-, right- and interval-censored responses with flexible censoring levels per observation.

The random effect structure is currently limited to the most simple case, namely models with a single random intercept. Model fitting is via maximum likelihood (ML), residual maximum likelihood (REML) is not supported.

A good choice of starting values is helpful, although there is a heuristic in place if none are given. The fitted parameter values may depend on the choice of starting values. As with all non-trivial optimization problems it is good practice to check convergence with different start values. Ideally, you would also confirm that the model fit remains the roughly the same when using different optimization routines (see the control= parameter for function lmercens).

Installation

This package is currently only available via Github. To install from within R use the following command:

remotes::install_github("lenz99/lme4cens")

lme4cens's People

Contributors

amackeyitx avatar lenz99 avatar moosterwegel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

lme4cens's Issues

`ranef` not working when you specify no fixed effects

Minimal reproducible example (MSE):

library(lme4cens)

fm.lmercens <- lmercens(Surv(Reaction3, time2 = Reaction3, event = event3, type = "interval") ~ Days + (1|Subject),
                        data = sleepstudy2, REML = FALSE,
                        control = lmerControl(optimizer = "optimx", optCtrl = list(method = "L-BFGS-B"), boundary.tol = 0))

fm.lmercens_no_fe <- lmercens(Surv(Reaction3, time2 = Reaction3, event = event3, type = "interval") ~ (1|Subject),
                              data = sleepstudy2, REML = FALSE,
                              control = lmerControl(optimizer = "optimx", optCtrl = list(method = "L-BFGS-B"), boundary.tol = 0))

ranef(fm.lmercens)
ranef(fm.lmercens_no_fe) # doesn't work

predict(fm.lmercens)
predict(fm.lmercens_no_fe) # as a result, predict doesn't work either

The random effect extraction doesn't work for models with only an intercept as fixed effect, because the fixed effects matrix is reduced to an 1x1 variable matrix and consequently the matrix multiplication inside ranef doesn't work.

I got a fix ready I think, will make a pull request shortly.

Error on install

Hi there,

I just found a poster on this package when looking for methods for censored linear mixed effects regression. It looks like this package will help me with my client's research question.

I tried installing your package with

remotes::install_github("https://github.com/lenz99-/lme4cens")

But got the following error:

Error: package or namespace load failed for 'lme4cens' in namespaceExport(ns, exports):
undefined exports: lmsegm, lmsegm.objFun
Error: loading failed

> sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 8.1 x64 (build 9600)

Matrix products: default

locale:
[1] LC_COLLATE=English_Australia.1252  LC_CTYPE=English_Australia.1252   
[3] LC_MONETARY=English_Australia.1252 LC_NUMERIC=C                      
[5] LC_TIME=English_Australia.1252    

attached base packages:
[1] graphics  grDevices utils     datasets  stats     methods   base     

other attached packages:
 [1] repmis_0.5            ProjectTemplate_0.9.0 lubridate_1.7.4       forcats_0.4.0        
 [5] stringr_1.4.0         dplyr_0.8.3           purrr_0.3.2           readr_1.3.1          
 [9] tidyr_1.0.0           tibble_2.1.3          ggplot2_3.2.1         tidyverse_1.2.1      
[13] plyr_1.8.4            reshape2_1.4.3       

loaded via a namespace (and not attached):
 [1] tidyselect_0.2.5  remotes_2.1.0     haven_2.1.1       lattice_0.20-38   colorspace_1.4-1 
 [6] vctrs_0.2.0       generics_0.0.2    pkgbuild_1.0.5    rlang_0.4.0       R.oo_1.22.0      
[11] pillar_1.4.2      glue_1.3.1        withr_2.1.2       R.utils_2.9.0     modelr_0.1.5     
[16] readxl_1.3.1      lifecycle_0.1.0   R.cache_0.13.0    munsell_0.5.0     gtable_0.3.0     
[21] cellranger_1.1.0  rvest_0.3.4       R.methodsS3_1.7.1 callr_3.3.2       ps_1.3.0         
[26] curl_4.2          broom_0.5.2       Rcpp_1.0.2        scales_1.0.0      backports_1.1.5  
[31] jsonlite_1.6      hms_0.5.1         digest_0.6.21     packrat_0.5.0     stringi_1.4.3    
[36] processx_3.4.1    rprojroot_1.3-2   grid_3.6.1        cli_1.1.0         tools_3.6.1      
[41] magrittr_1.5      lazyeval_0.2.2    crayon_1.3.4      pkgconfig_2.0.3   zeallot_0.1.0    
[46] prettyunits_1.0.2 data.table_1.12.2 xml2_1.2.2        assertthat_0.2.1  httr_1.4.1       
[51] rstudioapi_0.10   R6_2.4.0          nlme_3.1-141      compiler_3.6.1   

Error when running lmercens

Hi there,

I found your package from useR! 2017 poster. I'm able to install the package. I downloaded the whole folder from your github and try to run this example_lmm_cens.Rmd file on my local drive. However, when I run this line code:

fm.lmercens <- lmercens(Surv(Reaction3, time2 = Reaction3, event = event3, type = "interval") ~ Days + (1|Subject),
                        data = sleepstudy2, REML = FALSE,
                        control = lmerControl(optimizer = "optimx", optCtrl = list(method = "L-BFGS-B"), boundary.tol = 0),
                        start = paramSL)

I got the error saying as follow

 Error in optimx.check(par, optcfg$ufn, optcfg$ugr, optcfg$uhess, lower,  : 
  Cannot evaluate function at initial parameters

Could you please help me to identify what goes wrong here? I run as well the paramSL where you defined your starting values.
Thank you beforehand.

Dea

Pairwise Comparisons Alike Emmeans with Lmercens

Matthias,

I would like to implement a post hoc pairwise comparison output on a lmercens object like one can perform following a lme4 model output with emmeans ( ) + pair ( ), or simply anova ( ) to extract global F values for categorical fixed effects.

For example:

with lme4, I can do the following (testosterone is a left censored response variable below, and thus want to utilize lmercens as I do below with lme4). Pit is a unique individual identifier that needs to be accounted for with random effects. Outcome and period are both categorical variables (outcome: n = 3), (period: n = 4).

lmer_t <- lmer(testosterone ~ period * outcome + (1|pit), data = parent_t0, REML = FALSE)
summary(lmer_t) #for model output

THEN --
anova(lmer_t) #to get global F values for period and outcome (both categorical variables)
pairwise<-emmeans(lmer_t,"outcome","period")
pairs(pairwise) #to extract pairwise comparisons between outcome, nested within the group of period

With the lmercens object, I can't perform these anova ( ) or emmeans / pairs pairwise comparisons.

Is there a way to perform pairwise comparisons with a lmercens model with multiple categorical variables that are nested within each other, alike one would perform with emmeans?

Many thanks for any insights you might be able to provide !

Brian Case
PhD Candidate
Virginia Tech
Blacksburg, VA USA

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.