【发布时间】:2018-07-13 17:59:48
【问题描述】:
我必须使用如下所示的数据执行非线性多元回归:
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 中获得统计摘要?
添加假人后的列名:table with dummies
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
【问题讨论】:
-
不确定您使用的函数是否可以采用因子变量,或者您可能需要创建虚拟变量。看看
dummies包 -
您好,感谢您这么快的回答!是的,我使用了 dummies 包。所以现在我有多个假人,但是如何将这些假人放入统计汇总结果的非线性函数中?
-
> datadum names(datadum) [1] "ID" "Customer.a" "Customer.b" [4] "Customer.c" "Customer.d" "Country.China" [7] "Country.Europe" "Country.Rus" "Country.US" [10] "Industry.customized" "Industry.Customized" "Industry.mass " [13] "机器类型.A1" "机器类型.A2" "机器类型.A3" [16] "服务时间"
-
这些是我得到的假人。我想将它们添加到非线性回归中。提前感谢您对我的帮助!
-
能否更新问题中的数据框
标签: r categorical-data non-linear-regression