Linear regression with data from excel


#1

I have problems to apply a linear regression with two data set imported from excel. I have to find a simple model to predict ShareBelgium from MVBelgium (market value). The error message is the following :

ModelBelgium <- lm(ShareBelgium ~ MVBelgium[1:10])
Error in model.frame.default(formula = ShareBelgium ~ MVBelgium[1:10],  : 
  invalid type (list) for variable 'ShareBelgium'

Thanks


#2

Could you ask this with a minimal REPRoducible EXample (reprex)? A reprex makes it much easier for others to understand your issue and figure out how to help.

You should look at the documentation about lm to see how the formula interface works. It would better to put your two variables in a data.frame and use something like this

ModelBelgium <- lm(ShareBelgium ~ MVBelgium, data = my_data)

invalid type (list) for variable 'ShareBelgium'

Otherwise, be sure that ShareBelgium and MVBelgium are vectors.

From the help page example:

ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
group <- gl(2, 10, 20, labels = c("Ctl","Trt"))
group
#>  [1] Ctl Ctl Ctl Ctl Ctl Ctl Ctl Ctl Ctl Ctl Trt Trt Trt Trt Trt Trt Trt
#> [18] Trt Trt Trt
#> Levels: Ctl Trt
weight <- c(ctl, trt)
weight
#>  [1] 4.17 5.58 5.18 6.11 4.50 4.61 5.17 4.53 5.33 5.14 4.81 4.17 4.41 3.59
#> [15] 5.87 3.83 6.03 4.89 4.32 4.69
lm.D9 <- lm(weight ~ group)
lm.D9
#> 
#> Call:
#> lm(formula = weight ~ group)
#> 
#> Coefficients:
#> (Intercept)     groupTrt  
#>       5.032       -0.371

Created on 2018-11-11 by the reprex package (v0.2.1)