R - ggplot - 函数错误,参数意味着行数不同:25,0

时间:2018-04-12 15:36:52

标签: r ggplot2 lme4

我无法在lmer模型中绘制固定效果。

library(ggplot2)
library(lme4)
library(lmerTest)
library(effects)

data(diamonds)

m1 <- lmer(carat ~ price * depth + (1 | cut), diamonds)
summary(m1)
ee <- Effect(c("price", "depth"), m1)
ggplot(data.frame(ee), aes(price, fit, color = cut)) + geom_line()

当我使用ggplot时,我收到此错误:

  

不知道如何自动选择类型对象的比例   功能。违约持续。 (函数(...,row.names)中的错误   = NULL,check.rows = FALSE,check.names = TRUE,:参数意味着行数不同:25,0

但是一个简单的plot(ee)会产生5个平铺图:

enter image description here

不同的模型会产生一个情节:

m3 <- lmer(price ~ depth * clarity + (1 | cut), diamonds)
summary(m3)
eg <- Effect(c("depth", "clarity"), m3)
ggplot(as.data.frame(eg), aes(depth, fit, color = clarity)) + geom_line()

enter image description here

每列的行数似乎不匹配:

> as.data.frame(ee)
   price depth       fit         se     lower     upper
1    330    40 0.4618286 0.04227714 0.3789651 0.5446922
2   5000    40 0.7931920 0.04074246 0.7133365 0.8730476
3   9600    40 1.1195885 0.04366662 1.0340016 1.2051754
4  14000    40 1.4317938 0.04988618 1.3340165 1.5295711
5  19000    40 1.7865726 0.05966749 1.6696239 1.9035214
6    330    50 0.4566107 0.03977778 0.3786459 0.5345754
7   5000    50 0.8690398 0.03930531 0.7920010 0.9460785
8   9600    50 1.2752869 0.04021511 1.1964649 1.3541088
9  14000    50 1.6638710 0.04228263 1.5809968 1.7467453
10 19000    50 2.1054440 0.04584704 2.0155834 2.1953045
11   330    60 0.4513927 0.03870323 0.3755341 0.5272513
12  5000    60 0.9448875 0.03868697 0.8690608 1.0207143
13  9600    60 1.4309852 0.03871997 1.3550938 1.5068767
14 14000    60 1.8959482 0.03879694 1.8199059 1.9719906
15 19000    60 2.4243153 0.03893796 2.3479966 2.5006340
16   330    70 0.4461747 0.03917094 0.3693994 0.5229501
17  5000    70 1.0207353 0.03892648 0.9444391 1.0970315
18  9600    70 1.5866836 0.03940454 1.5094504 1.6639168
19 14000    70 2.1280255 0.04050652 2.0486324 2.2074186
20 19000    70 2.7431867 0.04245996 2.6599648 2.8264085
21   330    80 0.4409568 0.04112833 0.3603449 0.5215686
22  5000    80 1.0965831 0.04000842 1.0181662 1.1749999
23  9600    80 1.7423820 0.04216278 1.6597426 1.8250214
24 14000    80 2.3601027 0.04684598 2.2682842 2.4519212
25 19000    80 3.0620580 0.05442428 2.9553860 3.1687300

导致此错误的原因是什么?

0 个答案:

没有答案