0% found this document useful (0 votes)
51 views22 pages

Apurvareport

The document details a series of linear regression analyses performed on a dataset named 'trixdataap', focusing on the relationships between GDP, GB, and education (ED). Multiple models are created, including simple linear regressions and a multiple linear regression, with significant coefficients and high R-squared values indicating strong relationships. Additionally, diagnostic tests for model assumptions are conducted, and various transformations of the data are applied.

Uploaded by

Vanshika Agrawal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views22 pages

Apurvareport

The document details a series of linear regression analyses performed on a dataset named 'trixdataap', focusing on the relationships between GDP, GB, and education (ED). Multiple models are created, including simple linear regressions and a multiple linear regression, with significant coefficients and high R-squared values indicating strong relationships. Additionally, diagnostic tests for model assumptions are conducted, and various transformations of the data are applied.

Uploaded by

Vanshika Agrawal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

> View(trixdataap)

> attach(trixdataap)
> names(trixdataap)
[1] "gdp" "gb" "ed"
> plot(gb,ed,main="scatterplot")
> model<-lm(gb~gdp)
> summary(model)

Call:
lm(formula = gb ~ gdp)

Residuals:
Min 1Q Median 3Q Max
-58756 -21418 1015 20553 75134

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 3.389e+04 9.299e+03 3.645 0.00094 ***
gdp 1.401e+00 6.070e-02 23.079 < 2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 32570 on 32 degrees of freedom


Multiple R-squared: 0.9433, Adjusted R-squared: 0.9416
F-statistic: 532.7 on 1 and 32 DF, p-value: < 2.2e-16
> attributes(model)
$names
[1] "coefficients" "residuals" "effects" "rank" "fitt
ed.values" "assign" "qr"
[8] "df.residual" "xlevels" "call" "terms" "mode
l"

$class
[1] "lm"

> model$coefficients
(Intercept) gdp
33889.196597 1.400879
> plot(gb,eb,main="scatterplot")
Error: object 'eb' not found
> plot(gb,ed,main="scatterplot")
> abline(model)
> abline(model,col=2)
> abline(model,col=3,lwd=5)
> confint(model,level=0.99)
0.5 % 99.5 %
(Intercept) 8424.975808 59353.4174
gdp 1.234658 1.5671

> anova(model)
Analysis of Variance Table

Response: gb
Df Sum Sq Mean Sq F value Pr(>F)
gdp 1 5.6509e+11 5.6509e+11 532.66 < 2.2e-16 ***
Residuals 32 3.3948e+10 1.0609e+09
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> plot(gdp,ed,main="scatterplot")

abline(model)
> abline(model,col=2)
> abline(model,col=3,lwd=5)
> confint(model,level=0.99)
0.5 % 99.5 %
(Intercept) 8424.975808 59353.4174
gdp 1.234658 1.5671
> anova(model)
Analysis of Variance Table

Response: gb
Df Sum Sq Mean Sq F value Pr(>F)
gdp 1 5.6509e+11 5.6509e+11 532.66 < 2.2e-16 ***
Residuals 32 3.3948e+10 1.0609e+09
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> modeltwo<-lm(gdp~ed)
> summary(modeltwo)

Call:
lm(formula = gdp ~ ed)

Residuals:
Min 1Q Median 3Q Max
-35405 -13536 -6295 8045 47072

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 2.800e+04 4.911e+03 5.701 2.59e-06 ***
ed 5.477e-02 2.061e-03 26.571 < 2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 19750 on 32 degrees of freedom


Multiple R-squared: 0.9566, Adjusted R-squared: 0.9553
F-statistic: 706 on 1 and 32 DF, p-value: < 2.2e-16
> attributes(modeltwo)
$names
[1] "coefficients" "residuals" "effects" "rank" "fitt
ed.values" "assign" "qr"
[8] "df.residual" "xlevels" "call" "terms" "mode
l"

$class
[1] "lm"

> model$coefficients
(Intercept) gdp
33889.196597 1.400879
> modeltwo$coefficients
(Intercept) ed
2.799590e+04 5.476692e-02
MULTILINEAR
> model<-lm(gdp+gb~ed)
> summary(model)

Call:
lm(formula = gdp + gb ~ ed)

Residuals:
Min 1Q Median 3Q Max
-75032 -28373 3886 26176 55714

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 9.651e+04 8.896e+03 10.85 2.98e-12 ***
ed 1.342e-01 3.734e-03 35.93 < 2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 35780 on 32 degrees of freedom


Multiple R-squared: 0.9758, Adjusted R-squared: 0.9751
F-statistic: 1291 on 1 and 32 DF, p-value: < 2.2e-16

> confint(model,level=0.99)
0.5 % 99.5 %
(Intercept) 7.214898e+04 1.208745e+05
ed 1.239258e-01 1.443758e-01
> anova(model)
Analysis of Variance Table

Response: gdp + gb
Df Sum Sq Mean Sq F value Pr(>F)
ed 1 1.6528e+12 1.6528e+12 1290.9 < 2.2e-16 ***
Residuals 32 4.0972e+10 1.2804e+09
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

> predicted_value<-predict(model)
> trixdataap$predicted_y<-predicted_value
> residuals<-residuals(model)
> trixdataap$residuals<-residuals
hist(residuals)
logy<-log(ed)
> trixdataap$logy<-logy
> logx1<-log(gdp)
> trixdataap$logx1<-logx1
> logx2<-log(gb)
> trixdataap$logx2<-logx2
> logmodel=lm(formula=logy~logx1+logx2,data=trixdataap)
> logmodel

Call:
lm(formula = logy ~ logx1 + logx2, data = trixdataap)

Coefficients:
(Intercept) logx1 logx2
-2.9611 0.6659 0.7662

> summary(logmodel)

Call:
lm(formula = logy ~ logx1 + logx2, data = trixdataap)

Residuals:
Min 1Q Median 3Q Max
-0.27240 -0.11768 -0.02842 0.14019 0.24657

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -2.9611 0.6765 -4.377 0.000127 ***
logx1 0.6659 0.1050 6.342 4.65e-07 ***
logx2 0.7662 0.1430 5.360 7.65e-06 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.1559 on 31 degrees of freedom


Multiple R-squared: 0.9805, Adjusted R-squared: 0.9793
F-statistic: 780.1 on 2 and 31 DF, p-value: < 2.2e-16

> attributes(logmodel)
$names
[1] "coefficients" "residuals" "effects" "rank" "fitt
ed.values" "assign" "qr"
[8] "df.residual" "xlevels" "call" "terms" "mode
l"

$class
[1] "lm"
> pred_y<-predict(model)
> trixdataap$pred_y
NULL
Warning message:
Unknown or uninitialised column: `pred_y`.
> trixdataap$haty<-pred_y
> pred_logy<-predict(logmodel)
> trixdataap$hatlny<-pred_logy
> trixdataap$ln_haty<-log(trixdataap$haty)
> trixdataap$z1<-trixdataap$ln_haty-trixdataap$hatlny
> model2<-lm(ed~gdp+gb+trixdataap$z1)
> summary(model2)

Call:
lm(formula = ed ~ gdp + gb + trixdataap$z1)

Residuals:
Min 1Q Median 3Q Max
-422202 -90940 7833 31899 535105

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -48859.243 132588.636 -0.369 0.715
gdp 11.479 1.714 6.699 2.01e-07 ***
gb 6.378 1.072 5.951 1.60e-06 ***
trixdataap$z1 700167.518 131882.671 5.309 9.73e-06 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 195400 on 30 degrees of freedom


Multiple R-squared: 0.9875, Adjusted R-squared: 0.9863
F-statistic: 791.8 on 3 and 30 DF, p-value: < 2.2e-16
> trixdataap$antilog_hatlny<-exp(trixdataap$hatlny)
> trixdataap$z2<-trixdataap$antilog_hatlny-trixdataap$haty
> model3<-lm(trixdataap$logy~trixdataap$logx1+trixdataap$logx2+trixdataap$
z2)
> summary(model3)

Call:
lm(formula = trixdataap$logy ~ trixdataap$logx1 + trixdataap$logx2 +
trixdataap$z2)
Residuals:
Min 1Q Median 3Q Max
-0.26135 -0.10803 -0.03487 0.13318 0.27059

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -1.804e+00 1.280e+00 -1.409 0.168992
trixdataap$logx1 6.665e-01 1.048e-01 6.361 5.1e-07 ***
trixdataap$logx2 6.638e-01 1.721e-01 3.857 0.000565 ***
trixdataap$z2 5.058e-08 4.756e-08 1.064 0.295999
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.1556 on 30 degrees of freedom


Multiple R-squared: 0.9812, Adjusted R-squared: 0.9793
F-statistic: 522.7 on 3 and 30 DF, p-value: < 2.2e-16
> install.packages("lmtest")
WARNING: Rtools is required to build R packages but is not currently insta
lled. Please download and install the appropriate version of Rtools before
proceeding:

https://cran.rstudio.com/bin/windows/Rtools/
Installing package into ‘C:/Users/HP/AppData/Local/R/win-library/4.4’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/lmtest_0.9-40
.zip'
Content type 'application/zip' length 411446 bytes (401 KB)
downloaded 401 KB

package ‘lmtest’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in


C:\Users\HP\AppData\Local\Temp\RtmpOuWpqe\downloaded_packages
> library(lmtest)
Loading required package: zoo

Attaching package: ‘zoo’

The following objects are masked from ‘package:base’:

as.Date, as.Date.numeric

Warning message:
package ‘lmtest’ was built under R version 4.4.3
> bptest(model)

studentized Breusch-Pagan test

data: model
BP = 2.5669, df = 1, p-value = 0.1091
dwtest(model)

Durbin-Watson test

data: model
DW = 0.48078, p-value = 6.115e-09
alternative hypothesis: true autocorrelation is greater than 0

> install.packages("car")
WARNING: Rtools is required to build R packages but is not currently insta
lled. Please download and install the appropriate version of Rtools before
proceeding:

https://cran.rstudio.com/bin/windows/Rtools/
Installing package into ‘C:/Users/HP/AppData/Local/R/win-library/4.4’
(as ‘lib’ is unspecified)
also installing the dependencies ‘rbibutils’, ‘cowplot’, ‘Deriv’, ‘microbe
nchmark’, ‘Rdpack’, ‘numDeriv’, ‘doBy’, ‘SparseM’, ‘MatrixModels’, ‘minqa’
, ‘nloptr’, ‘reformulas’, ‘RcppEigen’, ‘carData’, ‘abind’, ‘Formula’, ‘pbk
rtest’, ‘quantreg’, ‘lme4’

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/rbibutils_2.3


.zip'
Content type 'application/zip' length 1032620 bytes (1008 KB)
downloaded 1008 KB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/cowplot_1.1.3


.zip'
Content type 'application/zip' length 1380990 bytes (1.3 MB)
downloaded 1.3 MB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/Deriv_4.1.6.z


ip'
Content type 'application/zip' length 152058 bytes (148 KB)
downloaded 148 KB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/microbenchmar


k_1.5.0.zip'
Content type 'application/zip' length 73680 bytes (71 KB)
downloaded 71 KB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/Rdpack_2.6.4.


zip'
Content type 'application/zip' length 641259 bytes (626 KB)
downloaded 626 KB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/numDeriv_2016


.8-1.1.zip'
Content type 'application/zip' length 117304 bytes (114 KB)
downloaded 114 KB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/doBy_4.6.26.z


ip'
Content type 'application/zip' length 4888715 bytes (4.7 MB)
downloaded 4.7 MB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/SparseM_1.84-


2.zip'
Content type 'application/zip' length 887351 bytes (866 KB)
downloaded 866 KB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/MatrixModels_


0.5-4.zip'
Content type 'application/zip' length 408229 bytes (398 KB)
downloaded 398 KB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/minqa_1.2.8.z


ip'
Content type 'application/zip' length 441955 bytes (431 KB)
downloaded 431 KB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/nloptr_2.2.1.


zip'
Content type 'application/zip' length 886472 bytes (865 KB)
downloaded 865 KB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/reformulas_0.


4.0.zip'
Content type 'application/zip' length 94840 bytes (92 KB)
downloaded 92 KB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/RcppEigen_0.3


.4.0.2.zip'
Content type 'application/zip' length 2592471 bytes (2.5 MB)
downloaded 2.5 MB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/carData_3.0-5


.zip'
Content type 'application/zip' length 1708112 bytes (1.6 MB)
downloaded 1.6 MB
trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/abind_1.4-8.z
ip'
Content type 'application/zip' length 67211 bytes (65 KB)
downloaded 65 KB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/Formula_1.2-5


.zip'
Content type 'application/zip' length 161370 bytes (157 KB)
downloaded 157 KB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/pbkrtest_0.5.


3.zip'
Content type 'application/zip' length 186280 bytes (181 KB)
downloaded 181 KB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/quantreg_6.1.


zip'
Content type 'application/zip' length 1474272 bytes (1.4 MB)
downloaded 1.4 MB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/lme4_1.1-37.z


ip'
Content type 'application/zip' length 4566642 bytes (4.4 MB)
downloaded 4.4 MB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/car_3.1-3.zip


'
Content type 'application/zip' length 1542575 bytes (1.5 MB)
downloaded 1.5 MB

package ‘rbibutils’ successfully unpacked and MD5 sums checked


package ‘cowplot’ successfully unpacked and MD5 sums checked
package ‘Deriv’ successfully unpacked and MD5 sums checked
package ‘microbenchmark’ successfully unpacked and MD5 sums checked
package ‘Rdpack’ successfully unpacked and MD5 sums checked
package ‘numDeriv’ successfully unpacked and MD5 sums checked
package ‘doBy’ successfully unpacked and MD5 sums checked
package ‘SparseM’ successfully unpacked and MD5 sums checked
package ‘MatrixModels’ successfully unpacked and MD5 sums checked
package ‘minqa’ successfully unpacked and MD5 sums checked
package ‘nloptr’ successfully unpacked and MD5 sums checked
package ‘reformulas’ successfully unpacked and MD5 sums checked
package ‘RcppEigen’ successfully unpacked and MD5 sums checked
package ‘carData’ successfully unpacked and MD5 sums checked
package ‘abind’ successfully unpacked and MD5 sums checked
package ‘Formula’ successfully unpacked and MD5 sums checked
package ‘pbkrtest’ successfully unpacked and MD5 sums checked
package ‘quantreg’ successfully unpacked and MD5 sums checked
package ‘lme4’ successfully unpacked and MD5 sums checked
package ‘car’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in


C:\Users\HP\AppData\Local\Temp\RtmpOuWpqe\downloaded_packages
> library(car)
Loading required package: carData
Warning messages:
1: package ‘car’ was built under R version 4.4.3
2: package ‘carData’ was built under R version 4.4.3
>vif(model)
gdp gb
22.144629 18.023133

You might also like