具有重复测量因子的线性模型

时间:2015-12-09 17:55:21

标签: r mixed-models

我有一个数据框df

    df<-structure(list(subject = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 
10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 
23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, 
36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L, 47L, 48L, 
49L, 50L, 51L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 
12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 
25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L, 
38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L, 47L, 48L, 49L, 50L, 
51L), sex = c(1L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 
1L, 2L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 2L, 2L, 
1L, 1L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 2L, 1L, 2L, 2L, 2L, 1L, 
2L, 2L, 1L, 2L, 1L, 2L, 1L, 1L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 1L, 
1L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 
1L, 2L, 2L, 1L, 1L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 2L, 1L, 2L, 
2L, 2L, 1L, 2L, 2L, 1L, 2L, 1L, 2L, 1L), age = c(29L, 54L, 67L, 
36L, 48L, 37L, 25L, 46L, 37L, 33L, 25L, 26L, 28L, 59L, 46L, 50L, 
55L, 56L, 37L, 30L, 38L, 30L, 50L, 39L, 29L, 46L, 48L, 46L, 55L, 
32L, 66L, 35L, 48L, 54L, 38L, 31L, 42L, 36L, 27L, 63L, 45L, 31L, 
26L, 38L, 43L, 52L, 36L, 43L, 65L, 46L, 42L, 29L, 54L, 67L, 36L, 
48L, 37L, 25L, 46L, 37L, 33L, 25L, 26L, 28L, 59L, 46L, 50L, 55L, 
56L, 37L, 30L, 38L, 30L, 50L, 39L, 29L, 46L, 48L, 46L, 55L, 32L, 
66L, 35L, 48L, 54L, 38L, 31L, 42L, 36L, 27L, 63L, 45L, 31L, 26L, 
38L, 43L, 52L, 36L, 43L, 65L, 46L, 42L), edu = c(4L, 3L, 3L, 
3L, 4L, 2L, 3L, 3L, 1L, 3L, 4L, 4L, 5L, 1L, 1L, 2L, 2L, 3L, 4L, 
4L, 4L, 4L, 4L, 4L, 2L, 2L, 1L, 2L, 2L, 4L, 2L, 4L, 4L, 3L, 3L, 
4L, 5L, 3L, 3L, 4L, 1L, 1L, 3L, 1L, 3L, 1L, 3L, 1L, 6L, 1L, 3L, 
4L, 3L, 3L, 3L, 4L, 2L, 3L, 3L, 1L, 3L, 4L, 4L, 5L, 1L, 1L, 2L, 
2L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 2L, 2L, 1L, 2L, 2L, 4L, 2L, 4L, 
4L, 3L, 3L, 4L, 5L, 3L, 3L, 4L, 1L, 1L, 3L, 1L, 3L, 1L, 3L, 1L, 
6L, 1L, 3L), biz_exp = c(5L, 15L, 3L, 4L, 10L, 6L, 0L, 5L, 8L, 
5L, 0L, 8L, 3L, 23L, 5L, 7L, 5L, 11L, 4L, 4L, 11L, 3L, 15L, 4L, 
4L, 6L, 6L, 5L, 13L, 2L, 13L, 6L, 8L, 27L, 7L, 3L, 11L, 5L, 1L, 
4L, 8L, 8L, 4L, 15L, 18L, 30L, 9L, 14L, 18L, 21L, 16L, 5L, 15L, 
3L, 4L, 10L, 6L, 0L, 5L, 8L, 5L, 0L, 8L, 3L, 23L, 5L, 7L, 5L, 
11L, 4L, 4L, 11L, 3L, 15L, 4L, 4L, 6L, 6L, 5L, 13L, 2L, 13L, 
6L, 8L, 27L, 7L, 3L, 11L, 5L, 1L, 4L, 8L, 8L, 4L, 15L, 18L, 30L, 
9L, 14L, 18L, 21L, 16L), turnov = c(36L, NA, 12L, 9L, 48L, 9L, 
8L, 24L, 4L, 250L, NA, 600L, 6L, 6L, 10L, 10L, 5L, 4L, 250L, 
200L, 50L, 150L, 48L, NA, 9L, 6L, 2L, NA, NA, 3L, 7L, 23L, 75L, 
7L, 5L, NA, 20L, 450L, 5L, 32L, 21L, 12L, 6L, 4L, 24L, 7L, 10L, 
12L, 12L, 14L, 18L, 36L, NA, 12L, 9L, 48L, 9L, 8L, 24L, 4L, 250L, 
NA, 600L, 6L, 6L, 10L, 10L, 5L, 4L, 250L, 200L, 50L, 150L, 48L, 
NA, 9L, 6L, 2L, NA, NA, 3L, 7L, 23L, 75L, 7L, 5L, NA, 20L, 450L, 
5L, 32L, 21L, 12L, 6L, 4L, 24L, 7L, 10L, 12L, 12L, 14L, 18L), 
    loc_pr = c(1L, 1L, 1L, 6L, 1L, 6L, 4L, 1L, 8L, 5L, 1L, 3L, 
    1L, 1L, 1L, 1L, 5L, 8L, 2L, 1L, 1L, 1L, 1L, 2L, 8L, 2L, 4L, 
    4L, 2L, 2L, 2L, 1L, 4L, 5L, 4L, 4L, 4L, 4L, NA, 4L, 5L, 5L, 
    5L, 8L, 1L, 2L, 4L, 3L, 3L, 4L, 3L, 1L, 1L, 1L, 6L, 1L, 6L, 
    4L, 1L, 8L, 5L, 1L, 3L, 1L, 1L, 1L, 1L, 5L, 8L, 2L, 1L, 1L, 
    1L, 1L, 2L, 8L, 2L, 4L, 4L, 2L, 2L, 2L, 1L, 4L, 5L, 4L, 4L, 
    4L, 4L, NA, 4L, 5L, 5L, 5L, 8L, 1L, 2L, 4L, 3L, 3L, 4L, 3L
    ), type = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 5L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 
    2L, 2L, 2L, 2L, 1L, 1L, 4L, 2L, 1L, 1L, 2L, 4L, 1L, 2L, 1L, 
    1L, 4L, 1L, 3L, 1L, 1L, 1L, 3L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 5L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 4L, 2L, 1L, 
    1L, 2L, 4L, 1L, 2L, 1L, 1L, 4L, 1L, 3L, 1L, 1L, 1L, 3L, 2L
    ), age_rec = c(2L, 4L, 4L, 100L, 4L, 100L, 100L, 4L, 100L, 
    2L, 1L, 2L, 2L, 4L, 4L, 4L, 4L, 100L, 3L, 2L, 3L, 2L, 4L, 
    3L, 100L, 27L, 100L, 100L, 4L, 2L, 100L, 2L, 4L, 30L, 3L, 
    2L, 59L, 8L, 100L, 27L, 3L, 59L, 2L, 59L, 3L, 59L, 3L, 3L, 
    4L, 64L, 3L, 2L, 4L, 4L, 100L, 4L, 100L, 100L, 4L, 100L, 
    2L, 1L, 2L, 2L, 4L, 4L, 4L, 4L, 100L, 3L, 2L, 3L, 2L, 4L, 
    3L, 100L, 27L, 100L, 100L, 4L, 2L, 100L, 2L, 4L, 30L, 3L, 
    2L, 59L, 8L, 100L, 27L, 3L, 59L, 2L, 59L, 3L, 59L, 3L, 3L, 
    4L, 64L, 3L), biz_exp_rec = c(2L, 4L, 2L, 3L, 3L, 3L, 1L, 
    2L, 3L, 2L, 1L, 3L, 2L, 4L, 2L, 3L, 2L, 4L, 2L, 2L, 4L, 2L, 
    4L, 2L, 2L, 4L, 4L, 4L, 4L, 1L, 4L, 3L, 3L, 4L, 3L, 2L, 3L, 
    3L, 2L, 4L, 3L, 2L, 2L, 3L, 4L, 4L, 3L, 4L, 4L, 4L, 4L, 2L, 
    4L, 2L, 3L, 3L, 3L, 1L, 2L, 3L, 2L, 1L, 3L, 2L, 4L, 2L, 3L, 
    2L, 4L, 2L, 2L, 4L, 2L, 4L, 2L, 2L, 4L, 4L, 4L, 4L, 1L, 4L, 
    3L, 3L, 4L, 3L, 2L, 3L, 3L, 2L, 4L, 3L, 2L, 2L, 3L, 4L, 4L, 
    3L, 4L, 4L, 4L, 4L), turnov_rec = structure(c(3L, NA, 3L, 
    2L, 3L, 3L, 1L, 3L, 3L, 4L, NA, 4L, 2L, 2L, 2L, 2L, 2L, 4L, 
    4L, 4L, 3L, 4L, 3L, 5L, 2L, 3L, 3L, 2L, NA, 2L, 4L, 3L, 4L, 
    4L, 2L, NA, 4L, 2L, 1L, 2L, 3L, 3L, 2L, 4L, 3L, 4L, 2L, 3L, 
    3L, 4L, 3L, 3L, NA, 3L, 2L, 3L, 3L, 1L, 3L, 3L, 4L, NA, 4L, 
    2L, 2L, 2L, 2L, 2L, 4L, 4L, 4L, 3L, 4L, 3L, NA, 2L, 3L, 3L, 
    2L, NA, 2L, 4L, 3L, 4L, 4L, 2L, NA, 4L, 2L, 1L, 2L, 3L, 3L, 
    2L, 4L, 3L, 4L, 2L, 3L, 3L, 4L, 3L), .Label = c("1", "2", 
    "3", "4", "MA"), class = "factor"), bundle = c(1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
    0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
    0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
    0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), investment = c(86L, 
    100L, 100L, 75L, 100L, 59L, 68L, 86L, 80L, 100L, 86L, 100L, 
    100L, 100L, 100L, 100L, 100L, 93L, 64L, 100L, 24L, 18L, 89L, 
    75L, 80L, 29L, 54L, 65L, 100L, 27L, 59L, 30L, 59L, 43L, 59L, 
    59L, 5L, 26L, 100L, 75L, 59L, 5L, 59L, 74L, 59L, 79L, 75L, 
    75L, 86L, 66L, 86L, 55L, 100L, 68L, 1L, 75L, 1L, 1L, 79L, 
    1L, 54L, 48L, 33L, 55L, 90L, 85L, 39L, 70L, 1L, 45L, 54L, 
    33L, 3L, 44L, 75L, 1L, 1L, 1L, 1L, 96L, 26L, 1L, 23L, 66L, 
    1L, 89L, 83L, 52L, 61L, 1L, 88L, 45L, 72L, 60L, 1L, 60L, 
    2L, 86L, 10L, 63L, 1L, 88L)), .Names = c("subject", "sex", 
"age", "edu", "biz_exp", "turnov", "loc_pr", "type", "age_rec", 
"biz_exp_rec", "turnov_rec", "bundle", "investment"), class = "data.frame", row.names = c(NA, 
-102L))

在此数据框中investment是我的因变量,其他变量是我的自变量。我的科目在捆绑类型中交叉。首先,我想知道我的主题是否捆绑(bundle = 1表示人们捆绑和捆绑= 0表示人们不捆绑),它会对投资产生影响。

我已经完成了这种混合效果线性模型,但我不确定这是否正确,因为我的p值等于零。

library(nlme) 
model <- lme(investment~bundle, random = ~1|subject/bundle, data=df)

我也试图用重复的措施制作一个anova: aov(investment~bundle+ Error(subject/bundle), data=df) 它有效,但不确定模型公式是否正确

任何人都可以帮助我吗?

0 个答案:

没有答案