时间序列混合效应模型lme4

如何解决时间序列混合效应模型lme4

我正在尝试运行一个使用时间作为固定效应的混合效应模型。我在不规则的时间间隔 (3-7) 上重复了测量,并想考虑我的变量与时间的固定线性关系。同时,我对确定处理效果(干旱和竞争)感兴趣。

以下是我尝试使用 lme4lmer

运行的数据集之一
> BRCAgassydays
   Species Drought Competition Treatment Time assimilation conductance intercellularcarbon
1     BRCA Control    Invasive       CxI    0     7.811799  0.16297273            297.5562
2     BRCA Control    Invasive       CxI   21     5.405663  0.19472180            314.8806
3     BRCA Control    Invasive       CxI   29     7.604270  0.14460617            291.1411
4     BRCA Control    Invasive       CxI   34     7.513887  0.22543327            326.1150
5     BRCA Control    Invasive       CxI   42     6.683802  0.18940180            318.6928
6     BRCA Control    Invasive       CxI   55     6.071712  0.13774260            301.6228
7     BRCA Control    Invasive       CxI   70     6.331053  0.13962460            306.8503
8     BRCA Control    Invasive       CxI   78     4.941679  0.13157067            312.1904
9     BRCA Control    Invasive       CxI   82     4.729761  0.11871700            313.6009
10    BRCA Control    Invasive       CxI   88     6.831296  0.16134250            305.1969
11    BRCA Control    Invasive       CxI   97     4.652050  0.09225767            295.9346
12    BRCA Control    Invasive       CxI  104     5.873223  0.16265633            313.8243
13    BRCA Control        None       CxN    0     7.644604  0.17184619            301.8665
14    BRCA Control        None       CxN   21     8.250492  0.23745253            317.0501
15    BRCA Control        None       CxN   29     7.463330  0.13094473            286.2365
16    BRCA Control        None       CxN   34     7.928604  0.24988353            328.3139
17    BRCA Control        None       CxN   42     7.415549  0.18531760            309.8957
18    BRCA Control        None       CxN   55     6.764483  0.13508080            291.4254
19    BRCA Control        None       CxN   70     5.666392  0.11958453            304.4248
20    BRCA Control        None       CxN   78     7.267130  0.16822320            303.4725
21    BRCA Control        None       CxN   82     5.870902  0.11838573            297.4116
22    BRCA Control        None       CxN   88     7.400286  0.18886560            306.0608
23    BRCA Control        None       CxN   97     5.397562  0.13183013            313.4487
24    BRCA Control        None       CxN  104     5.756836  0.14453173            311.5725
25    BRCA Drought    Invasive       DxI    0     6.932256  0.12224355            285.7301
26    BRCA Drought    Invasive       DxI   21     8.448956  0.22943413            311.6504
27    BRCA Drought    Invasive       DxI   29     7.410476  0.12434440            280.5574
28    BRCA Drought    Invasive       DxI   34     8.208636  0.26668580            327.9786
29    BRCA Drought    Invasive       DxI   42     5.324922  0.12691907            312.5066
30    BRCA Drought    Invasive       DxI   55     5.196439  0.10962533            295.7930
31    BRCA Drought    Invasive       DxI   70     4.643326  0.08082647            289.0008
32    BRCA Drought    Invasive       DxI   78     3.675965  0.07471427            298.9459
33    BRCA Drought    Invasive       DxI   82     4.113252  0.09586540            310.3563
34    BRCA Drought    Invasive       DxI   88     4.340185  0.09807740            310.9444
35    BRCA Drought    Invasive       DxI   97     4.410509  0.09351200            304.7900
36    BRCA Drought    Invasive       DxI  104     2.961152  0.06973620            309.7580
37    BRCA Drought        None       DxN    0     5.299206  0.10402717            299.4199
38    BRCA Drought        None       DxN   21     8.931698  0.22541307            310.6568
39    BRCA Drought        None       DxN   29     6.490820  0.10163740            271.2123
40    BRCA Drought        None       DxN   34     6.748470  0.19204680            323.1626
41    BRCA Drought        None       DxN   42     4.175082  0.08008673            295.1853
42    BRCA Drought        None       DxN   55     4.740064  0.10071627            293.5214
43    BRCA Drought        None       DxN   70     5.147252  0.09366540            284.0992
44    BRCA Drought        None       DxN   78     5.187626  0.09444033            291.6765
45    BRCA Drought        None       DxN   82     4.608225  0.09833660            303.1695
46    BRCA Drought        None       DxN   88     6.398861  0.14120963            303.1060
47    BRCA Drought        None       DxN   97     3.980145  0.11448827            324.5742
48    BRCA Drought        None       DxN  104     5.233092  0.12851007            313.0436
   transpiration        seA        seG     seCi       seE
1       2.822450 0.43644138 0.05761956 105.2020 0.9978866
2       2.320922 0.45469707 0.08708224 140.8189 1.0379479
3       1.790830 0.47508738 0.05903522 118.8578 0.7311035
4       2.400032 0.43793202 0.10081682 145.8431 1.0733268
5       2.805418 0.67185683 0.08470306 142.5237 1.2546211
6       3.114693 0.74197040 0.06160036 134.8898 1.3929330
7       1.795997 1.23465637 0.06244202 137.2276 0.8031942
8       2.715327 0.72150617 0.05884019 139.6158 1.2143311
9       2.544619 0.74568747 0.05309186 140.2466 1.1379881
10      3.019007 1.51528270 0.08067125 152.5985 1.5095034
11      1.784082 0.03402206 0.04612883 147.9673 0.8920409
12      3.453956 0.33488091 0.07274212 140.3465 1.5446562
13      2.598881 0.46217235 0.06075680 106.7259 0.9188432
14      2.909069 0.84976554 0.10619200 141.7891 1.3009752
15      2.025599 0.50776426 0.05856027 128.0088 0.9058755
16      2.487442 0.54267771 0.11175131 146.8264 1.1124180
17      2.875295 0.11954494 0.08287655 138.5896 1.2858709
18      3.265247 0.84720688 0.06040997 130.3294 1.4602628
19      1.483867 0.44247329 0.05347983 136.1429 0.6636057
20      3.203109 0.74145804 0.07523170 135.7170 1.4324737
21      2.539916 1.02080831 0.05294371 133.0065 1.1358850
22      3.553893 0.34056152 0.08446326 136.8745 1.5893495
23      1.926768 0.80018829 0.05895623 140.1785 0.8616768
24      3.047124 0.42481340 0.06463656 139.3395 1.3627154
25      1.899871 0.55859666 0.04321962 101.0208 0.6717057
26      2.797467 0.88094476 0.10260606 139.3743 1.2510653
27      2.110417 0.64763904 0.05560851 125.4691 0.9438074
28      2.689897 0.42303271 0.11926552 146.6765 1.2029587
29      2.197370 0.97036269 0.05675993 139.7572 0.9826938
30      2.669697 0.54886662 0.04902594 132.2827 1.1939247
31      1.295458 0.61865489 0.03614669 129.2451 0.5793462
32      1.736331 0.69632750 0.03341324 133.6927 0.7765110
33      2.171248 0.58167406 0.04287231 138.7956 0.9710117
34      2.127337 1.02370322 0.04386155 139.0585 0.9513742
35      1.719165 0.61438695 0.04181984 136.3062 0.7688341
36      1.628725 1.18038670 0.03118698 138.5280 0.7283880
37      1.572679 0.73317733 0.03677916 105.8609 0.5560261
38      2.887991 0.75700712 0.10080779 138.9300 1.2915488
39      1.712095 0.86022203 0.04545363 121.2898 0.7656720
40      2.074472 0.31120772 0.08588594 144.5227 0.9277320
41      1.466688 0.40419493 0.03581588 132.0109 0.6559227
42      2.380746 0.70855853 0.04504168 131.2668 1.0647018
43      1.520280 0.62697587 0.04188844 127.0530 0.6798899
44      1.772095 0.45202487 0.04223500 130.4417 0.7925049
45      2.191443 0.55772642 0.04397746 135.5815 0.9800431
46      2.756795 1.13005016 0.06315087 135.5531 1.2328762
47      2.051825 0.83631901 0.05120071 145.1540 0.9176041
48      2.867810 1.07582755 0.05747145 139.9974 1.2825237

我很难确定我是否正确编码:

brcalme <- lmer(assimilation ~ Competition*Drought + (1|Time),data = BRCAgassydays)

我也很难解释结果并确定它们在没有 p 值的情况下是否显着

> brcalme
Linear mixed model fit by REML ['lmerMod']
Formula: assimilation ~ Competition * Drought + (1 | Time)
   Data: BRCAgassydays
REML criterion at convergence: 147.2326
Random effects:
 Groups   Name        Std.Dev.
 Time     (Intercept) 1.0027  
 Residual             0.9269  
Number of obs: 48,groups:  Time,12
Fixed Effects:
                   (Intercept)                 CompetitionNone  
                        6.2042                          0.6980  
                DroughtDrought  CompetitionNone:DroughtDrought  
                       -0.7320                         -0.5918  


 summary(brcalme)
Linear mixed model fit by REML ['lmerMod']
Formula: assimilation ~ Competition * Drought + (1 | Time)
   Data: BRCAgassydays

REML criterion at convergence: 147.2

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-2.3906 -0.4165  0.0132  0.5943  2.0888 

Random effects:
 Groups   Name        Variance Std.Dev.
 Time     (Intercept) 1.0055   1.0027  
 Residual             0.8591   0.9269  
Number of obs: 48,12

Fixed effects:
                               Estimate Std. Error t value
(Intercept)                      6.2042     0.3942  15.739
CompetitionNone                  0.6980     0.3784   1.845
DroughtDrought                  -0.7320     0.3784  -1.935
CompetitionNone:DroughtDrought  -0.5918     0.5351  -1.106

Correlation of Fixed Effects:
            (Intr) CmpttN DrghtD
CompetitnNn -0.480              
DroghtDrght -0.480  0.500       
CmpttnNn:DD  0.339 -0.707 -0.707

在此先感谢您的帮助!

解决方法

关于 lmer() 函数的编码/说明,您确实有有效的输入。它们是否正确或有用最终取决于您正在使用/测试的理论。对于此类特定主题或理论问题,请查看 CrossValidated。

关于如何获取 p 值,加载包 lmerTest,然后在模型上运行 summary()

library(lme4)
library(lmerTest)

lmm <- lmer(assimilation ~ Competition*Drought + (1|Time),data = brcalme)
summary(lmm)

输出:

Linear mixed model fit by REML. t-tests use Satterthwaite's method ['lmerModLmerTest']
Formula: assimilation ~ Competition * Drought + (1 | Time)
   Data: brcalme

REML criterion at convergence: 147.2

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-2.3906 -0.4165  0.0132  0.5943  2.0888 

Random effects:
 Groups   Name        Variance Std.Dev.
 Time     (Intercept) 1.0055   1.0027  
 Residual             0.8591   0.9269  
Number of obs: 48,groups:  Time,12

Fixed effects:
                               Estimate Std. Error      df t value Pr(>|t|)    
(Intercept)                      6.2042     0.3942 23.4989  15.739 5.61e-14 ***
CompetitionNone                  0.6980     0.3784 33.0000   1.845   0.0741 .  
DroughtDrought                  -0.7320     0.3784 33.0000  -1.935   0.0617 .  
CompetitionNone:DroughtDrought  -0.5918     0.5351 33.0000  -1.106   0.2768    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Correlation of Fixed Effects:
            (Intr) CmpttN DrghtD
CompetitnNn -0.480              
DroghtDrght -0.480  0.500       
CmpttnNn:DD  0.339 -0.707 -0.707
,

关于“我正在尝试运行一个使用时间作为固定效应的混合效应模型。我在不规则的时间间隔 (3-7) 上重复了测量,并希望考虑我的变量与时间的固定线性关系.” 不,您没有正确编码。 (1|Time) 是一个随机效应术语(请参阅这些参考资料:https://cran.r-project.org/web/packages/lme4/vignettes/lmer.pdfhttps://stats.stackexchange.com/questions/4700/what-is-the-difference-between-fixed-effect-random-effect-and-mixed-effect-mode

此随机效应术语用于将“重复测量”中的数据点分组。例如,如果您多次调查 20 个不同的网站,您可能会使用 (1|Sites) 作为随机效应术语(有关语法帮助,请参阅上面的 lme4 插图链接)。如果您确实有重复测量,最好以这种方式对数据进行分组(有助于避免伪复制)。

对于 Time,您可以将其拟合为固定效果:

brcalme <- lmer(assimilation ~ Competition*Drought + Time,data = BRCAgassydays)

但在这里您可能会收到错误消息,因为您没有指定任何随机效应(时间是上述等式中的固定效应)。因此,您只需要一个线性模型(不是混合效应)。您可以将 lmer 更改为 lm 以执行此操作:

brcalme <- lm(assimilation ~ Competition*Drought + Time,data = BRCAgassydays)

但同样,如果可以/合适的话,拟合随机效应项(但根据你的问题,我猜时间不是你想要的随机效应项)。

关于 p 值,值得仔细阅读这些值的真正含义(例如 P-value,significance level and hypothesishttps://stats.stackexchange.com/questions/166323/misunderstanding-a-p-value),并尝试学习解释您的估计值和围绕这些估计值的 SE(幅度效应)而不是寻找“统计显着性”。 lme4 没有开箱即用的 p 值功能是有原因的(即,您必须加载 lmerTest)。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-