Closed AustinFournierKL closed 1 year ago
On further review of the results, it looks to me like maybe the issue here is that I implemented the AFT in such a way that I have to take the negative of the coefficient flexsurvreg estimates to get the correct coefficient for my equation. Can you tell if that's correct?
There's a lot of detail in your post, so it's hard to tell instantly, but that's probably what is happening. The model that flexsurvreg fits here is fully specified in https://cran.r-project.org/web/packages/flexsurv/vignettes/distributions.pdf so you could cross-check with that.
Okay, the difference between my final equation and yours was more or less as I expected. On that note, what I wrote above was in error on one point; for my equation to be correct, c would be the negative of the sum of all covariates times their coefficients; I seem to have dropped the negative at some point. The resulting equation was still an AFT, but parameterized slightly differently than originally intended, and thus different from what flexsurv assumed.
Hello,
I'm attempting to fit an AFT Weibull model with flexsurvreg, which, if I understand from the help page on the function, should be the default model that the function fits when you specify that you want a Weibull regression. I managed to figure out the CDF for a Weibull AFT, take its inverse, and simulate data from it. However, when I use flexsurvreg on my simulated data, it does not appear to be correctly estimating the coefficient on my covariate (shape and scale estimates, on the other hand, seem quite accurate).
That said, I am not sure whether I am perhaps making a mistake with the model fitting procedure, or perhaps misinterpreting the outfit window. My code was as follows:
Here, the final model I got returned:
So the estimate for the coefficient on on covsamp would seem to be -0.5853, and when exponentiated it comes out to ~.557. In contrast, I was expecting a coefficient of ~.69, which would come out to around 2 when exponentiated. What could be going on here?
In case this part of my code is suspect, I will note that the CDF on which I based my random sampling was:
1 - exp(-(((t^shape)*(exp(c*shape)))/scale**shape))
In the above equation, shape and scale are exactly what they say on the label, t is time, and c is the sum of all covariates times their coefficients. I tested and confirmed that if c = log(2), this expression will return the same probability as the function below, at half the value of t:pweibull(t, shape = shape, scale = scale)
Likewise, if I set c to log(3), it would gave the same results at one third the value of t.With this confirmed I took the inverse function:
(((-scale^shape)*log(1-prob))/(exp(c*shape)))^(1/shape)
In the above, prob is the input to the function; I tested and confirmed that it would give me back the correct value of t when I put in the output from CDF shown above.