Question

In: Math

*Please provide r studio code/file* 1) Find the equation of the best fit line using least...

*Please provide r studio code/file*

1) Find the equation of the best fit line using least squares
linear fit of x,y:
set.seed(88)
x <- 1:100
y <- jitter(1.5*x+8,amount=10)

2) For question 1, Draw the P=0.95 prediction intervals for y
when x=1:150

3) For question 1, Find the equation of the best fit line using
median-based linear fit of x,y.

4) For question 3, draw the P=0.95 prediction interval for y
# when x=1:150

Solutions

Expert Solution

The R script for problem 1-4 is given as------

# code for linear fit based on least square model....
set.seed(88)
x <- 1:100
y <- jitter(1.5*x+8,amount=10)

lm(y~x)
predict(lm(y ~ x))
newdata<-data.frame(x=seq(1,150,1))
m=pred.w.plim <- predict(lm(y ~ x), newdata, interval = "prediction",level=0.95)
m
# code for meadian basedfit----
# we have to install meadian based package------
install.packages("mblm")
library(mblm)
set.seed(88)
x <- 1:100
y <- jitter(1.5*x+8,amount=10)

mblm(y~x)
predict(mblm(y ~ x))
newdata=data.frame(x=seq(1,150,1))
m=pred.w.plim <- predict(lm(y ~ x), newdata, interval = "prediction",level=0.95)
m

Output-------------

> # code for linear fit based on least square model....
> set.seed(88)
> x <- 1:100
> y <- jitter(1.5*x+8,amount=10)

> lm(y~x)

Call:
lm(formula = y ~ x)

Coefficients:
(Intercept) x
9.103 1.484

> predict(lm(y ~ x))
1 2 3 4 5 6 7 8 9 10
10.58716 12.07165 13.55614 15.04063 16.52512 18.00961 19.49409 20.97858 22.46307 23.94756
11 12 13 14 15 16 17 18 19 20
25.43205 26.91654 28.40102 29.88551 31.37000 32.85449 34.33898 35.82347 37.30795 38.79244
21 22 23 24 25 26 27 28 29 30
40.27693 41.76142 43.24591 44.73040 46.21488 47.69937 49.18386 50.66835 52.15284 53.63733
31 32 33 34 35 36 37 38 39 40
55.12181 56.60630 58.09079 59.57528 61.05977 62.54426 64.02874 65.51323 66.99772 68.48221
41 42 43 44 45 46 47 48 49 50
69.96670 71.45119 72.93567 74.42016 75.90465 77.38914 78.87363 80.35812 81.84260 83.32709
51 52 53 54 55 56 57 58 59 60
84.81158 86.29607 87.78056 89.26505 90.74953 92.23402 93.71851 95.20300 96.68749 98.17198
61 62 63 64 65 66 67 68 69 70
99.65646 101.14095 102.62544 104.10993 105.59442 107.07891 108.56339 110.04788 111.53237 113.01686
71 72 73 74 75 76 77 78 79 80
114.50135 115.98584 117.47032 118.95481 120.43930 121.92379 123.40828 124.89277 126.37725 127.86174
81 82 83 84 85 86 87 88 89 90
129.34623 130.83072 132.31521 133.79970 135.28418 136.76867 138.25316 139.73765 141.22214 142.70663
91 92 93 94 95 96 97 98 99 100
144.19111 145.67560 147.16009 148.64458 150.12907 151.61356 153.09804 154.58253 156.06702 157.55151
> newdata<-data.frame(x=seq(1,150,1))
> m=pred.w.plim <- predict(lm(y ~ x), newdata, interval = "prediction",level=0.95)
> m
fit lwr upr
1 10.58716 -1.1518873 22.32622
2 12.07165 0.3392444 23.80406
3 13.55614 1.8302442 25.28204
4 15.04063 3.3211119 26.76015
5 16.52512 4.8118472 28.23839
6 18.00961 6.3024499 29.71676
7 19.49409 7.7929198 31.19527
8 20.97858 9.2832568 32.67391
9 22.46307 10.7734605 34.15268
10 23.94756 12.2635309 35.63159
11 25.43205 13.7534677 37.11063
12 26.91654 15.2432707 38.58980
13 28.40102 16.7329398 40.06911
14 29.88551 18.2224748 41.54855
15 31.37000 19.7118754 43.02813
16 32.85449 21.2011416 44.50784
17 34.33898 22.6902732 45.98768
18 35.82347 24.1792699 47.46766
19 37.30795 25.6681318 48.94778
20 38.79244 27.1568585 50.42803
21 40.27693 28.6454499 51.90841
22 41.76142 30.1339060 53.38893
23 43.24591 31.6222265 54.86959
24 44.73040 33.1104114 56.35038
25 46.21488 34.5984604 57.83131
26 47.69937 36.0863736 59.31237
27 49.18386 37.5741507 60.79357
28 50.66835 39.0617916 62.27491
29 52.15284 40.5492963 63.75638
30 53.63733 42.0366646 65.23799
31 55.12181 43.5238964 66.71973
32 56.60630 45.0109917 68.20161
33 58.09079 46.4979503 69.68363
34 59.57528 47.9847721 71.16579
35 61.05977 49.4714571 72.64808
36 62.54426 50.9580052 74.13051
37 64.02874 52.4444163 75.61307
38 65.51323 53.9306903 77.09577
39 66.99772 55.4168272 78.57861
40 68.48221 56.9028270 80.06159
41 69.96670 58.3886895 81.54471
42 71.45119 59.8744147 83.02796
43 72.93567 61.3600026 84.51135
44 74.42016 62.8454532 85.99487
45 75.90465 64.3307663 87.47854
46 77.38914 65.8159421 88.96234
47 78.87363 67.3009803 90.44627
48 80.35812 68.7858811 91.93035
49 81.84260 70.2706445 93.41456
50 83.32709 71.7552703 94.89891
51 84.81158 73.2397586 96.38340
52 86.29607 74.7241094 97.86803
53 87.78056 76.2083228 99.35279
54 89.26505 77.6923986 100.83769
55 90.74953 79.1763370 102.32273
56 92.23402 80.6601379 103.80791
57 93.71851 82.1438014 105.29322
58 95.20300 83.6273275 106.77867
59 96.68749 85.1107163 108.26426
60 98.17198 86.5939677 109.74998
61 99.65646 88.0770818 111.23585
62 101.14095 89.5600588 112.72185
63 102.62544 91.0428985 114.20798
64 104.10993 92.5256011 115.69426
65 105.59442 94.0081667 117.18067
66 107.07891 95.4905952 118.66722
67 108.56339 96.9728869 120.15390
68 110.04788 98.4550417 121.64072
69 111.53237 99.9370598 123.12768
70 113.01686 101.4189412 124.61478
71 114.50135 102.9006860 126.10201
72 115.98584 104.3822944 127.58938
73 117.47032 105.8637664 129.07688
74 118.95481 107.3451021 130.56452
75 120.43930 108.8263016 132.05230
76 121.92379 110.3073651 133.54021
77 123.40828 111.7882927 135.02826
78 124.89277 113.2690845 136.51645
79 126.37725 114.7497407 138.00477
80 127.86174 116.2302613 139.49322
81 129.34623 117.7106465 140.98181
82 130.83072 119.1908964 142.47054
83 132.31521 120.6710112 143.95940
84 133.79970 122.1509911 145.44840
85 135.28418 123.6308362 146.93753
86 136.76867 125.1105467 148.42680
87 138.25316 126.5901227 149.91620
88 139.73765 128.0695644 151.40573
89 141.22214 129.5488720 152.89540
90 142.70663 131.0280456 154.38521
91 144.19111 132.5070854 155.87514
92 145.67560 133.9859917 157.36521
93 147.16009 135.4647646 158.85542
94 148.64458 136.9434043 160.34575
95 150.12907 138.4219111 161.83622
96 151.61356 139.9002850 163.32683
97 153.09804 141.3785264 164.81756
98 154.58253 142.8566354 166.30843
99 156.06702 144.3346122 167.79943
100 157.55151 145.8124571 169.29056
101 159.03600 147.2901703 170.78182
102 160.52049 148.7677520 172.27322
103 162.00497 150.2452025 173.76475
104 163.48946 151.7225220 175.25640
105 164.97395 153.1997107 176.74819
106 166.45844 154.6767688 178.24011
107 167.94293 156.1536967 179.73216
108 169.42742 157.6304946 181.22434
109 170.91190 159.1071627 182.71664
110 172.39639 160.5837012 184.20908
111 173.88088 162.0601105 185.70165
112 175.36537 163.5363908 187.19435
113 176.84986 165.0125424 188.68717
114 178.33435 166.4885655 190.18013
115 179.81883 167.9644604 191.67321
116 181.30332 169.4402275 193.16642
117 182.78781 170.9158669 194.65975
118 184.27230 172.3913790 196.15322
119 185.75679 173.8667640 197.64681
120 187.24128 175.3420223 199.14053
121 188.72576 176.8171542 200.63437
122 190.21025 178.2921598 202.12834
123 191.69474 179.7670396 203.62244
124 193.17923 181.2417939 205.11666
125 194.66372 182.7164229 206.61101
126 196.14821 184.1909270 208.10548
127 197.63269 185.6653064 209.60008
128 199.11718 187.1395616 211.09480
129 200.60167 188.6136927 212.58965
130 202.08616 190.0877002 214.08462
131 203.57065 191.5615843 215.57971
132 205.05514 193.0353454 217.07493
133 206.53962 194.5089838 218.57026
134 208.02411 195.9824998 220.06572
135 209.50860 197.4558939 221.56131
136 210.99309 198.9291662 223.05701
137 212.47758 200.4023172 224.55284
138 213.96207 201.8753471 226.04878
139 215.44655 203.3482565 227.54485
140 216.93104 204.8210454 229.04104
141 218.41553 206.2937145 230.53735
142 219.90002 207.7662639 232.03377
143 221.38451 209.2386940 233.53032
144 222.86900 210.7110052 235.02699
145 224.35348 212.1831979 236.52377
146 225.83797 213.6552723 238.02067
147 227.32246 215.1272290 239.51769
148 228.80695 216.5990681 241.01483
149 230.29144 218.0707902 242.51208
150 231.77593 219.5423955 244.00945
> # code for meadian basedfit----
> # we have to install meadian based package------
> set.seed(88)
> x <- 1:100
> y <- jitter(1.5*x+8,amount=10)

> mblm(y~x)

Call:
mblm(formula = y ~ x)

Coefficients:
(Intercept) x
9.304 1.456

> predict(mblm(y ~ x))
1 2 3 4 5 6 7 8 9 10
10.75944 12.21500 13.67057 15.12614 16.58171 18.03728 19.49285 20.94842 22.40398 23.85955
11 12 13 14 15 16 17 18 19 20
25.31512 26.77069 28.22626 29.68183 31.13739 32.59296 34.04853 35.50410 36.95967 38.41524
21 22 23 24 25 26 27 28 29 30
39.87081 41.32637 42.78194 44.23751 45.69308 47.14865 48.60422 50.05978 51.51535 52.97092
31 32 33 34 35 36 37 38 39 40
54.42649 55.88206 57.33763 58.79320 60.24876 61.70433 63.15990 64.61547 66.07104 67.52661
41 42 43 44 45 46 47 48 49 50
68.98217 70.43774 71.89331 73.34888 74.80445 76.26002 77.71559 79.17115 80.62672 82.08229
51 52 53 54 55 56 57 58 59 60
83.53786 84.99343 86.44900 87.90456 89.36013 90.81570 92.27127 93.72684 95.18241 96.63798
61 62 63 64 65 66 67 68 69 70
98.09354 99.54911 101.00468 102.46025 103.91582 105.37139 106.82695 108.28252 109.73809 111.19366
71 72 73 74 75 76 77 78 79 80
112.64923 114.10480 115.56037 117.01593 118.47150 119.92707 121.38264 122.83821 124.29378 125.74934
81 82 83 84 85 86 87 88 89 90
127.20491 128.66048 130.11605 131.57162 133.02719 134.48276 135.93832 137.39389 138.84946 140.30503
91 92 93 94 95 96 97 98 99 100
141.76060 143.21617 144.67173 146.12730 147.58287 149.03844 150.49401 151.94958 153.40515 154.86071
> newdata=data.frame(x=seq(1,150,1))
> m=pred.w.plim <- predict(lm(y ~ x), newdata, interval = "prediction",level=0.95)
> m
fit lwr upr
1 10.58716 -1.1518873 22.32622
2 12.07165 0.3392444 23.80406
3 13.55614 1.8302442 25.28204
4 15.04063 3.3211119 26.76015
5 16.52512 4.8118472 28.23839
6 18.00961 6.3024499 29.71676
7 19.49409 7.7929198 31.19527
8 20.97858 9.2832568 32.67391
9 22.46307 10.7734605 34.15268
10 23.94756 12.2635309 35.63159
11 25.43205 13.7534677 37.11063
12 26.91654 15.2432707 38.58980
13 28.40102 16.7329398 40.06911
14 29.88551 18.2224748 41.54855
15 31.37000 19.7118754 43.02813
16 32.85449 21.2011416 44.50784
17 34.33898 22.6902732 45.98768
18 35.82347 24.1792699 47.46766
19 37.30795 25.6681318 48.94778
20 38.79244 27.1568585 50.42803
21 40.27693 28.6454499 51.90841
22 41.76142 30.1339060 53.38893
23 43.24591 31.6222265 54.86959
24 44.73040 33.1104114 56.35038
25 46.21488 34.5984604 57.83131
26 47.69937 36.0863736 59.31237
27 49.18386 37.5741507 60.79357
28 50.66835 39.0617916 62.27491
29 52.15284 40.5492963 63.75638
30 53.63733 42.0366646 65.23799
31 55.12181 43.5238964 66.71973
32 56.60630 45.0109917 68.20161
33 58.09079 46.4979503 69.68363
34 59.57528 47.9847721 71.16579
35 61.05977 49.4714571 72.64808
36 62.54426 50.9580052 74.13051
37 64.02874 52.4444163 75.61307
38 65.51323 53.9306903 77.09577
39 66.99772 55.4168272 78.57861
40 68.48221 56.9028270 80.06159
41 69.96670 58.3886895 81.54471
42 71.45119 59.8744147 83.02796
43 72.93567 61.3600026 84.51135
44 74.42016 62.8454532 85.99487
45 75.90465 64.3307663 87.47854
46 77.38914 65.8159421 88.96234
47 78.87363 67.3009803 90.44627
48 80.35812 68.7858811 91.93035
49 81.84260 70.2706445 93.41456
50 83.32709 71.7552703 94.89891
51 84.81158 73.2397586 96.38340
52 86.29607 74.7241094 97.86803
53 87.78056 76.2083228 99.35279
54 89.26505 77.6923986 100.83769
55 90.74953 79.1763370 102.32273
56 92.23402 80.6601379 103.80791
57 93.71851 82.1438014 105.29322
58 95.20300 83.6273275 106.77867
59 96.68749 85.1107163 108.26426
60 98.17198 86.5939677 109.74998
61 99.65646 88.0770818 111.23585
62 101.14095 89.5600588 112.72185
63 102.62544 91.0428985 114.20798
64 104.10993 92.5256011 115.69426
65 105.59442 94.0081667 117.18067
66 107.07891 95.4905952 118.66722
67 108.56339 96.9728869 120.15390
68 110.04788 98.4550417 121.64072
69 111.53237 99.9370598 123.12768
70 113.01686 101.4189412 124.61478
71 114.50135 102.9006860 126.10201
72 115.98584 104.3822944 127.58938
73 117.47032 105.8637664 129.07688
74 118.95481 107.3451021 130.56452
75 120.43930 108.8263016 132.05230
76 121.92379 110.3073651 133.54021
77 123.40828 111.7882927 135.02826
78 124.89277 113.2690845 136.51645
79 126.37725 114.7497407 138.00477
80 127.86174 116.2302613 139.49322
81 129.34623 117.7106465 140.98181
82 130.83072 119.1908964 142.47054
83 132.31521 120.6710112 143.95940
84 133.79970 122.1509911 145.44840
85 135.28418 123.6308362 146.93753
86 136.76867 125.1105467 148.42680
87 138.25316 126.5901227 149.91620
88 139.73765 128.0695644 151.40573
89 141.22214 129.5488720 152.89540
90 142.70663 131.0280456 154.38521
91 144.19111 132.5070854 155.87514
92 145.67560 133.9859917 157.36521
93 147.16009 135.4647646 158.85542
94 148.64458 136.9434043 160.34575
95 150.12907 138.4219111 161.83622
96 151.61356 139.9002850 163.32683
97 153.09804 141.3785264 164.81756
98 154.58253 142.8566354 166.30843
99 156.06702 144.3346122 167.79943
100 157.55151 145.8124571 169.29056
101 159.03600 147.2901703 170.78182
102 160.52049 148.7677520 172.27322
103 162.00497 150.2452025 173.76475
104 163.48946 151.7225220 175.25640
105 164.97395 153.1997107 176.74819
106 166.45844 154.6767688 178.24011
107 167.94293 156.1536967 179.73216
108 169.42742 157.6304946 181.22434
109 170.91190 159.1071627 182.71664
110 172.39639 160.5837012 184.20908
111 173.88088 162.0601105 185.70165
112 175.36537 163.5363908 187.19435
113 176.84986 165.0125424 188.68717
114 178.33435 166.4885655 190.18013
115 179.81883 167.9644604 191.67321
116 181.30332 169.4402275 193.16642
117 182.78781 170.9158669 194.65975
118 184.27230 172.3913790 196.15322
119 185.75679 173.8667640 197.64681
120 187.24128 175.3420223 199.14053
121 188.72576 176.8171542 200.63437
122 190.21025 178.2921598 202.12834
123 191.69474 179.7670396 203.62244
124 193.17923 181.2417939 205.11666
125 194.66372 182.7164229 206.61101
126 196.14821 184.1909270 208.10548
127 197.63269 185.6653064 209.60008
128 199.11718 187.1395616 211.09480
129 200.60167 188.6136927 212.58965
130 202.08616 190.0877002 214.08462
131 203.57065 191.5615843 215.57971
132 205.05514 193.0353454 217.07493
133 206.53962 194.5089838 218.57026
134 208.02411 195.9824998 220.06572
135 209.50860 197.4558939 221.56131
136 210.99309 198.9291662 223.05701
137 212.47758 200.4023172 224.55284
138 213.96207 201.8753471 226.04878
139 215.44655 203.3482565 227.54485
140 216.93104 204.8210454 229.04104
141 218.41553 206.2937145 230.53735
142 219.90002 207.7662639 232.03377
143 221.38451 209.2386940 233.53032
144 222.86900 210.7110052 235.02699
145 224.35348 212.1831979 236.52377
146 225.83797 213.6552723 238.02067
147 227.32246 215.1272290 239.51769
148 228.80695 216.5990681 241.01483
149 230.29144 218.0707902 242.51208
150 231.77593 219.5423955 244.00945

now you can extract all useful information from the output....


Related Solutions

*Please provide r studio file/code* Question: Test the equality of means of populations X,Y,Z using ANOVA:...
*Please provide r studio file/code* Question: Test the equality of means of populations X,Y,Z using ANOVA: set.seed(88) dta <- data.frame(v = c(2+2*rnorm(100), 3+3*rnorm(100), 4+4*rnorm(100)), id = rep(c("x","y","z"),c(100,100,100)))
Find the line of best fit. r = What is the SSE for this problem?
Movies 3 6 0 9 14 5 7 12 2 1 7 0 5 11 4 Books 7 0 18 0 1 4 5 0 6 2 10 9 2 2 0 Find the line of best fit. r = What is the SSE for this problem?
Find the linear regression equation (line of best fit), determine the correlation, and then make a...
Find the linear regression equation (line of best fit), determine the correlation, and then make a prediction. 1. The table below gives the amount of time students in a class studied for a test and their test scores. Graph the data on a scatter plot, find the line of best fit, and write the equation for the line you draw. Hours Studied 1 0 3 1.5 2.75 1 0.5 2 Test Score 78 75 90 89 97 85 81 80...
***This problem must be done using R so please provide the R code used to find...
***This problem must be done using R so please provide the R code used to find the solution. I have provided the data in data-wtLoss.txt below the question. I will also give "thumbs-up for correct R code" Thanks in advance.*** The file “data-wtLoss.txt” contains data on weight loss and self esteem evaluation at three time points over a period of three months for 34 individuals who are randomly selected from a residential area. These individuals are randomly assigned to one...
***This problem must be done using R so please provide the R code used to find...
***This problem must be done using R so please provide the R code used to find the solution. I have provided the data in data-wtLoss.txt below the question. I will also give "thumbs-up for correct R code" Thanks in advance.*** The file “data-wtLoss.txt” contains data on weight loss and self esteem evaluation at three time points over a period of three months for 34 individuals who are randomly selected from a residential area. These individuals are randomly assigned to one...
Plot the data and line of best fit in R and paste it into this document
C D 3 2 6 7 8 5 9 4 1 0 3 4 Plot the data and line of best fit in R and paste it into this document Code: Plot:
Solve following using Program R studio. Please show code and results. Thank you. 1. Assume that...
Solve following using Program R studio. Please show code and results. Thank you. 1. Assume that ? is a random variable follows binomial probability distribution with parameters 15 and 0.25.   a. Simulate 100 binomial pseudorandom numbers from the given distribution (using set.seed(200)) and assign them to vector called binran. b. Calculate ?(? < 8) using cumulative probability function. c. Calculate ?(? = 8) using probability distribution function. d. Calculate the average of simulated data and compare it with the corresponding...
Find the equation of the least-squares regression line ŷ and the linear correlation coefficient r for...
Find the equation of the least-squares regression line ŷ and the linear correlation coefficient r for the given data. Round the constants, a, b, and r, to the nearest hundredth. {(0, 10.8), (3, 11.3), (5, 11.2), (−4, 10.7), (1, 9.3)}
In R/ R Studio, what code would I enter to find the answers to these questions?...
In R/ R Studio, what code would I enter to find the answers to these questions? What is the code to find the descriptive/ summary statistics of all variables in a data set and how do i find the mean values? What is the code to measure the skewness measure of delta time for all of all the values in the data set? What is the code to draw a histogram and q-q plot of the natural log of a...
Using R-Studio please answer the following questions and show your code. 1. Julie buys a take-out...
Using R-Studio please answer the following questions and show your code. 1. Julie buys a take-out coffee from one of two coffee shops on a random basis: Ultimo Coffee and Joe’s Place. This month, she measured the temperature of each cup immediately after purchase, using a cooking thermometer. Sample data is shown below, temperatures are in Fahrenheit. ultimo =  c(171,161,169,179, 171,166,169,178,171, 165,172,172) joes = c(168,165,172, 151,162,158,157,160, 158,160,158,164) State the null and alternative hypothesis in your own words. What type of statistical...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT