使用 R 建模时间趋势(混合模型)

发布于 2025-01-12 03:04:27 字数 1551 浏览 2 评论 0原文

我有一个问题,但似乎无法解决。

我有大约 2000 个不同 VPN 的数据。我在四个时间点询问他们的精神状态(“Psychisch”)。如果我查看散点图中的不同数据,您可以清楚地看到存在非常不同的进展。由于人数太多,我只同时关注大约 50 个人,但他们似乎总是表现出不同的进展(从消极、过度到与时间的积极关联)。

现在,我首先计算了仅截距模型,效果很好。然后我添加时间因子作为协变量(首先固定)。这个模型也奏效了。

如果我现在尝试将时间变量的斜率设为随机因子,则会出现以下错误消息:

boundary (singular) fit: see help('isSingular') 

或者

Error: number of observations (=6676) <= number of random effects (=6676) for term (1 + Zeit.n | id); the random-effects parameters and the residual variance (or scale parameter) are probably unidentifiable 

取决于我如何转换时间变量。我是否应该将 time 变量转换为数字或因子变量?我会假设因素,因为它只是这四个时间点,但是当我将其作为因素时,我收到另一条错误消息。

我已经阅读了很多关于这个问题的其他帖子,但似乎无法弄清楚为什么我的数据集有同样的问题。我对每个人有四个观察结果,我只想查看每个人时间回归系数的方差。我确信存在方差,因此估计方差非常小对我来说没有意义。

我不明白我做错了什么。有人可以帮我吗?

这是我的数据集: https://wetransfer.com/downloads/feba9b0316850cecf78dcb161a7c08ec20220307010300/4f9b39

和我的语法:

df <- read.csv2("Data.csv")
library(lmerTest)

colnames(df) <- c("id","ART","Zeit","Phy","Psy")

df$id <- as.factor(df$id)
df$Zeit.n <- as.factor(df$Zeit)
df$Psy.c <- scale(df$Psy,scale=F)


mod0 <- lmer(Psy.c ~ 1 + (1|id),data=df)
summary(mod0)


mod1 <- lmer(Psy.c ~ 1+Zeit + (1|id),df)
summary(mod1)


mod2 <- lmer(Psy.c ~ 1+Zeit + (1+Zeit|id),df)
summary(mod2)

mod3 <- lmer(Psy.c ~ 1+Zeit.n + (1+Zeit.n|id),df)

亲切的问候!

I have a problem and just can't seem to solve it.

I have data from about 2000 different VPN. At four points in time I asked them about their state of mind ("Psychisch"). If I look at the different data in the scatter plot, you can see very well that there are very different progressions. As there are so many people I only look at about 50 at the same time, but they always seem to show different progressions (from negative, over no, to positive associations with time).

Now I first calculated an intercept only model and that worked well. Then I added the time factor as a covariate (first fixed). This model also worked.

If I now try to make the slopes for the time variable a random factor there is the following error message:

boundary (singular) fit: see help('isSingular') 

or

Error: number of observations (=6676) <= number of random effects (=6676) for term (1 + Zeit.n | id); the random-effects parameters and the residual variance (or scale parameter) are probably unidentifiable 

depending on how I transform the time variable. Am I supposed to transform the time variable into a numeric or factor variable? I would have assumed factor, as it is just those four timepoints, but when I make it a factor I get another error message.

I already read through a lot of other posts about this problem, but can't seem to figure out why my dataset has that same problem. I have four observations per Person and I just want to look at the variance of the regression coefficients for time for each person. I'm sure that there is variance, so the estimated variance being very small doesn't make sense for me.

I can't figure out what I'm doing wrong. Can anyone help me out?

Here is my dataset: https://wetransfer.com/downloads/feba9b0316850cecf78dcb161a7c08ec20220307010300/4f9b39

and my syntax:

df <- read.csv2("Data.csv")
library(lmerTest)

colnames(df) <- c("id","ART","Zeit","Phy","Psy")

df$id <- as.factor(df$id)
df$Zeit.n <- as.factor(df$Zeit)
df$Psy.c <- scale(df$Psy,scale=F)


mod0 <- lmer(Psy.c ~ 1 + (1|id),data=df)
summary(mod0)


mod1 <- lmer(Psy.c ~ 1+Zeit + (1|id),df)
summary(mod1)


mod2 <- lmer(Psy.c ~ 1+Zeit + (1+Zeit|id),df)
summary(mod2)

mod3 <- lmer(Psy.c ~ 1+Zeit.n + (1+Zeit.n|id),df)

Kind regards!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文