我正在尝试对表中的数据进行反向转换。但我不能让它工作。有人知道为什么吗?我想要对整个表进行反向转换,但首先我需要让函数工作,因此首先尝试使用一个变量。
trt <- c("A","B")
emmean <- c(0.95,0.23)
SE <- c(0.3,0.2)
df <- c(18.3, 24.6)
lower.CL <- c(0.60, 0.1)
upper.CL <- c(1.2, 0.5)
df <- data.frame(trt,emmean,SE,df,lower.CL,upper.CL)
library(confidence)
backtransform(df$emmean, type = "log")
Error in backtransform(df$emmean, type = "log") :
could not find function "backtransform"
发布于 2020-02-29 00:00:23
您需要键入以下内容:
confidence:::backtransform(df$emmean, type = "log")
[1] 2.58571 1.25860
正如@Dason所提到的,包的作者没有在他们的命名空间中导出这个函数,使得它有点隐藏(不可见)。
发布于 2020-02-29 00:09:53
您也可以改用exp(df$emmean)
。实际上,这基本上就是backtransform()
函数在您的例子中所做的事情。
完整代码:
#' Back-transformations
#'
#' Performs inverse log or logit transformations.
#'
#' @param x value to back-transform
#' @param type type of transform (log, logit).
#'
#' @return backtransformed value
backtransform <-
function(x, type = c("identity", "log", "logit", "none", NA_character_)) {
switch(
match.arg(type),
log = exp(x),
logit = exp(x) / (1 + exp(x)),
x
)
}
https://stackoverflow.com/questions/60454782
复制相似问题