0

I have 3 numerical variables A, B and C. I am trying to create a linear model capable of predicting A. The expression that I am using is the product of B*C in order to predict A; however, when looking at the output I am not able to get my equation because I get and extra variable that I don't know what is it.

Here is my code

MyData<-read.csv("...", header = T)
head(MyData,6)
str(MyData)

#Linear Model 
#Expersion A= B*C
Model1<-lm(MyData$A~MyData$B*MyData$C)
summary(Model1)

Output of str(MyData)

> str(MyData)
'data.frame':   6 obs. of  3 variables:
 $ A: num  2.5 3.4 2.7 3.6 2.5 2.1
 $ B: num  0.01 0.02 0.015 0.017 0.018 0.01
 $ C: num  0.1 0.2 0.27 0.19 0.17 0.16

Output of summary(Model1)

Call:
lm(formula = MyData$A ~ MyData$B * MyData$C)

Residuals:
       1        2        3        4        5        6 
-0.03945 -0.08386 -0.13925  0.67703 -0.40055 -0.01393 

Coefficients:
                  Estimate Std. Error t value Pr(>|t|)
(Intercept)          5.473      5.774   0.948    0.443
MyData$B          -222.431    454.508  -0.489    0.673
MyData$C           -26.482     36.222  -0.731    0.541
MyData$B:MyData$C 1938.961   2679.207   0.724    0.544

Residual standard error: 0.5688 on 2 degrees of freedom
Multiple R-squared:  0.6149,    Adjusted R-squared:  0.03723 
F-statistic: 1.064 on 3 and 2 DF,  p-value: 0.5178

lm uses the Wilkinson-Rogers notation so "*" is an iteration, based on the output, right? is this true, how do I create my model using the product of my two variables?

closed as off-topic by Spacedman, ArMoraer, whyzar, Mark Ireland, Vince Apr 18 at 15:29

  • This question does not appear to be about geographic information systems (GIS) within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Is there a GIS component to your question? To me it looks like it may more suited to researching/asking at Stack Overflow. – PolyGeo Apr 18 at 4:05
  • Yes there is; however, I did not explicitly indicated/mentioned this in the post. All of these measurements have a lat long component. Unfortunately, I have not gotten to that part, because I am stuck on the model development. – Perro Apr 18 at 4:10
  • 4
    I'm voting to close this question as off-topic because not a GIS question or spatial data...yet. – Spacedman Apr 18 at 7:48
  • You should find a tutorial on linear models in R - there's enough out there that none of this should need repeating here until you get stuck. – Spacedman Apr 18 at 7:49
1

To calculate the product (or any in-formula calculation) use the I() function:

mod <- lm(A ~ B + C + I(B*C))

B and C should be included by themselves (as noted above). If they are not significant and the interaction term is, still leave them in.

  • Thank you at @Jackson. So from the output summary(mod) how do I interpret the results to get the actual equation in case B+C are not significant? – Perro Apr 18 at 5:45
  • I would just state that on their own nieither B nor C have a significant impact, however their interaction does. But you still need to leave them in the formula in the event that I(B*C) is significant! – Jackson Apr 19 at 0:59

Not the answer you're looking for? Browse other questions tagged or ask your own question.