English 中文(简体)
在内部“欢迎(FUN=FUN,......)”时,我如何获得职能守则;具体来说,“分配”职能:qdouparetolognormal ......
原标题:How do I get code for a function when internally `mapply(FUN=FUN, ...)` is called; specifically the function `distributionsrd::qdoubleparetolognormal`
  • 时间:2024-04-18 02:06:14
  •  标签:
  • r

tldr;我想到用来计算distributionsrd的包装法>中双胎率的数学表述,功能qdouparetolognormal。 内部<代码>mapply(FUN=FUN,...) 正在被称作,我看不出任何数学或<代码>FUN

我已成功地利用了镜子包,以安装带有双向标志正常边缘的普通镜子(使用dparetolognormalpparetolognormal在<代码>分配rd包中的功能;我注意到我不得不稍微重新安排这些功能中的计算方法,以防止数字超支[组合成]。 在试图使用<代码>rMvdc生成随机数字时,我正在发现错误。

Error in uniroot(功能(q, 形状1, 形状2, 平均log, sdlog, p){: 1 000英亩/代码中未发现任何信号变化>

内部见<代码>r Mvdc是指qdouparetolognormal。 参看<代码>qdoubleparetolognormal 电话uniroot,因此我印刷了功能代码,并收到了。

> qdoubleparetolognormal
function (p, shape1 = 1.5, shape2 = 1.5, meanlog = -0.5, sdlog = 0.5, 
    lower.tail = TRUE, log.p = FALSE) 
{
    args <- lapply(as.list(match.call())[-1L], eval, parent.frame())
    names <- if (is.null(names(args))) 
        character(length(args))
    else names(args)
    dovec <- names %in% vectorize.args
    do.call("mapply", c(FUN = FUN, args[dovec], MoreArgs = list(args[!dovec]), 
        SIMPLIFY = SIMPLIFY, USE.NAMES = USE.NAMES))
}
<bytecode: 0x00000224fdf267f0>
<environment: 0x00000224fdf1f460>

I was wondering what FUN=FUN is doing, because there is no variable called FUN in the workspace. So looked into the mapply documentation:

FUN     function to apply, found via match.fun.

我的猜测是,FUN=FUN使用match.fun( , 电话:qdouparetolognormal? 但是,我对如何使内部法典qdoubleparetolognormal在本最后步骤中使用(在<代码>match.fun(<>之后)感到困惑。 我如何掌握实际数字的功能定义?

问题回答

I do not know what you are trying to accomplish. The mapply function is just there for vectorization. It has nothing to do with solving the problem. Here is a function that accomplishes what you want:

my_qdoubleparetolognormal1 <- function (p, shape1 = 1.5, shape2 = 1.5, meanlog = -0.5, sdlog = 0.5, 
          lower.tail = TRUE, log.p = FALSE){
  p <- if(log.p) exp(p) else p
  p <- if (lower.tail) p else  1 - p
  fn <- (q) pdoubleparetolognormal(q, shape1, shape2, meanlog, sdlog) - p
  uniroot(fn, interval = c(1e-06, 1), extendInt = "yes")$root
}

注:上述职能有时会发出延伸=是的警告。

my_qdoubleparetolognormal1(0.1)
[1] 0.1723352
qdoubleparetolognormal(0.1) # one from the package
[1] 0.1723352

该功能并非以矢量表示。 因此,它们使用<代码>mapply实现病媒化。 我们将使用<条码>。

my_qdoubleparetolognormal_vec <- function (p, shape1 = 1.5, shape2 = 1.5, meanlog = -0.5, sdlog = 0.5, 
                                           lower.tail = TRUE, log.p = FALSE){
  
  mapply(my_qdoubleparetolognormal1, p, shape1, shape2, meanlog, sdlog, lower.tail, log.p)
}

将职能与内在职能进行比较:

x <- seq(0.1,0.9,0.1)
my_qdoubleparetolognormal_vec(x)
[1] 0.1723352 0.2783234 0.3781708 0.4841963 0.6065086 0.7598161 0.9727864 1.3217682 2.1345231

qdoubleparetolognormal(x)
[1] 0.1723352 0.2783234 0.3781708 0.4841963 0.6065086 0.7598161 0.9727864 1.3217682 2.1345231
 




相关问题
How to plot fitted model over observed time series

This is a really really simple question to which I seem to be entirely unable to get a solution. I would like to do a scatter plot of an observed time series in R, and over this I want to plot the ...

REvolution for R

since the latest Ubuntu release (karmic koala), I noticed that the internal R package advertises on start-up the REvolution package. It seems to be a library collection for high-performance matrix ...

R - capturing elements of R output into text files

I am trying to run an analysis by invoking R through the command line as follows: R --no-save < SampleProgram.R > SampleProgram.opt For example, consider the simple R program below: mydata =...

R statistical package: wrapping GOFrame objects

I m trying to generate GOFrame objects to generate a gene ontology mapping in R for unsupported organisms (see http://www.bioconductor.org/packages/release/bioc/vignettes/GOstats/inst/doc/...

Changing the order of dodged bars in ggplot2 barplot

I have a dataframe df.all and I m plotting it in a bar plot with ggplot2 using the code below. I d like to make it so that the order of the dodged bars is flipped. That is, so that the bars labeled "...

Strange error when using sparse matrices and glmnet

I m getting a weird error when training a glmnet regression. invalid class "dgCMatrix" object: length(Dimnames[[2]]) must match Dim[2] It only happens occasionally, and perhaps only under larger ...

Generating non-duplicate combination pairs in R

Sorry for the non-descriptive title but I don t know whether there s a word for what I m trying to achieve. Let s assume that I have a list of names of different classes like c( 1 , 2 , 3 , 4 ) ...

Per panel smoothing in ggplot2

I m plotting a group of curves, using facet in ggplot2. I d like to have a smoother applied to plots where there are enough points to smooth, but not on plots with very few points. In particular I d ...

热门标签