不知道我应该在model.matrix中放入什么。我想把这个名字放到model.matrix的名字列表中
a <- row.names(bbb)
a <- noquote(a)
a
for(k in a){
y <- election_data_train$Obama_margin_percent
x <- model.matrix( Obama_margin_percent ~ .-k-Obama_wins-Obama_margin-FIPS-ElectionDate-TotalVote-Clinton-Obama, data = election_data_train )
d <- election_data_train[["k"]]
gg_k <- glm(y~d+x)
print(summary(gg_k)$coef['d',])
}
答案 0 :(得分:0)
已解决。只需在下面第二行代码的末尾添加[-1]: model.matrix(Obama_margin_percent〜.-k-Obama_wins-Obama_margin-FIPS-ElectionDate-TotalVote-Clinton-Obama,数据= lection_data_train)