R

时间:2017-06-22 14:37:37

标签: r statistics correlation

样本数据

A   B       C           D   E
1   2016    94.49433733 2   81.28
5   2016    95.38104534 4   139.6944
7   2016    95.43885385 1   69.11
8   2016    94.91936704 1   7.23
9   2016    95.21859776 3   152.31
10  2016    95.15797535 1   86.32
11  2016    95.1830432  2   38.24
13  2016    94.01256633 2   33.3

给定样本数据并使用R,我想构建一个序列,让我从预测变量( C )中获得增量影响。

预期表格(增加0.5):

C           ANSWER
85          
85.05       
85.1        
85.15       
85.2        
85.25       
85.3        
85.35       

我希望了解C中的每个delta变化(增加),D会发生什么?

以下是我尝试使用转换和应用

的内容
transform(df, volumen=unlist(tapply(C, D,  function(x) c(0, diff(x)))))

1 个答案:

答案 0 :(得分:0)

fit <- lm(D ~ C, data = my_sample_data) #Fits a linear model
my_sequence <- seq(from = 85, to = 85.35, by = 0.05 ) # first column
result <- fit$coefficients[1] + my_sequence * fit$coefficients[2] #2nd column
df <- data.frame(C = my_sequence, ANSWER = result) #Makes a table