首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >反向转换日志数据,包和函数不工作吗?

反向转换日志数据,包和函数不工作吗?
EN

Stack Overflow用户
提问于 2020-02-28 23:31:08
回答 2查看 169关注 0票数 0

我正在尝试对表中的数据进行反向转换。但我不能让它工作。有人知道为什么吗?我想要对整个表进行反向转换,但首先我需要让函数工作,因此首先尝试使用一个变量。

代码语言:javascript
运行
复制
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"
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-02-29 00:00:23

您需要键入以下内容:

代码语言:javascript
运行
复制
confidence:::backtransform(df$emmean, type = "log")
[1] 2.58571 1.25860

正如@Dason所提到的,包的作者没有在他们的命名空间中导出这个函数,使得它有点隐藏(不可见)。

票数 1
EN

Stack Overflow用户

发布于 2020-02-29 00:09:53

您也可以改用exp(df$emmean)。实际上,这基本上就是backtransform()函数在您的例子中所做的事情。

完整代码:

代码语言:javascript
运行
复制
#' 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
    )
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60454782

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档