具有多个条件的R条件回归

编程入门 行业动态 更新时间:2024-10-26 14:35:28
本文介绍了具有多个条件的R条件回归的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试基于两个条件在R中进行回归.我的数据具有年份和其他分类的二进制变量.仅使用1个条件,我就可以使回归正常运行:

I am trying to run a regression in R based on two conditions. My data has binary variables for both year and another classification. I can get the regression to run properly while only using 1 condition:

# now time for the millions of OLS # format: OLSABCD where ABCD are binary for the values of MSA/UA and years # A = 1 if MSA, 0 if UA # B = 1 if 2010 # C = 1 if 2000 # D = 1 if 1990 OLS1000<-summary(lm(lnrank ~ lnpop, data = subset(df, msa==1))) OLS1000

但是,我无法弄清楚如何同时将MSA/UA分类与年份变量一起使用.我已经尝试过:

However I cannot figure out how to get both the MSA/UA classification to work with the year variables as well. I have tried:

OLS1100<-summary(lm(lnrank ~ lnpop, data = subset(df, msa==1, df$2010==1))) OLS1100

但是它返回错误:

Error: unexpected numeric constant in "OLS1100<-summary(lm(lnrank ~ lnpop, data = subset(df, msa==1, df$2010"

如何使程序在两种情况下都能运行?

How can I get the program to run utilizing both conditions?

再次感谢您!

推荐答案

问题是:

df$2010

如果您的数据确实有一个名为2010的列,那么您需要在其周围加上反引号:

If your data really has a column named 2010, then you need backticks around it:

df$`2010`

在您的子集中,不要两次指定df:

And in your subset, don't specify df twice:

subset(df, msa == 1, `2010` == 1)

通常,最好不要使用数字开头的列名.最好不要命名数据帧df,因为这是一个函数名.

In general it's better if column names don't start with digits. It's also best not to name data frames df, since that's a function name.

更多推荐

具有多个条件的R条件回归

本文发布于:2023-11-22 00:49:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1615322.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:条件   多个

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!