comment: sisa atau residu atau eror dari regresinya bersifat acak
Berikut merupakan hasil input dan outputnya
Input:
#masukkan data menjadi vector x dan vector y
x<-
c(17.3,19.3,19.5,19.7,22.9,23.1,26.4,26.8,27.6,28.1,28.2,28.7,29.0,29.6,29.9,29.9,30.3,31.3,36.0,39.5,40.4,44.
3,44.6,50.4,55.9)
y<-
c(71.7,48.3,88.3,75.0,91.7,100.0,73.3,65.0,75.0,88.3,68.3,96.7,76.7,78.3,60.0,71.7,85.0,85.0,88.3,100.0,100.0
,100.0,91.7,100.0,71.7)
#prepare plot
plot(x,y,col="blue",main="Regresi Arm Strength and Dynamic Lift",
abline(lm(y~x)),cex=1.3,pch=16,xlab="Arm Strength",ylab="Dynamic Lift")
Output:
#masukkan data menjadi vector x dan vector y
> x<-
c(17.3,19.3,19.5,19.7,22.9,23.1,26.4,26.8,27.6,28.1,28.2,28.7,29.0,29.6,29.9,29.9,30.3,31.3,36.0,39.5,40.4,44.
3,44.6,50.4,55.9)
> y<-
c(71.7,48.3,88.3,75.0,91.7,100.0,73.3,65.0,75.0,88.3,68.3,96.7,76.7,78.3,60.0,71.7,85.0,85.0,88.3,100.0,100.0
,100.0,91.7,100.0,71.7)
>
> #memeriksa data kembali
> mydata=data.frame(x,y)
> View(mydata)
> str(mydata)
'data.frame': 25 obs. of 2 variables:
$ x: num 17.3 19.3 19.5 19.7 22.9 23.1 26.4 26.8 27.6 28.1 ...
$ y: num 71.7 48.3 88.3 75 91.7 100 73.3 65 75 88.3 ...
>
> # gunakan rumus linear model (disingkat lm): menyatakan formula antara x & y adalah regresi linear
y=b0+b1x dgn b0=intercept & b1=slope(kemiringan)
> pers_regresi<-lm(y~x)
> print(pers_regresi)
Call:
lm(formula = y ~ x)
Coefficients:
(Intercept) x
64.5292 0.5609
>
> #untuk mengeluarkan hasil uji t untuk parameter b0 & b1
> print(summary(pers_regresi))
Call:
lm(formula = y ~ x)
Residuals:
Min 1Q Median 3Q Max
-27.055 -6.037 2.155 10.623 22.514
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 64.5292 8.9599 7.202 2.48e-07 ***
x 0.5609 0.2747 2.042 0.0528 .
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
(c). Estimate the amount of chemical that will dissolve in 100 grams of water at 50◦C.
Nur Hafizah Soal Bernomor Ganjil
112009400000013 Tugas Linear Regresi
Jadi berdasarkan output diatas perkiraan banyaknya zat kimia yang akan larut dalam 100
gram air pada suhu 50◦C. adalah
estimasi nilai untuk x = 50:
𝑦̂ = 5.8254 + 0.5676 (50) = 34.2054
Dan interpolasi nilai untuk x = 100:
𝑦̂ = 5.8254 + 0.5676(100) = 62.58730
# gunakan rumus linear model (disingkat lm): menyatakan formula antara x & y adalah regresi linear
y=b0+b1x dgn b0=intercept & b1=slope(kemiringan)
pers_regresi<-lm(y~x)
print(pers_regresi)
#hasil prediksi
predict_result<-predict(pers_regresi,x_test)
print(predict_result)
#prepare plot
plot(x,y,col="blue",main="Regresi ◦C and grams",
abline(lm(y~x)),cex=1.3,pch=16,xlab="◦C",ylab="grams")
Output:
> library(car)
> library(stats)
> #masukkan data menjadi vector x dan vector y
> x<-c(0,0,0,15,15,15,30,30,30,45,45,45,60,60,60,75,75,75)
> y<-c(8,6,8,12,10,14,25,21,24,31,33,28,44,39,42,48,51,44)
>
> #memeriksa data kembali
> mydata=data.frame(x,y)
> View(mydata)
> str(mydata)
'data.frame': 18 obs. of 2 variables:
$ x: num 0 0 0 15 15 15 30 30 30 45 ...
$ y: num 8 6 8 12 10 14 25 21 24 31 ...
>
> # gunakan rumus linear model (disingkat lm): menyatakan formula antara x & y adalah regresi linear
y=b0+b1x dgn b0=intercept & b1=slope(kemiringan)
> pers_regresi<-lm(y~x)
> print(pers_regresi)
Call:
Nur Hafizah Soal Bernomor Ganjil
112009400000013 Tugas Linear Regresi
lm(formula = y ~ x)
Coefficients:
(Intercept) x
5.8254 0.5676
>
> #untuk mengeluarkan hasil uji t untuk parameter b0 & b1
> print(summary(pers_regresi))
Call:
lm(formula = y ~ x)
Residuals:
Min 1Q Median 3Q Max
-4.3968 -1.6111 -0.0825 2.1389 4.1175
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 5.82540 1.07497 5.419 5.68e-05 ***
x 0.56762 0.02367 23.980 5.73e-14 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
>
> #data yang akan diprediksi
> x_test<-data.frame(x=c(50,100))
>
> #hasil prediksi
> predict_result<-predict(pers_regresi,x_test)
> print(predict_result)
1 2
34.20635 62.58730
>
> #prepare plot
> plot(x,y,col="blue",main="Regresi ◦C and grams",
+ abline(lm(y~x)),cex=1.3,pch=16,xlab="◦C",ylab="grams")
Berdasarkan hasil output di atas maka estimasi garis regresi linearnya adalah
𝑦̂ = 6.4136 + 1.8091x
Nur Hafizah Soal Bernomor Ganjil
112009400000013 Tugas Linear Regresi
(b). Estimate the mean amount of converted sugar produced when the coded temperature
is 1.75.
Perkiraan jumlah gula yang dikonversi pada suhu 1,75 dengan menggunakan R adalah
𝑦̂ = 6.4136 + 1.8091(1.75) = 9.5795
comment: sisa atau residu atau eror dari regresinya bersifat tidak acak
Input :
#masukkan data menjadi vector x dan vector y
x<-c(1.0,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,2.0)
y<-c(8.1,7.8,8.5,9.8,9.5,8.9,8.6,10.2,9.3,9.2,10.5)
# gunakan rumus linear model (disingkat lm): menyatakan formula antara x & y adalah regresi linear
y=b0+b1x dgn b0=intercept & b1=slope(kemiringan)
pers_regresi<-lm(y~x)
print(pers_regresi)
#hasil prediksi
predict_result<-predict(pers_regresi,x_test)
print(predict_result)
Nur Hafizah Soal Bernomor Ganjil
112009400000013 Tugas Linear Regresi
#prepare plot
plot(x,y,col="blue",main="Regresi Temperture and Converted Sugar",
abline(lm(y~x)),cex=1.3,pch=16,xlab="Temperature",ylab="Converted Sugar")
Output:
#masukkan data menjadi vector x dan vector y
> x<-c(1.0,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,2.0)
> y<-c(8.1,7.8,8.5,9.8,9.5,8.9,8.6,10.2,9.3,9.2,10.5)
>
> #memeriksa data kembali
> mydata=data.frame(x,y)
> View(mydata)
> str(mydata)
'data.frame': 11 obs. of 2 variables:
$ x: num 1 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 ...
$ y: num 8.1 7.8 8.5 9.8 9.5 8.9 8.6 10.2 9.3 9.2 ...
>
> # gunakan rumus linear model (disingkat lm): menyatakan formula antara x & y adalah regresi linear
y=b0+b1x dgn b0=intercept & b1=slope(kemiringan)
> pers_regresi<-lm(y~x)
> print(pers_regresi)
Call:
lm(formula = y ~ x)
Coefficients:
(Intercept) x
6.414 1.809
>
> #untuk mengeluarkan hasil uji t untuk parameter b0 & b1
> print(summary(pers_regresi))
Call:
lm(formula = y ~ x)
Residuals:
Min 1Q Median 3Q Max
-0.7082 -0.4868 -0.1227 0.5109 1.0346
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 6.4136 0.9246 6.936 6.79e-05 ***
x 1.8091 0.6032 2.999 0.015 *
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
>
> #data yang akan diprediksi
> x_test<-data.frame(x=1.75)
>
> #hasil prediksi
> predict_result<-predict(pers_regresi,x_test)
> print(predict_result)
1
9.579545
>
> #prepare plot
Nur Hafizah Soal Bernomor Ganjil
112009400000013 Tugas Linear Regresi
> plot(x,y,col="blue",main="Regresi Temperture and Converted Sugar",
+ abline(lm(y~x)),cex=1.3,pch=16,xlab="Temperature",ylab="Converted Sugar")
>
7. a. Plot the data; does it appear that a simple linear regression will be a suitable model?
Berdasarkan plot datanya, dengan regresi linier sederhana akan menjadi model yang cocok
untuk digunakan
b. Fit a simple linear regression; estimate a slope and intercept
# gunakan rumus linear model (disingkat lm): menyatakan formula antara x & y adalah regresi linear
y=b0+b1x dgn b0=intercept & b1=slope(kemiringan)
pers_regresi<-lm(y~x)
print(pers_regresi)
#prepare plot
plot(x,y,col="blue",main="Regresi Organic Acid Content Produced by Extraction and Weighing and Acid
Content of Material Produced by Titration ",
abline(lm(y~x)),cex=1.3,pch=16,xlab="Organic Acid Content Produced by Extraction and
Weighing",ylab="Acid Content of Material Produced by Titration")
Output:
#masukkan data menjadi vector x dan vector y
> x<-c(76,62,66,58,88,70,37,82,88,43)
> y<-c(123,55,100,75,159,109,48,138,164,28)
>
> #memeriksa data kembali
> mydata=data.frame(x,y)
> View(mydata)
> str(mydata)
'data.frame': 10 obs. of 2 variables:
$ x: num 76 62 66 58 88 70 37 82 88 43
$ y: num 123 55 100 75 159 109 48 138 164 28
>
> # gunakan rumus linear model (disingkat lm): menyatakan formula antara x & y adalah regresi linear
y=b0+b1x dgn b0=intercept & b1=slope(kemiringan)
> pers_regresi<-lm(y~x)
> print(pers_regresi)
Call:
lm(formula = y ~ x)
Coefficients:
(Intercept) x
-71.818 2.563
>
> #untuk mengeluarkan hasil uji t untuk parameter b0 & b1
> print(summary(pers_regresi))
Call:
lm(formula = y ~ x)
Residuals:
Min 1Q Median 3Q Max
-32.085 -1.461 0.722 4.624 24.988
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -71.8176 20.2223 -3.551 0.00749 **
x 2.5629 0.2929 8.750 2.28e-05 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
>
> #prepare plot
> plot(x,y,col="blue",main="Regresi Organic Acid Content Produced by Extraction and Weighing and Acid
Content of Material Produced by Titration ",
+ abline(lm(y~x)),cex=1.3,pch=16,xlab="Organic Acid Content Produced by Extraction and
Weighing",ylab="Acid Content of Material Produced by Titration")
Nur Hafizah Soal Bernomor Ganjil
112009400000013 Tugas Linear Regresi
9. (a) Plot a scatter diagram.
(b) Find the equation of the regression line to predict weekly sales from advertising
expenditures.
Jadi berdasarkan output di atas persamaan garis regresi untuk memprediksi penjualan
mingguan dari pengeluaran iklan yang didapat adalah
𝑦̂ = 343.706 + 3.221𝑥
(c) Estimate the weekly sales when advertising costs are $35.
comment: sisa atau residu atau eror dari regresinya bersifat acak
Input:
#masukkan data menjadi vector x dan vector y
x<-c(40,20,25,20,30,50,40,20,50,40,25,50)
y<-c(385,400,395,365,475,440,490,420,560,525,480,510)
# gunakan rumus linear model (disingkat lm): menyatakan formula antara x & y adalah regresi linear
y=b0+b1x dgn b0=intercept & b1=slope(kemiringan)
pers_regresi<-lm(y~x)
print(pers_regresi)
#hasil prediksi
predict_result<-predict(pers_regresi,x_test)
print(predict_result)
#prepare plot
plot(x,y,col="blue",main="Regresi Advertising Costs and Sales",
abline(lm(y~x)),cex=1.3,pch=16,xlab="Advertising Costs ($)",ylab="Sales ($)")
Output:
> #masukkan data menjadi vector x dan vector y
> x<-c(40,20,25,20,30,50,40,20,50,40,25,50)
> y<-c(385,400,395,365,475,440,490,420,560,525,480,510)
>
> #memeriksa data kembali
> mydata=data.frame(x,y)
Nur Hafizah Soal Bernomor Ganjil
112009400000013 Tugas Linear Regresi
> View(mydata)
> str(mydata)
'data.frame': 12 obs. of 2 variables:
$ x: num 40 20 25 20 30 50 40 20 50 40 ...
$ y: num 385 400 395 365 475 440 490 420 560 525 ...
>
> # gunakan rumus linear model (disingkat lm): menyatakan formula antara x & y adalah regresi linear
y=b0+b1x dgn b0=intercept & b1=slope(kemiringan)
> pers_regresi<-lm(y~x)
> print(pers_regresi)
Call:
lm(formula = y ~ x)
Coefficients:
(Intercept) x
343.706 3.221
>
> #untuk mengeluarkan hasil uji t untuk parameter b0 & b1
> print(summary(pers_regresi))
Call:
lm(formula = y ~ x)
Residuals:
Min 1Q Median 3Q Max
-87.538 -32.700 8.566 39.118 55.774
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 343.706 44.766 7.678 1.68e-05 ***
x 3.221 1.240 2.598 0.0266 *
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
>
> #data yang akan diprediksi
> x_test<-data.frame(x=35)
>
> #hasil prediksi
> predict_result<-predict(pers_regresi,x_test)
> print(predict_result)
1
456.434
>
> #prepare plot
> plot(x,y,col="blue",main="Regresi Advertising Costs and Sales",
+ abline(lm(y~x)),cex=1.3,pch=16,xlab="Advertising Costs ($)",ylab="Sales ($)")
Nur Hafizah Soal Bernomor Ganjil
112009400000013 Tugas Linear Regresi
11. (a). Plot the data.
(b) Fit a simple linear regression to the data and plot the line through the data.
Berdasarkan Regresi linier sederhana dengan data dan plot garis melalui data di atas dapat
disimpulkan bahwa:
Persamaan garis regresinya adalah 𝑦̂ = −1847.633 + 3.653𝑥, selain itu dari plot garis
yang diatas dapat dilihat sisa atau residu atau eror dari regresinya bersifat tidak acak
Input:
#masukkan data menjadi vector x dan vector y
x<-c(1760,1652,1485,1390,1820,1665,1550,1700,1270)
y<-c(4300,4650,3200,3150,4950,4010,3810,4500,3008)
# gunakan rumus linear model (disingkat lm): menyatakan formula antara x & y adalah regresi linear
y=b0+b1x dgn b0=intercept & b1=slope(kemiringan)
pers_regresi<-lm(y~x)
print(pers_regresi)
Nur Hafizah Soal Bernomor Ganjil
112009400000013 Tugas Linear Regresi
#prepare plot
plot(x,y,col="blue",main="Regresi The Thrust of an Engine and Function of Exhaust Temperature in ◦F",
abline(lm(y~x)),cex=1.3,pch=16,xlab="Function of Exhaust Temperature in ◦F",ylab="The Thrust of an
Engine")
Output:
> #masukkan data menjadi vector x dan vector y
> x<-c(1760,1652,1485,1390,1820,1665,1550,1700,1270)
> y<-c(4300,4650,3200,3150,4950,4010,3810,4500,3008)
>
> #memeriksa data kembali
> mydata=data.frame(x,y)
> View(mydata)
> str(mydata)
'data.frame': 9 obs. of 2 variables:
$ x: num 1760 1652 1485 1390 1820 ...
$ y: num 4300 4650 3200 3150 4950 ...
>
> # gunakan rumus linear model (disingkat lm): menyatakan formula antara x & y adalah regresi linear
y=b0+b1x dgn b0=intercept & b1=slope(kemiringan)
> pers_regresi<-lm(y~x)
> print(pers_regresi)
Call:
lm(formula = y ~ x)
Coefficients:
(Intercept) x
-1847.633 3.653
>
> #untuk mengeluarkan hasil uji t untuk parameter b0 & b1
> print(summary(pers_regresi))
Call:
lm(formula = y ~ x)
Residuals:
Min 1Q Median 3Q Max
-376.9 -224.4 -4.3 149.4 463.1
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -1847.6330 904.8743 -2.042 0.080491 .
x 3.6529 0.5666 6.447 0.000351 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
>
> #prepare plot
> plot(x,y,col="blue",main="Regresi The Thrust of an Engine and Function of Exhaust Temperature in ◦F",
+ abline(lm(y~x)),cex=1.3,pch=16,xlab="Function of Exhaust Temperature in ◦F",ylab="The Thrust of an
Engine")
Nur Hafizah Soal Bernomor Ganjil
112009400000013 Tugas Linear Regresi
13. (a) Find the equation of the regression line to predict the particulate removed from the
amount of daily rainfall.
Jadi berdasarkan output yang diatas persamaan garis regresi untuk memprediksi partikel
yang dihilangkan adalah 𝑦̂ = 153.175 + (−6.324𝑥)
(b) Estimate the amount of particulate removed when the daily rainfall is x =4.8 units.
Perkirakan jumlah partikulat yang dihilangkan ketika curah hujan harian saat x= 4.8 unit
adalah 𝑦̂ = 153.175 + (−6.324𝑥) = 122.8204
# gunakan rumus linear model (disingkat lm): menyatakan formula antara x & y adalah regresi linear
y=b0+b1x dgn b0=intercept & b1=slope(kemiringan)
pers_regresi<-lm(y~x)
print(pers_regresi)
#hasil prediksi
predict_result<-predict(pers_regresi,x_test)
print(predict_result)
#prepare plot
plot(x,y,col="blue",main="Regresi Daily Rainfall and Particulate Removed",
abline(lm(y~x)),cex=1.3,pch=16,xlab="Daily Rainfall(0.01 cm)",ylab=" Particulate Removed (μg/m3)")
Output:
> #masukkan data menjadi vector x dan vector y
> x<-c(4.3,4.5,5.9,5.6,6.1,5.2,3.8,2.1,7.5)
> y<-c(126,121,116,118,114,118,132,141,108)
>
> #memeriksa data kembali
> mydata=data.frame(x,y)
> View(mydata)
> str(mydata)
'data.frame': 9 obs. of 2 variables:
$ x: num 4.3 4.5 5.9 5.6 6.1 5.2 3.8 2.1 7.5
$ y: num 126 121 116 118 114 118 132 141 108
>
> # gunakan rumus linear model (disingkat lm): menyatakan formula antara x & y adalah regresi linear
y=b0+b1x dgn b0=intercept & b1=slope(kemiringan)
> pers_regresi<-lm(y~x)
> print(pers_regresi)
Call:
lm(formula = y ~ x)
Coefficients:
(Intercept) x
153.175 -6.324
>
> #untuk mengeluarkan hasil uji t untuk parameter b0 & b1
> print(summary(pers_regresi))
Call:
lm(formula = y ~ x)
Residuals:
Min 1Q Median 3Q Max
-3.7175 -0.5992 0.1360 1.1049 2.8557
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 153.1755 2.6147 58.58 1.11e-10 ***
x -6.3240 0.5019 -12.60 4.58e-06 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
>
> #data yang akan diprediksi
> x_test<-data.frame(x=4.8)
>
> #hasil prediksi
Nur Hafizah Soal Bernomor Ganjil
112009400000013 Tugas Linear Regresi
> predict_result<-predict(pers_regresi,x_test)
> print(predict_result)
1
122.8204
>
> #prepare plot
> plot(x,y,col="blue",main="Regresi Daily Rainfall and Particulate Removed",
+ abline(lm(y~x)),cex=1.3,pch=16,xlab="Daily Rainfall(0.01 cm)",ylab=" Particulate Removed (μg/m3)")