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

2013-02-14 Thread Greg Snow
The abline function works fine for simple linear regression because there
is only 1 line, but with multiple linear regression there are an infinite
number of lines and you need to decide which to plot (or find a way to plot
t he plane/hyperplane/surface/etc.).

One option is to use the Predict.Plot and TkPredict functions in the
TeachingDemos package.  These will plot the relationship between the
response and 1 of the predictors conditioned on values of the other
predictors.


On Wed, Feb 13, 2013 at 3:02 PM, Craig O'Connell
wrote:

> 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.   0.
> 2   10   3 0.8750   0.
> 38   3 0.8180   0.0300
> 48   3 0.6670   0.0667
> 58   1 0.2110   0.
> 66   1 0.2500   0.
> 7   10   1 0.3000   0.
> 8   10   1 0.1050   0.
> 98   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.
> 16   3   4 0.5710   0.
>
> 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 between
> visibility and density may impact entrance behaviors
> model6=lm(entrance~vis*den)
> 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*
>
> 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@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.
>



-- 
Gregory (Greg) L. Snow Ph.D.
538...@gmail.com

[[alternative HTML version deleted]]

__
R-help@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.


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

2013-02-14 Thread PIKAL Petr
Hi

> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> project.org] On Behalf Of Craig O'Connell
> Sent: Wednesday, February 13, 2013 11:03 PM
> To: r-help@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.   0.
> 2   10   3 0.8750   0.
> 38   3 0.8180   0.0300
> 48   3 0.6670   0.0667
> 58   1 0.2110   0.
> 66   1 0.2500   0.
> 7   10   1 0.3000   0.
> 8   10   1 0.1050   0.
> 98   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.
> 16   3   4 0.5710   0.
> 
> 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@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.

__
R-help@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.


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

2013-02-13 Thread Craig O'Connell
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.   0.
2   10   3 0.8750   0.
38   3 0.8180   0.0300
48   3 0.6670   0.0667
58   1 0.2110   0.
66   1 0.2500   0.
7   10   1 0.3000   0.
8   10   1 0.1050   0.
98   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.
16   3   4 0.5710   0.

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 between
visibility and density may impact entrance behaviors
model6=lm(entrance~vis*den)
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*

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@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.