{"action":"opened","issue":{"url":"https://api.github.com/repos/chjackson/flexsurv-dev/issues/6","labels_url":"https://api.github.com/repos/chjackson/flexsurv-dev/issues/6/labels{/name}","comments_url":"https://api.github.com/repos/chjackson/flexsurv-dev/issues/6/comments","events_url":"https://api.github.com/repos/chjackson/flexsurv-dev/issues/6/events","html_url":"https://github.com/chjackson/flexsurv-dev/issues/6","id":109298621,"number":6,"title":"Subsetting in flexsurvspline","user":{"login":"WetRobot","id":11218767,"avatar_url":"https://avatars.githubusercontent.com/u/11218767?v=3","gravatar_id":"","url":"https://api.github.com/users/WetRobot","html_url":"https://github.com/WetRobot","followers_url":"https://api.github.com/users/WetRobot/followers","following_url":"https://api.github.com/users/WetRobot/following{/other_user}","gists_url":"https://api.github.com/users/WetRobot/gists{/gist_id}","starred_url":"https://api.github.com/users/WetRobot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/WetRobot/subscriptions","organizations_url":"https://api.github.com/users/WetRobot/orgs","repos_url":"https://api.github.com/users/WetRobot/repos","events_url":"https://api.github.com/users/WetRobot/events{/privacy}","received_events_url":"https://api.github.com/users/WetRobot/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-10-01T13:26:29Z","updated_at":"2015-10-01T13:26:29Z","closed_at":null,"body":"Hi,\r\n\r\nI've run into some minor issues / room for minor enhancements using `flexsurvspline`. Namely, subsetting requires the user to point to the appropriate data set when subsetting instead of the usual behaviour when using e.g. `coxph`. Additionally, a subset that leads to zero rows in an ad-hoc created factor variable crashes `flexsurvspline`.\r\n\r\n* works fine without subsetting\r\n```r\r\n> flex <- flexsurvspline(Surv(time = time, event = status) ~ sex + cut(age, 4), \r\n                                          data = survival::lung)\r\n```\r\n\r\n* subsetting in `coxph` \r\n```r\r\n> cp <- coxph(Surv(time = time, event = status) ~ sex + cut(age, 4), \r\n                      data = survival::lung, \r\n                      subset = !is.na(wt.loss))\r\n```\r\n\r\n* subsetting with `flexsurvspline` \r\n```r\r\n> subflex <- flexsurvspline(Surv(time = time, event = status) ~ sex + cut(age, 4), \r\n                                          data = survival::lung,\r\n                                          subset = !is.na(wt.loss))\r\nError in flexsurvspline(Surv(time = time, event = status) ~ sex + cut(age,  : \r\n  object 'wt.loss' not found\r\n```\r\n* this works\r\n```r\r\n> subflex <- flexsurvspline(Surv(time = time, event = status) ~ sex + cut(age, 4), \r\n                                          data = survival::lung, \r\n                                          subset = !is.na(survival::lung$wt.loss))\r\n```\r\n\r\n* ad-hoc factor with empty levels\r\n```r\r\n> subflex <- flexsurvspline(Surv(time = time, event = status) ~ sex + cut(age, 4), \r\n                                          data = survival::lung, \r\n                                          subset = survival::lung$age > 60)\r\nError in optim(method = \"BFGS\", par = c(-6.03077305549557, 1.06257724751466,  : \r\n  non-finite value supplied by optim\r\nIn addition: Warning message:\r\nIn coxph(as.formula(form), weights = wt) :\r\n  X matrix deemed to be singular; variable 2 4\r\n```\r\n\r\nThese are minor issues, but I only realized after a day or two to refer to the data set explicitly. Also, in my view, an ad-hoc created factor such as `cut(age, 4)` in the example should possibly only be evaluated on the subsetted data set?\r\n\r\nThank you for the great package by the way, it works very well in general.\r\n"}}