R:多元线性回归误差

时间:2014-03-24 08:42:31

标签: r linear-regression lm read.table

我很难运行lm()函数并理解错误。

所以,我的脚本是这样的:

#! /usr/bin/env/ Rscript

meteodata <- read.table("/path/to/dataset.txt", header=T)
meteodata
summary(meteodata)


plot(meteodata)

lmodel <- lm(temperature~altitude+sea.distance, data=meteodata)

控制台输出是这样的:

temperature station.id latitude longtitude sea.distance altitude
1         20,1         S1      0,5        0,5          0,5        0
2         20,5         S1      0,5        0,5          0,5        0
3         19,3         S1      0,5        0,5          0,5        0
4         18,6         S1      0,5        0,5          0,5        0
5         21,5         S1      0,5        0,5          0,5        0
6         17,1         S2      3,5        2,5          1,5      200
7         18,3         S2      3,5        2,5          1,5      200
8         16,8         S2      3,5        2,5          1,5      200
9         17,5         S2      3,5        2,5          1,5      200
10        16,4         S2      3,5        2,5          1,5      200
11        18,4         S3      2,5        3,5          0,5      100
12        19,1         S3      2,5        3,5          0,5      100
13        18,9         S3      2,5        3,5          0,5      100
14        17,8         S3      2,5        3,5          0,5      100
15        17,6         S3      2,5        3,5          0,5      100
16        15,1         S4        4          0            4      400
17        15,5         S4        4          0            4      400
18        15,0         S4        4          0            4      400
19        14,9         S4        4          0            4      400
20        15,8         S4        4          0            4      400
  temperature station.id latitude longtitude sea.distance    altitude  
 14,9   : 1   S1:5       0,5:5    0  :5      0,5:10       Min.   :  0  
 15,0   : 1   S2:5       2,5:5    0,5:5      1,5: 5       1st Qu.: 75  
 15,1   : 1   S3:5       3,5:5    2,5:5      4  : 5       Median :150  
 15,5   : 1   S4:5       4  :5    3,5:5                   Mean   :175  
 15,8   : 1                                               3rd Qu.:250  
 16,4   : 1                                               Max.   :400  
 (Other):14                                                            
Warning messages:
1: In model.response(mf, "numeric") :
  using type = "numeric" with a factor response will be ignored
2: In Ops.factor(y, z$residuals) : - not meaningful for factors

我在这里和那里读过一些类似的问题,但我仍然无法弄清楚我做错了什么。 我需要temperature作为我的响应y变量,由独立的 x1,x2 altitudesea.distance变量计算。

任何帮助将不胜感激,只是尝试具体。提前致谢

1 个答案:

答案 0 :(得分:1)

R使用.作为小数点分隔符。您的数据使用,,R将数据解释为字符,默认情况下是因子变量。使用dec=","告诉read.table数据是数字的,,为小数点分隔符。