Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Computing residuals when scaling is logarithmic #1087

Open
IndrajeetPatil opened this issue Aug 16, 2022 · 10 comments
Open

Computing residuals when scaling is logarithmic #1087

IndrajeetPatil opened this issue Aug 16, 2022 · 10 comments
Assignees

Comments

@IndrajeetPatil
Copy link
Member

log(x) is ln(x) in R, right?
Seems wrong to me, I would expect log10(predicted)-log10(observed) and not ln(predicted)-ln(observed)???

Originally posted by @Yuri05 in #1085 (comment)

Referring to the code here:

if (scaling %in% c(tlf::Scaling$lin, "identity")) {
pairedData <- dplyr::mutate(pairedData, residualValues = predictedValues - yValues)
} else {
pairedData <- dplyr::mutate(pairedData, residualValues = log(predictedValues) - log(yValues))
}

@IndrajeetPatil
Copy link
Member Author

This was done to stay faithful to what is done in the reporting engine:

https://github.com/Open-Systems-Pharmacology/OSPSuite.ReportingEngine/blob/3a3aa9ac469643a0a50db34ca4b4aafdeae71250/R/utilities-goodness-of-fit.R#L189-L194

But, yes, you are correct that log(x) in R is log(x, exp(1)), i.e. ln(x). Therefore, the correct way to do this would be using log10().

@Yuri05
Copy link
Member

Yuri05 commented Aug 16, 2022

@sfrechen @PavelBal Is calculating of logarithmic residuals using ln (and not log10) in RE correct?

@sfrechen
Copy link
Member

Natural logarithm is correct. The residuals should follow then a lognormal distribution.

@PavelBal
Copy link
Member

Then the PK-Sim implementation is not correct?

@sfrechen
Copy link
Member

Let's say: uncommon. And not directly comparable to a lognormal distribution.

@Yuri05
Copy link
Member

Yuri05 commented Aug 16, 2022

Let's say: uncommon. And not directly comparable to a lognormal distribution.

Then I wonder, why in the "Histogram of residuals" in RE we plot normal distribution all the time??? @sfrechen

@sfrechen
Copy link
Member

sfrechen commented Aug 17, 2022

Then I wonder, why in the "Histogram of residuals" in RE we plot normal distribution all the time???

Well, if the assumed error model is logarithmic, i.e. epsilon follows log normal distribution (which is usually the case), then plotting the logarithmized residuals against a normal distribution is correct (because log(residual) follows then a normal distribution while residual follows a log normal distribution)

If the assumed error model is linear, i.e. epsilon follows normal distribution, then plotting the "raw" residuals against normal distribution is also correct.

Whether the residuals are logarithmized or not should depend on the underlying assumption of the error model!

@sfrechen sfrechen reopened this Aug 17, 2022
@Yuri05
Copy link
Member

Yuri05 commented Aug 17, 2022

a) We don't plot log(residual) in the histogram. We plot residual.
b) Actually, the residuals can be negative. How can they be lognormal distributed then???

@sfrechen
Copy link
Member

a) We don't plot log(residual) in the histogram. We plot residual.

Hm. As said: Whether the residuals are logarithmized or not should depend on the underlying assumption of the error model, i.e. if the parameter identification is done in log scale for an output, then the residuals should be calculated as res = log(obs)-log(sim).

b) Actually, the residuals can be negative. How can they be lognormal distributed then???

Sorry, I was not accurate:

If the assumed error model is logarithmic, i.e. log(y)=log(f)+eps and epsilon follows a normal distribution, thus exp(epsilon) follows log normal distribution, then plotting the logarithmized residuals against a normal distribution is correct.

@PavelBal
Copy link
Member

Do we have an agreement?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants