带加权因变量的双向方差分析
Two-way ANOVA with weighted dependent variable
试图通过个体大小来比较3个独立的人口,我有这样的数据集:
year <- c(rep(2000,5),rep(2001,3),rep(2002,7))
region <- c(1,1,2,3,3,1,2,3,rep(1,3),rep(2,3),3)
size <- c(28,24,26,56,47,85,12,24,68,71,42,59,12,25,33)
count <- c(3,8,9,1,2,4,7,12,4,8,3,2,7,15,4)
df <- data.frame(year, region, size, count)
给出:
year region size count
2000 1 28 3
2000 1 24 8
2000 2 26 9
2000 3 56 1
2000 3 47 2
2001 1 85 4
2001 2 12 7
2001 3 24 12
2002 1 68 4
2002 1 71 8
2002 1 42 3
2002 2 59 2
2002 2 12 7
2002 2 25 15
2002 3 33 4
我想进行二次方差分析:
model.2way <- lm(size ~ year * region, df) # example of code
anova(model.2way)
我的问题是变量 size
由 count
加权:对于每个 size
,我有 count
个个体。我有数百万个数据,但无法轻松地将我的数据转换为具有数百万个 size
值。
你知道用这种加权数据进行二次方差分析的方法吗?
提前致谢!
model.2way <- lm(size ~ year * region, df, weights = count)
来自?lm
:
... when the elements of ‘weights’ are positive integers w_i, that each response y_i is the mean of w_i unit-weight observations ...
换句话说,权重为 2 表示该案例出现两次。
试图通过个体大小来比较3个独立的人口,我有这样的数据集:
year <- c(rep(2000,5),rep(2001,3),rep(2002,7))
region <- c(1,1,2,3,3,1,2,3,rep(1,3),rep(2,3),3)
size <- c(28,24,26,56,47,85,12,24,68,71,42,59,12,25,33)
count <- c(3,8,9,1,2,4,7,12,4,8,3,2,7,15,4)
df <- data.frame(year, region, size, count)
给出:
year region size count
2000 1 28 3
2000 1 24 8
2000 2 26 9
2000 3 56 1
2000 3 47 2
2001 1 85 4
2001 2 12 7
2001 3 24 12
2002 1 68 4
2002 1 71 8
2002 1 42 3
2002 2 59 2
2002 2 12 7
2002 2 25 15
2002 3 33 4
我想进行二次方差分析:
model.2way <- lm(size ~ year * region, df) # example of code
anova(model.2way)
我的问题是变量 size
由 count
加权:对于每个 size
,我有 count
个个体。我有数百万个数据,但无法轻松地将我的数据转换为具有数百万个 size
值。
你知道用这种加权数据进行二次方差分析的方法吗?
提前致谢!
model.2way <- lm(size ~ year * region, df, weights = count)
来自?lm
:
... when the elements of ‘weights’ are positive integers w_i, that each response y_i is the mean of w_i unit-weight observations ...
换句话说,权重为 2 表示该案例出现两次。