对数变换的线性模型不适用于ggplot

时间:2018-12-14 18:18:23

标签: r ggplot2 linear-regression

LDPE_ester_80 <- read.table(text="Time  Value   SampleID
0   0.043501842 PP_0m_3a
0   0.062837605 PP_virgin_1a
0   0.047448064 PP_virgin_1b
0   0.06169221  PP_virgin_2a
30  0.164727573 PP_1_mhnes_UV_1a
30  0.143102841 PP_1m_1a
30  0.172545413 PP_1_mhnes_UV_1b
30  0.169354044 PP_1m_2a
60  0.223527391 PP_2_mhnes_UV_1a
60  0.134201756 PP_2m_1b
60  0.177466856 PP_2_mhnes_UV_1b
60  0.194665864 PP_2m_3b
60  0.281681336 PP_2m_4b
90  0.41039937  PP_3m_1a
90  0.398709677 PP_3m_1b
90  0.339117621 PP_3m_2a
90  0.379362836 PP_3m_3b
120 0.601786493 PP_4m_1a
120 0.784720551 PP_4m_2b
120 0.58218528  PP_4m_3a
120 0.586435863 PP_4m_3b
150 1.008573326 PP_5m_1a
150 1.00662725  PP_5m_1b
150 0.435590375 PP_5m_3a
150 0.57474698  PP_5m_4a", header=TRUE)

经过线性回归后,我发现指数模型最适合。但是在ggplot中表现不佳。该模型是:

exp.model <-lm(log(Value) ~ Time, data=LDPE_ester_80) 

和ggplot:

ggplot(LDPE_ester_80, aes(Time, Value) ) +
    geom_point() +   
    stat_smooth(method = lm, formula = log(y) ~ x, fill="mediumorchid4", colour="mediumorchid4", size=1.5, alpha = 0.2)+
    theme_classic() + 
    theme(text = element_text (family = "Calimbri", size = 12))+
    geom_point(shape=8, size=4, color="blue") + 
    ggtitle("exponetial regression") 

我确信错误很容易找到,但是我还没有!

2 个答案:

答案 0 :(得分:2)

如果将

stat_smooth与实际的y值一起使用,则效果最好。无法自动对结果进行运行日志转换。最好从头开始绘制log(Value)

ggplot(LDPE_ester_80, aes(Time, log(Value)) ) +
  geom_point() +   
  stat_smooth(method = lm, formula = y ~ x, fill="mediumorchid4", colour="mediumorchid4", size=1.5, alpha = 0.2)+
  theme_classic() + 
  theme(text = element_text (family = "Calimbri", size = 12))+
  geom_point(shape=8, size=4, color="blue") + 
  ggtitle("exponetial regression") 

enter image description here

答案 1 :(得分:0)

我无法在评论中放置图片,因此请将其放在此处。如果您有兴趣在不进行对数转换的情况下拟合数据,则可以将发布的数据拟合为具有两个形状参数ab且偏移量为y = 1.0 / (1.0 + exp(-1.0 * a * (x - b))) + offset的S型方程使用参数值a = 2.7733501227846083E-02, b = 1.0879951192178710E+02Offset = 2.2490280017710324E-02产生RMSE = 0.117R-squared = 0.819 sigmoidal