vvbond
April 2, 2024, 11:27am
1
My question is motivated by the need for a quick Deming regression computation.
In R, it is included in the mcr, Method Comparison Regression , package. Alas, my search for a Julia’s alternative wasn’t successful, despite Julia’s excellent statistics ecosystem.
I guess there is no real demand for it in the community. By what do you people do when you find yourself in need for something that exists in an R? Is using RCall, instead of porting a package, the preferred approach?
nilshg
April 2, 2024, 11:48am
2
Yes, I would say that’s right, at least for one-off usages. I’d say the hierarchy is:
Just use RCall to call R
Write a package which depends on RCall to wrap the R library, exposing a Julia API
Write a pure-Julia port of the R functionality
Sometimes 2 and 3 can go hand-in-hand, i.e. you could start with 2 and gradually replace some functionality with pure-Julia ports.
2 Likes
I did this a few years ago:
"""
Clouds months tends to have lower radiance due to attenuation. The bias_correction function uses the number of cloud-free observations to adjust the radiance accordingly.
```julia
bias_correction(radiance, clouds)
```
"""
function bias_correction(radiance::Array{T, 1}, clouds) where T <: Real
R"""
bias_correction_R <- function(radiance, clouds)
{
cf <- clouds/max(clouds)
ly1 <- radiance
time <- seq(1, length.out = length(radiance))
m.timetrend <- lm(ly1 ~ time, na.action = na.exclude)
ly2 <- residuals(m.timetrend) # ly2 is the residuals after removing the time trend
m <- loess(ly2 ~ cf, na.action = "na.exclude")
topval <- max(na.omit(predict(m)))#predict(m.loess, newdata=data.frame(cf=cutoff, ly2=NA))
corrected <- ly2 + topval - predict(m)
fixed.1 <- ly2
fixed.1 <- corrected
This file has been truncated. show original
I used RCall for functions that didn’t exist in Julia, then gradually replaced them with native code.
3 Likes
vvbond
April 2, 2024, 1:09pm
4
Thanks for the confirmation!