比较三个治疗组之间的时间序列数据(在R中)

问题描述 投票:0回答:1

我有时间序列数据,响应随时间而下降。减少的速度应该取决于治疗方法(药物浓度)。通过查看数据,我不确定数据是否会显示出治疗之间的显着差异,但我需要以p值进行统计学显示。为此,需要执行哪种类型的统计分析?数据可以用一阶速率方程拟合R = R_0 * exp(-k * t)。

样本数据:

library(ggplot2)

df = structure(list(time = c(0, 0, 5, 5, 10, 10, 15, 15, 20, 20, 30, 30, 40, 40),
                    conc_A = c(0.9957, 1.004, 0.9074, 0.8415, 0.8033, 0.7782, 0.6642, 0.6504, 0.6183, 0.6347, 0.48, 0.5222, 0.3737, 0.4229),
                    conc_B = c(1.054, 0.9463, 0.8999, 0.775, 0.738, 0.6598, 0.6498, 0.6078, 0.5878, 0.552, 0.4826, 0.4218, 0.3624, 0.2902),
                    conc_C = c(0.9735, 1.026, 0.7553, 0.82, 0.6976, 0.6548, 0.5795, 0.531, 0.4751, 0.4508, 0.3259, 0.3688, 0.2806, 0.244)),
               class = "data.frame", row.names = c(NA, -14L))

melt.df <- melt(df, id.vars = 'time', variable.name = 'treatment', value.name = 'response')
plot.df <- ggplot(melt.df, aes(time, response, color = treatment)) +
  geom_point() +
  theme_classic()
plot.df

quick plot of the provided data

r nls p-value
1个回答
0
投票

将数据转换为长格式。使用该模型针对时间fm0运行线性模型以获取初始值,然后运行相应的非线性模型fm1。然后运行类似于fm1的模型,但添加了浓度名称。最后在fm2fm1之间执行方差分析。我们看到浓度非常重要。

library(tidyr)
long <- pivot_longer(df, -time)

fm0 <- nls(log(value) ~ log(R) - k * time, long, start = list(R = 1, k = 1))
fm1 <- nls(value ~ R * exp(-k * time), long, start = coef(fm0))

R <- coef(fm1)[[1]]
k <- coef(fm1)[[2]]
st <- list(RA = R, kA = k, RB = R, kB = k, RC = R, kC = k)
fm2 <- nls(value ~ 
        (RA * exp(-kA * time)) * (name == "conc_A") + 
        (RB * exp(-kB * time)) * (name == "conc_B") +
        (RC * exp(-kC * time)) * (name == "conc_C"), long, 
        start = st)
anova(fm2, fm1)

给予:

Analysis of Variance Table

Model 1: value ~ (RA * exp(-kA * time)) * (name == "conc_A") + (RB * exp(-kB * time)) * (name == "conc_B") + (RC * exp(-kC * time)) * (name == "conc_C")
Model 2: value ~ R * exp(-k * time)
  Res.Df Res.Sum Sq Df    Sum Sq F value    Pr(>F)    
1     36   0.051482                                   
2     40   0.151207 -4 -0.099725  17.434 4.866e-08 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
© www.soinside.com 2019 - 2024. All rights reserved.