[R] Need Help Plotting "Line" for multiple linear regression

PIKAL Petr petr.pikal at precheza.cz
Thu Feb 14 09:02:57 CET 2013


Hi

> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Craig O'Connell
> Sent: Wednesday, February 13, 2013 11:03 PM
> To: r-help at r-project.org
> Subject: [R] Need Help Plotting "Line" for multiple linear regression
> 
> Hello,
> 
> My name is Craig and I need help plotting a "line" for a multiple
> linear regression in R.
> 
> Here is my sample data (filename:  convis.txt)
> 
> Output of convis.txt is (vis and density being predictors of either
> avoidance or entrance):
> 
>    vis den  avoid entrance
> 1   10   1 0.0000   0.0000
> 2   10   3 0.8750   0.0000
> 3    8   3 0.8180   0.0300
> 4    8   3 0.6670   0.0667
> 5    8   1 0.2110   0.0000
> 6    6   1 0.2500   0.0000
> 7   10   1 0.3000   0.0000
> 8   10   1 0.1050   0.0000
> 9    8   1 0.7000   0.1000
> 10   3   5 0.1176   0.0588
> 11   3   5 0.3077   0.1150
> 12   3   9 0.9090   0.0900
> 13   3   7 0.7778   0.1110
> 14   3   5 0.5560   0.1110
> 15   3   1 0.5710   0.0000
> 16   3   4 0.5710   0.0000
> 
> In order to do the multiple regression, I used the following coding:
> 
> 
> double=read.table("convis.txt",header=TRUE)
> attach(double)
> double
> stem(vis)
> stem(den)
> stem(avoid)
> stem(entrance)
> plot(entrance,vis*den)      *as means to see how the interaction

This is not an interaction, you just multiply vis and den and plot entrance on x axis and vis*den on y axis, so basically you want to model vis*den by entrance.

> between
> visibility and density may impact entrance behaviors
> model6=lm(entrance~vis*den)

This model is oposite of what you plotted.

> model6
> summary(model6)
> *abline(model6)      *Here is the issue as I used this for my simple
> linear
> regression technique, but do not know what to use for a multiple
> regression*

You seem to not understand how the multiple regression output and abline works.

Based on what you want you can do

plot(vis*den, entrance)
model6 <- lm(entrance~I(vis*den))
abline(model6)

however your model will have only intercept and one coefficient for variable x=vis*den

If you want to have separate coefficients for vis ***and*** den and their interaction you can use 

model6=lm(entrance~vis*den)

but in this case resulting coefficients are Intercept, vis, den and interaction between vis and den. In that case beside of other procedures for model evaluation you can do.

plot(entrance, fitted(model6))
abline(0,1)

Regards
Petr


> 
> If anybody can provide some feedback on this, it would be greatly
> appreciated.
> 
> Kind Regards,
> 
> Craig
> 
> --
> <><  <><  <><
> Craig O'Connell
> University of Massachusetts Dartmouth
> Marine Biologist
> www.youtube.com/craigpoconnell
> craigosea.blogspot.com
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list