如何使用 Box cox 传输数据?

How can transfer data using Box cox?

我有如下数据。

数据:

temperature stage Replicate week Nematode_Number

        T20   All         1    1            60.0
        T20   All         2    1            72.7 
        T20   All         3    1            69.3
        T20   All         4    1            45.3
        T20   All         5    1            40.7

我喜欢找线性模型,然后对这个数据基于Box cox归一化数据,但是有一个错误。

Script: 

> mode (all)
[1] "list"

> is.data.frame (all)
[1] TRUE

> getClass(class(all))
Class "data.frame" [package "methods"]

Slots:


Name:                .Data               names           row.names            .S3Class
Class:                list           character data.frameRowLabels           character

Extends: 
Class "list", from data part
Class "oldClass", directly
Class "vector", by class "list", distance 2

> a <- boxcox(lm(Nematode_Number ~ week, data = all))

Error in terms.formula(formula, data = data) : 'data' argument is of the wrong type

boxcox 应该可以。那么 boxcox 也确实采用公式对象。因此,如果可以,请尝试清理您的环境或 rm(all) 并重新阅读。然后尝试下面的代码,如果此代码在上述之前不起作用。

 a=boxcox(Nematode_Number~week,data=all)

希望对您有所帮助

数据

df <- data.frame(temperature=rep("T20",5),
                 stage=rep("All",5),
                 Replicate=1:5, week=rep(1,5),
                 Nematode_Number=c(60.0, 72.7, 69.3, 45.3, 40.7),
                 stringsAsFactors=F)

这是你想要的吗?

这个有效

lm(Nematode_Number ~ week, data=df)

这行得通

library(MASS)
boxcox(Nematode_Number ~ week, data=df)

这行得通

temp <- lm(Nematode_Number ~ week, data=df)
boxcox(temp, data=df)