Question

Using R program:

Read and try out the list of comments and examples in Appendix A: A Sample Session in the An Introduction to R textbook. Then solve the following exercises in R. Use the help function if needed in the increments of 1.Generate a vector a between 0 and 100 Create a vector b with 100 pseudo-random numbers in it Plot a on the x-axis and b on the y-axis. Make a data frame of two columns a and b (name it MyDataFrame) and take a look at it. Fit a linear regression and look at the analysis. Finally, find the following values and discuss each of these, what they exactly mean: intercept, slo pe, multipleR-squared, p-value.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

(1) v<-c(seq(0,100,by=1))
v

Output:

 [1]   0   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17
 [19]  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35
 [37]  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53
 [55]  54  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71
 [73]  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89
 [91]  90  91  92  93  94  95  96  97  98  99 100

(2) ran<-rnorm(0:100,1)
ran

Output

[1] -0.53495685 -0.24373323  1.31657584  1.00558529  0.28038424  0.34730961
  [7]  1.14099536  0.64072055  0.80377016  2.21045220  1.46040008  0.84849428
 [13]  1.33270406  0.87970318  0.29624966  0.74263297  1.49633990  1.67960338
 [19]  1.80338846  1.45623291  2.13783741  3.00656117  2.00605910  1.60006928
 [25]  1.86253096 -0.40638285  1.20140449 -0.16857857 -0.32947635  1.93762760
 [31] -0.17648530  1.36924966  1.14769197 -0.20453337  2.80605836  1.37364098
 [37]  1.70842826  3.12633697  0.76043287 -0.59209954 -0.43453385  2.30675858
 [43]  0.15251603  1.11336177  1.79280456 -0.10608356 -0.87673978  0.39047266
 [49]  1.78946565  1.96439288  2.29568322  0.92615957  1.59795803 -0.20228123
 [55]  0.55708277  0.05796782  1.82184022  0.03222094  1.68642988  0.48935721
 [61] -0.68757384  0.65357894  3.53941629  1.68050831  1.08991455  3.03918246
 [67]  1.93064867  0.52797877  0.38071749  0.32118442  1.67685945 -0.24300160
 [73]  1.28086226  1.92172099  1.69516517  0.93769908 -0.01763943  2.72495364
 [79]  0.05501530 -0.20930529  1.73086980 -0.20961432 -0.29131153  1.54367171
 [85]  0.82833553  1.24370782  1.73894409  0.53129399 -0.88819535 -0.75305281
 [91]  0.45867582  0.25136691  1.82595202  1.16638303  1.18087097  0.71385253
 [97]  1.38949585  1.04752367  0.96417356  0.70869635  1.43773887

(3) g_range<-range(0,v,ran)
plot(v,type='o',col="blue",ylim=g_range)

Output

(4) MyDataFrame<-data.frame(v,ran)
MyDataFrame

Output:

      v         ran
1     0 -0.53495685
2     1 -0.24373323
3     2  1.31657584
4     3  1.00558529
5     4  0.28038424
6     5  0.34730961
7     6  1.14099536
8     7  0.64072055
9     8  0.80377016
10    9  2.21045220
11   10  1.46040008
12   11  0.84849428
13   12  1.33270406
14   13  0.87970318
15   14  0.29624966
16   15  0.74263297
17   16  1.49633990
18   17  1.67960338
19   18  1.80338846
20   19  1.45623291
21   20  2.13783741
22   21  3.00656117
23   22  2.00605910
24   23  1.60006928
25   24  1.86253096
26   25 -0.40638285
27   26  1.20140449
28   27 -0.16857857
29   28 -0.32947635
30   29  1.93762760
31   30 -0.17648530
32   31  1.36924966
33   32  1.14769197
34   33 -0.20453337
35   34  2.80605836
36   35  1.37364098
37   36  1.70842826
38   37  3.12633697
39   38  0.76043287
40   39 -0.59209954
41   40 -0.43453385
42   41  2.30675858
43   42  0.15251603
44   43  1.11336177
45   44  1.79280456
46   45 -0.10608356
47   46 -0.87673978
48   47  0.39047266
49   48  1.78946565
50   49  1.96439288
51   50  2.29568322
52   51  0.92615957
53   52  1.59795803
54   53 -0.20228123
55   54  0.55708277
56   55  0.05796782
57   56  1.82184022
58   57  0.03222094
59   58  1.68642988
60   59  0.48935721
61   60 -0.68757384
62   61  0.65357894
63   62  3.53941629
64   63  1.68050831
65   64  1.08991455
66   65  3.03918246
67   66  1.93064867
68   67  0.52797877
69   68  0.38071749
70   69  0.32118442
71   70  1.67685945
72   71 -0.24300160
73   72  1.28086226
74   73  1.92172099
75   74  1.69516517
76   75  0.93769908
77   76 -0.01763943
78   77  2.72495364
79   78  0.05501530
80   79 -0.20930529
81   80  1.73086980
82   81 -0.20961432
83   82 -0.29131153
84   83  1.54367171
85   84  0.82833553
86   85  1.24370782
87   86  1.73894409
88   87  0.53129399
89   88 -0.88819535
90   89 -0.75305281
91   90  0.45867582
92   91  0.25136691
93   92  1.82595202
94   93  1.16638303
95   94  1.18087097
96   95  0.71385253
97   96  1.38949585
98   97  1.04752367
99   98  0.96417356
100  99  0.70869635
101 100  1.43773887

(5) relation<-lm(ran~v)
print(summary(relation))

Output:

Call:
lm(formula = ran ~ v)

Residuals:
     Min       1Q   Median       3Q      Max 
-1.86795 -0.75128  0.07938  0.71922  2.57636 

Coefficients:
             Estimate Std. Error t value Pr(>|t|)    
(Intercept)  1.072172   0.192801   5.561 2.28e-07 ***
v           -0.001760   0.003331  -0.528    0.598    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.976 on 99 degrees of freedom
Multiple R-squared:  0.002812,  Adjusted R-squared:  -0.007261 
F-statistic: 0.2792 on 1 and 99 DF,  p-value: 0.5984
Add a comment
Know the answer?
Add Answer to:
Using R program: Read and try out the list of comments and examples in Appendix A:...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT