Function to calculate product density
calebepiacentini opened this issue · 6 comments
Hello!
A function to calculate product density could very easily be added to the package by, mimicking the distance function, writing:
density <- function(balassa_index, proximity_product) {
# sanity checks ----
if (!(any(class(balassa_index) %in% "dgCMatrix") == TRUE)) {
stop("'balassa_index' must be a dgCMatrix")
}
if (!(any(class(proximity_product) %in% "dsCMatrix") == TRUE)) {
stop("'proximity_product' must be a dgCMatrix")
}
return(
tcrossprod(balassa_index, proximity_product / rowSums(proximity_product))
)
}
The only difference is that, instead of 1-balassa_index
, we use balassa_index
.
Density measures are commonly used in the literature. See for example Balland et al. (2019).
Obs.: I tried it locally and it worked only after I specified Matrix::tcrossproduct()
and Matrix:rowSums()
hi @calebepiacentini
so sorry for the delay, I haven't touched the package in years
when I have free time, can I use the code you propose? I'll add some @importFrom and that's it
hi @pachadotdev, no problem at all!
Of course, feel free to use it
@calebepiacentini I wrote my own function, thanks
you can install the development version from this repository
@calebepiacentini if i understood correctly, this function is an overkill, we could just do 1 - distance
Hello, @pachadotdev! yes, you're correct! My solution is totally an overkill hahahaha. I'm sorry :(
Nevertheless, this point out that separating it as a function, or even an option to the distance function, may make the code easier to use.
@calebepiacentini sorry for the delay, I implemented it as 1 - distance and the density function is now exported and available for the end user (now = 30 days ago, it took me long to read your confirmation on the 1 - distance)