[英]Nonlinear regression in R with multiple categorical dependent variables
我必须对数据进行非线性多元回归,如下所示:
ID Customer Country Industry Machine-type Service hours**
1 A China mass A1 120
2 B Europe customized A2 400
3 C US mass A1 60
4 D Rus mass A3 250
5 A China mass A2 480
6 B Europe customized A1 300
7 C US mass A4 250
8 D Rus customized A2 260
9 A China Customized A2 310
10 B Europe mass A1 110
11 C US Customized A4 40
12 D Rus customized A2 80
因变量:服务小时数自变量:客户,国家,行业,机器类型
我进行了线性回归,但是由于线性假设不成立,我必须执行非线性回归。
我知道可以使用nls函数完成非线性回归。 如何将类别变量添加到非线性回归中,以便获得R中的统计摘要 ?
ID Customer.a Customer.b Customer.c Customer.d Country.China Country.Europe Country.Rus Country.US Industry.customized industry.Customized Industry.mass Machine type.A1 Machine type.A2 Machine type.A3 Service hours
1 1 0 0 0 1 0 0 0 0 0 1 1 0 0 120
2 0 1 0 0 0 1 0 0 1 0 0 0 1 0 400
3 0 0 1 0 0 0 0 1 0 0 1 0 0 1 60
4 0 0 0 1 0 0 1 0 0 0 1 1 0 0 250
5 1 0 0 0 1 0 0 0 1 0 0 0 0 1 480
6 0 1 0 0 0 1 0 0 0 1 0 1 0 0 300
7 0 0 1 0 0 0 0 1 0 0 1 0 0 1 250
8 0 0 0 1 0 0 1 0 1 0 0 0 1 0 260
9 1 0 0 0 1 0 0 0 0 0 1 0 1 0 210
10 0 1 0 0 0 1 0 0 1 0 0 0 1 0 110
11 0 0 1 0 0 0 0 1 0 0 1 0 0 1 40
12 0 0 0 1 0 0 1 0 0 0 1 1 0 0 80
处理分类预测变量的方式取决于预测变量可以保持的级别数。
对于只能采用2种形式(男性或女性)的性别等预测变量,您可以简单地将它们表示为二进制(1,0)变量。
对于具有2个以上级别的预测变量,我们使用k分之一的虚拟编码,其中k是特定变量采用的级别数。 请参阅假人包以获取有用的功能!
之后,您可以使用公式拟合模型:
nls(Service.hours ~ predictor1 + predictor2 + predictorN, data = df)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.