# Simple Linear Regression in R

I have answered all of the following questions I need someone to verify me or if there is a better approach I would like to know about.

Q1) Look at your model summary to find the x variable whose model coefficient is most significantly different from 0. (You don't have to write R code to find this other variable–just read your model summary.)
Q2) Make a simple linear regression model for PBE vs. this x.
Q3) Make a scatterplot of PBE vs. this x.
Q5) Include a reasonable title and axis labels.

A0) beeflm = lm(PBE ~., data=beef)

A1) (coef(beeflm))
(Intercept)          YEAR           CBE
2693.01348650   -1.28693774   -1.84919910
PPO           CPO           PFO
-0.99901169   -1.73045916    1.27410503
DINC           CFO         RDINC
-2.49792219    1.04485422    1.32154103
RFP
-0.01729997

A2) PBEvsDINC = lm(PBE~DINC, data=beef)

A3,A5) plot(beef$PBE, beef$DINC, main="Beef PBE vs DINC", xlab="DINC", ylab="PBE")
(Am I right?)
Error in plot.new() : figure margins too large

A4) abline(PBEvsDINC)


And finally here's the question I don't know the answer:

Q: Are the coefficients (y-intercept and slope in the x direction) the same for this second simple linear regression model as they are in the first multiple regression model?

Here's the data for beef data.frame:

YEAR    PBE     CBE     PPO     CPO     PFO     DINC    CFO     RDINC   RFP
1925    59.7    58.6    60.5    65.8    65.8    51.4    90.9    68.5     877
1926    59.7    59.4    63.3    63.3      68    52.6    92.1    69.6     899
1927      63    53.7    59.9    66.8    65.5    52.1    90.9    70.2     883
1928      71    48.1    56.3    69.9    64.8    52.7    90.9    71.9     884
1929      71      49      55    68.7    65.6    55.1    91.1    75.2     895
1930    74.2    48.2    59.6    66.1    62.4    48.8    90.7    68.3     874
1931    72.1    47.9      57    67.4    51.4    41.5      90      64     791
1932      79      46    49.5    69.7    42.8    31.4    87.8    53.9     733
1933    73.1    50.8    47.3    68.7    41.6    29.4      88    53.2     752
1934    70.2    55.2    56.6    62.2    46.4    33.2    89.1      58     811
1935    82.2    52.2    73.9    47.7    49.7      37    87.3    63.2     847
1936    68.4    57.3    64.4    54.4    50.1    41.8    90.5    70.5     845
1937      73    54.4    62.2      55    52.1    44.5    90.4    72.5     849
1938    70.2    53.6    59.9    57.4    48.4    40.8    90.6    67.8     803
1939    67.8    53.9      51    63.9    47.1    43.5    93.8    73.2     793
1940    63.4    54.2    41.5    72.4    47.8    46.5    95.5    77.6     798


## 1941 56 60 43.9 67.4 52.2 56.3 97.5 89.5 830

Here is the t-value results, so is CBE the most significant variable according to this?:

summary(lm(formula = PBE ~ ., data = beef))

Call:
lm(formula = PBE ~ ., data = beef)
Residuals:
Min 1Q Median 3Q Max
-1.1986 -0.5658 -0.1001 0.7067 1.3251
Coefficients:
Estimate Std. Error t value
(Intercept) 2693.0135 1337.9523 2.013
YEAR -1.2869 0.6970 -1.846
CBE -1.8492 0.2834 -6.525
PPO -0.9990 0.4051 -2.466
CPO -1.7305 0.5685 -3.044
PFO 1.2741 1.9645 0.649
DINC -2.4979 2.6018 -0.960
CFO 1.0449 1.0678 0.979
RDINC 1.3215 1.7117 0.772
RFP -0.0173 0.1131 -0.153
Pr(>|t|)
(Intercept) 0.084020 .
YEAR 0.107337
CBE 0.000326 ***
PPO 0.043064 *
CPO 0.018743 *
PFO 0.537314
DINC 0.368995
CFO 0.360411
RDINC 0.465337
RFP 0.882717
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 1.238 on 7 degrees of freedom
Multiple R-squared: 0.986, Adjusted R-squared: 0.968
F-statistic: 54.77 on 9 and 7 DF, p-value: 1.165e-05

• Re: Q!, just because a particular variable has the largest raw coefficient does not necessarily mean it is the most significant variable. Feb 19, 2014 at 3:25
• @gung so DINC isn't the one I should have selected? I thought it's the one which has the most difference from zero! Can you tell me which one is the one with most difference with 0? Feb 19, 2014 at 3:30
• Mona, the question doesn't say 'most different'. The word you left out of your comment implies something other than what you did. Feb 19, 2014 at 3:35
• It may or may not be. I don't know. The fact that the coefficient is furthest from 0 does not necessarily mean that it is the most significantly different from 0. Those are two different things. Also, please learn our policy regarding HW ([self-study]) questions. We do not do your HW for you or give you answers. We provide hints only. Please read the wiki for [self-study] to learn more. Feb 19, 2014 at 3:37
• "most different" means what you did. The inclusion of the qualifier 'significantly' implies the person asking the question is looking for which one is the most standard errors from zero, or which one has the lowest p-value. Feb 19, 2014 at 4:20

Salam Mona:

A1)

>beef=read.table("C:/.../beef.txt",header=T)
>attach(beef)
> beeflm = lm(PBE ~., data=beef)
> summary(beeflm)

Call:
lm(formula = PBE ~ ., data = beef)

Residuals:
Min      1Q  Median      3Q     Max
-1.1637 -0.3655 -0.1406  0.6686  1.0238

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 2613.5927  1211.6305   2.157 0.074375 .
YEAR          -1.2285     0.6317  -1.945 0.099794 .
CBE           -1.8901     0.2577  -7.335 0.000328 ***
PPO           -1.1175     0.3739  -2.988 0.024369 *
CPO           -1.6758     0.5155  -3.251 0.017452 *
PFO            4.6485     2.7613   1.683 0.143276
DINC          -6.8875     3.6191  -1.903 0.105716
CFO            0.4570     1.0339   0.442 0.673989
RDINC          4.0028     2.2843   1.752 0.130269
RFP           -0.1926     0.1501  -1.283 0.246658
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 1.12 on 6 degrees of freedom
Multiple R-squared:  0.9871,    Adjusted R-squared:  0.9678
F-statistic: 51.12 on 9 and 6 DF,  p-value: 5.528e-05


If you look at the p-values for the t-test, you will see three stars for the CBE variable. It means that, taking into account other variables in the model, the CBE is the most significant variable at $\alpha=0.001$ confidence level. See the Signif. codes: below the table. There are no other variables that are even significant at 1%.

A2)

> m2=lm(PBE ~CBE, data=beef)
> summary(m2)

Call:
lm(formula = PBE ~ CBE, data = beef)

Residuals:
Min      1Q  Median      3Q     Max
-5.7529 -3.1370 -0.6019  2.2417 11.8345

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 126.4851    15.8134   7.999 1.37e-06 ***
CBE          -1.0751     0.2995  -3.590  0.00296 **
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 4.663 on 14 degrees of freedom
Multiple R-squared:  0.4793,    Adjusted R-squared:  0.4421
F-statistic: 12.89 on 1 and 14 DF,  p-value: 0.002959


A3) & A5)

> plot(CBE,PBE,xlab="CBE",ylab="PBE",main="Beef PBE vs CBE with the fitted line")


A4)

> points(CBE,fitted(m2),type="l")


To answer your last question ... First let me denote the true slope and intercept parametesr (for CBE) in the simple regression model by $\beta_1$ and $\beta_0$, respectively. The corresponding estimates for $\beta_1$ and $\beta_0$ in the multiple regression model are -1.8901 and 2613.5927. Basically, you need to test $H_0: \beta_1=-1.8901$ vs $H1: \beta_1\neq-1.8901$ and $H_0: \beta_0=2613.5927$ vs $H1: \beta_0\neq2613.5927$. I will give you a hint, you need to use the t-test and the standard errors reported in the simple regression model.

• I think this might be creeping a tad beyond the 'helpful hints' of the guidelines for self-study questions. More specifically "Try to provide explanations that will lead the asker in the correct direction" and "use pseudo-code and general descriptions first" rather than "a complete solution (or code sample)" Feb 19, 2014 at 5:26
• I think YEAR is the most significant one not the CBE Feb 19, 2014 at 5:41
• I know those stuff ... She had some programing problems AND she asked a question. The parts I provided are mainly the programing issues. I decided to answer them. But I gave the hint for the last question that no one discussed.
– Stat
Feb 19, 2014 at 6:02
• Mona, that is not correct. Look at the p-values. The smallest one is for the CBE with ***. For the Year, the p-value is 0.099794 and you see a single dot (.) in front of the p-value. It means that Year is significant at 0.01.
– Stat
Feb 19, 2014 at 6:07
> summary(beeflm)

Call:
lm(formula = PBE ~ ., data = beef)

Residuals:
Min       1Q   Median       3Q      Max
-1.49670 -0.30821 -0.07606  0.33081  1.07739

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 128.88641   57.63454   2.236   0.0557 .
YEAR         -0.62475    0.07986  -7.823 5.13e-05 ***
CBE          -0.37246    0.20821  -1.789   0.1114
PPO          -0.72692    0.22410  -3.244   0.0118 *
CPO           0.24804    1.48960   0.167   0.8719
PFO          -0.33435    1.92641  -0.174   0.8665
DINC          0.27685    0.61652   0.449   0.6653
CFO          -0.06465    1.26185  -0.051   0.9604
RDINCRFP      0.01873    0.08524   0.220   0.8316
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.9378 on 8 degrees of freedom
Multiple R-squared: 0.976,  Adjusted R-squared: 0.952
F-statistic: 40.66 on 8 and 8 DF,  p-value: 1.096e-05


for YEAR there are * assigned, and it's most significant

• you do not have the same predictors in the model (one less), possibly omitted RDINC? Apr 24, 2014 at 1:08