proj 3.R

Scott Callahan — Dec 11, 2013, 11:57 AM

### Solutions for the various kinds of bad behavior in data:




# nonconstant error variance

# non-normal error distribution

# model using wrong predictors

# collinearity of predictors

ltrdata10 <- read.csv("~/Group_project-figure/ltrdata10.csv")
options(show.signif.stars=FALSE, digits=3)

ltrdata10$GDP <-log(ltrdata10$GDP)

ltrdata10$MOBILE <-log(ltrdata10$MOBILE)




View(ltrdata10)

row.names(ltrdata10) <- ltrdata10$Country.Name

ltrdata10$Country.Name <- NULL

ltrdata10$Region <- factor(ltrdata10$Region)

str(ltrdata10)
'data.frame':   95 obs. of  14 variables:
 $ Country : Factor w/ 95 levels "Angola","Antigua and Barbuda",..: 1 2 3 4 5 6 7 8 9 10 ...
 $ Region  : Factor w/ 8 levels "AF","AS","AU",..: 1 4 8 5 4 6 2 5 1 8 ...
 $ LTR     : num  0.701 0.99 0.978 0.996 0.968 0.919 0.568 0.979 0.845 0.904 ...
 $ GDP     : num  8.35 9.47 9.12 8.05 10.1 ...
 $ UNEMP   : num  0.25 0.11 0.077 0.19 0.069 0.037 0.045 0.272 0.178 0.067 ...
 $ SPGDP   : num  0.035 0.025 0.058 0.032 0.069 0.029 0.022 0 0.078 0.058 ...
 $ HTEXM   : num  0 0 0.075 0.018 0.033 0.001 0.012 0.026 0.004 0.112 ...
 $ HTEXD   : num  0 0 1648290 3760 561 ...
 $ URBGR   : num  0.048 0.006 0.011 -0.002 0.003 0.05 0.027 0.008 0.021 0.012 ...
 $ GINI    : num  42.7 NA 44.5 31.3 NA ...
 $ MOBILE  : num  3.84 5.24 4.89 4.83 4.81 ...
 $ INTERNET: num  10 80 45 25 62 ...
 $ WMPOL   : num  0.386 0.105 0.385 0.092 0 0.025 0.186 0.167 0.079 0.086 ...
 $ LEXP    : num  50.7 75.3 73.1 74.2 75 ...

levels(ltrdata10$Region) <- c("Africa", "Asia", "Oceanic", "C. America", "Europe","Mid. East", "N. America", "S. America")

summary(ltrdata10$Region)
    Africa       Asia    Oceanic C. America     Europe  Mid. East 
        17         15          4         12         29          9 
N. America S. America 
         3          6 




## Locate all 0's in the data set and set them to NA

ltrdata10[ltrdata10 == 0] <- NA

summary (ltrdata10)
                Country          Region        LTR             GDP       
 Angola             : 1   Europe    :29   Min.   :0.311   Min.   : 5.35  
 Antigua and Barbuda: 1   Africa    :17   1st Qu.:0.846   1st Qu.: 7.83  
 Argentina          : 1   Asia      :15   Median :0.947   Median : 8.80  
 Armenia            : 1   C. America:12   Mean   :0.887   Mean   : 8.71  
 Aruba              : 1   Mid. East : 9   3rd Qu.:0.990   3rd Qu.: 9.74  
 Bahrain            : 1   S. America: 6   Max.   :0.999   Max.   :11.20  
 (Other)            :89   (Other)   : 7                                  
     UNEMP           SPGDP          HTEXM          HTEXD         
 Min.   :0.002   Min.   :0.01   Min.   :0.00   Min.   :5.00e+01  
 1st Qu.:0.050   1st Qu.:0.03   1st Qu.:0.02   1st Qu.:9.62e+03  
 Median :0.084   Median :0.05   Median :0.06   Median :1.39e+05  
 Mean   :0.111   Mean   :0.05   Mean   :0.09   Mean   :1.82e+07  
 3rd Qu.:0.146   3rd Qu.:0.06   3rd Qu.:0.11   3rd Qu.:5.19e+06  
 Max.   :0.512   Max.   :0.11   Max.   :0.50   Max.   :4.06e+08  
                 NA's   :16     NA's   :15     NA's   :14        
     URBGR              GINI          MOBILE        INTERNET   
 Min.   :-0.0150   Min.   :24.2   Min.   :2.89   Min.   : 0.2  
 1st Qu.: 0.0065   1st Qu.:32.8   1st Qu.:4.27   1st Qu.:11.6  
 Median : 0.0180   Median :37.6   Median :4.63   Median :31.6  
 Mean   : 0.0205   Mean   :40.0   Mean   :4.49   Mean   :36.8  
 3rd Qu.: 0.0300   3rd Qu.:45.7   3rd Qu.:4.82   3rd Qu.:55.6  
 Max.   : 0.1150   Max.   :65.0   Max.   :5.24   Max.   :90.7  
                   NA's   :6                                   
     WMPOL           LEXP     
 Min.   :0.00   Min.   :46.4  
 1st Qu.:0.10   1st Qu.:67.1  
 Median :0.17   Median :73.5  
 Mean   :0.19   Mean   :70.9  
 3rd Qu.:0.24   3rd Qu.:76.6  
 Max.   :0.45   Max.   :82.8  
 NA's   :6                    

## Checking for nonconstant variance of errors







g <- lm(LTR~GDP+UNEMP+ URBGR + MOBILE + LEXP  , ltrdata10)

summary(g)

Call:
lm(formula = LTR ~ GDP + UNEMP + URBGR + MOBILE + LEXP, data = ltrdata10)

Residuals:
    Min      1Q  Median      3Q     Max 
-0.3358 -0.0402  0.0008  0.0334  0.2035 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)
(Intercept) -0.13939    0.11518   -1.21  0.22940
GDP          0.02100    0.01034    2.03  0.04531
UNEMP        0.24867    0.11122    2.24  0.02786
URBGR       -1.21459    0.52967   -2.29  0.02420
MOBILE       0.10561    0.02619    4.03  0.00012
LEXP         0.00518    0.00167    3.11  0.00252

Residual standard error: 0.0883 on 89 degrees of freedom
Multiple R-squared:  0.66,  Adjusted R-squared:  0.641 
F-statistic: 34.6 on 5 and 89 DF,  p-value: <2e-16




# Residual Plots




# Plot for detecting nonconstant variance and nonlinear departures from model

par(mfrow=c(1,1))

plot(fitted(g), residuals(g), xlab="Fitted", ylab="Residuals")

abline(h=0)

plot of chunk unnamed-chunk-1





#Ceres Polt

library(car)
Warning: package 'car' was built under R version 3.0.2

ceresPlots(g, terms= ~ . - type)

plot of chunk unnamed-chunk-1





# A better plot for detecting nonconstant variance

plot(fitted(g), abs(residuals(g)), xlab="Fitted", ylab="|Residuals|")

plot of chunk unnamed-chunk-1


par(mfrow=c(1,1))




# An approximate test of noncontant variance

summary(lm(abs(residuals(g)) ~ fitted(g)))

Call:
lm(formula = abs(residuals(g)) ~ fitted(g))

Residuals:
    Min      1Q  Median      3Q     Max 
-0.0991 -0.0312 -0.0139  0.0226  0.2139 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)
(Intercept)   0.2887     0.0409    7.05  3.1e-10
fitted(g)    -0.2578     0.0457   -5.64  1.8e-07

Residual standard error: 0.0531 on 93 degrees of freedom
Multiple R-squared:  0.255, Adjusted R-squared:  0.247 
F-statistic: 31.8 on 1 and 93 DF,  p-value: 1.85e-07

# Checking if nonconstant variance is related to a predictor

par(mfrow=c(1,1))

plot(ltrdata10$GDP, residuals(g), xlab="GDP", ylab="Residuals")

plot of chunk unnamed-chunk-1


plot(ltrdata10$URBGR, residuals(g), xlab="Urban Growth", ylab="Residuals")

plot of chunk unnamed-chunk-1


plot(ltrdata10$UNEMP, residuals(g), xlab="Unemployment", ylab="Residuals")

plot of chunk unnamed-chunk-1


plot(ltrdata10$MOBILE, residuals(g), xlab="Mobile Subscribers", ylab="Residuals")

plot of chunk unnamed-chunk-1


plot(ltrdata10$LEXP, residuals(g), xlab="Life Expectancy", ylab="Residuals")

plot of chunk unnamed-chunk-1


par(mfrow=c(1,1))




# An F test for nonconstant error variance between two groups defined by a predictor

var.test(residuals(g)[ltrdata10$UNEMP>.05], residuals(g)[ltrdata10$UNEMP<.05])

    F test to compare two variances

data:  residuals(g)[ltrdata10$UNEMP > 0.05] and residuals(g)[ltrdata10$UNEMP < 0.05]
F = 0.548, num df = 69, denom df = 22, p-value = 0.06192
alternative hypothesis: true ratio of variances is not equal to 1
95 percent confidence interval:
 0.258 1.030
sample estimates:
ratio of variances 
             0.548 

var.test(residuals(g)[ltrdata10$GDP>8], residuals(g)[ltrdata10$GDP<8])

    F test to compare two variances

data:  residuals(g)[ltrdata10$GDP > 8] and residuals(g)[ltrdata10$GDP < 8]
F = 0.228, num df = 64, denom df = 29, p-value = 8.593e-07
alternative hypothesis: true ratio of variances is not equal to 1
95 percent confidence interval:
 0.117 0.413
sample estimates:
ratio of variances 
             0.228 

var.test(residuals(g)[ltrdata10$URBGR>.039], residuals(g)[ltrdata10$URBGR<.039])

    F test to compare two variances

data:  residuals(g)[ltrdata10$URBGR > 0.039] and residuals(g)[ltrdata10$URBGR < 0.039]
F = 2.32, num df = 12, denom df = 81, p-value = 0.02642
alternative hypothesis: true ratio of variances is not equal to 1
95 percent confidence interval:
 1.10 6.54
sample estimates:
ratio of variances 
              2.32 

var.test(residuals(g)[ltrdata10$MOBILE>4.5], residuals(g)[ltrdata10$MOBILE<4.5])

    F test to compare two variances

data:  residuals(g)[ltrdata10$MOBILE > 4.5] and residuals(g)[ltrdata10$MOBILE < 4.5]
F = 0.18, num df = 57, denom df = 36, p-value = 1.099e-08
alternative hypothesis: true ratio of variances is not equal to 1
95 percent confidence interval:
 0.0971 0.3212
sample estimates:
ratio of variances 
              0.18 

var.test(residuals(g)[ltrdata10$LEXP>65], residuals(g)[ltrdata10$LEXP<65])

    F test to compare two variances

data:  residuals(g)[ltrdata10$LEXP > 65] and residuals(g)[ltrdata10$LEXP < 65]
F = 0.387, num df = 75, denom df = 18, p-value = 0.004416
alternative hypothesis: true ratio of variances is not equal to 1
95 percent confidence interval:
 0.169 0.749
sample estimates:
ratio of variances 
             0.387 




# A variance stabilizing transformation

gg <- lm(LTR ~ GDP +UNEMP +URBGR + MOBILE + LEXP , ltrdata10)

gs <- lm((LTR)^2 ~  GDP +UNEMP+URBGR + MOBILE + LEXP , ltrdata10)

ge <- lm(log(LTR) ~  GDP +UNEMP+URBGR + MOBILE + LEXP , ltrdata10)

gr <- lm(sqrt(LTR) ~  GDP +UNEMP+URBGR + MOBILE + LEXP , ltrdata10)

par(mfrow=c(1,1))

plot(fitted(gg), residuals(gg), xlab="Fitted", ylab="Residuals")

plot of chunk unnamed-chunk-1


plot(fitted(ge), residuals(ge), xlab="Fitted (Log)", ylab="Residuals")

plot of chunk unnamed-chunk-1


plot(fitted(gr), residuals(gr), xlab="Fitted (Square-Root)", ylab="Residuals")

plot of chunk unnamed-chunk-1


plot(fitted(gs), residuals(gs), xlab="Fitted (Squared)", ylab="Residuals")

plot of chunk unnamed-chunk-1


spread.level.plot(g)
Warning: 'spread.level.plot' is deprecated. Use 'spreadLevelPlot' instead.
See help("Deprecated") and help("car-deprecated").

plot of chunk unnamed-chunk-1


Suggested power transformation:  4.41 




par(mfrow=c(1,1))

gB <- lm((LTR)^4.57~GDP+UNEMP+ URBGR + MOBILE + LEXP  , ltrdata10)

summary(g); summary(gB)

Call:
lm(formula = (LTR)^4.57 ~ GDP + UNEMP + URBGR + MOBILE + LEXP, 
    data = ltrdata10)

Residuals:
    Min      1Q  Median      3Q     Max 
-0.4093 -0.1023 -0.0082  0.0841  0.5107 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)
(Intercept) -1.17186    0.24248   -4.83  5.6e-06
GDP          0.06025    0.02178    2.77  0.00688
UNEMP        0.29579    0.23414    1.26  0.20978
URBGR       -4.20610    1.11509   -3.77  0.00029
MOBILE       0.16951    0.05513    3.07  0.00280
LEXP         0.00877    0.00351    2.50  0.01430

Residual standard error: 0.186 on 89 degrees of freedom
Multiple R-squared:  0.665, Adjusted R-squared:  0.646 
F-statistic: 35.3 on 5 and 89 DF,  p-value: <2e-16

plot(fitted(gB), residuals(gB), xlab="Fitted (Suggested)", ylab="Residuals")

abline(h=0)

plot of chunk unnamed-chunk-1


a <- model.matrix(~LTR+GDP +UNEMP +URBGR + MOBILE + LEXP , ltrdata10)

cor(a)
Warning: the standard deviation is zero
            (Intercept)     LTR    GDP   UNEMP   URBGR MOBILE   LEXP
(Intercept)           1      NA     NA      NA      NA     NA     NA
LTR                  NA  1.0000  0.676 -0.0766 -0.4710  0.700  0.681
GDP                  NA  0.6757  1.000 -0.1896 -0.2976  0.674  0.703
UNEMP                NA -0.0766 -0.190  1.0000 -0.0577 -0.239 -0.380
URBGR                NA -0.4710 -0.298 -0.0577  1.0000 -0.325 -0.403
MOBILE               NA  0.7000  0.674 -0.2390 -0.3253  1.000  0.625
LEXP                 NA  0.6810  0.703 -0.3797 -0.4029  0.625  1.000

b <- model.matrix(~(LTR)^2 + GDP +UNEMP +URBGR + MOBILE + LEXP , ltrdata10)

cor(b)
Warning: the standard deviation is zero
            (Intercept)     LTR    GDP   UNEMP   URBGR MOBILE   LEXP
(Intercept)           1      NA     NA      NA      NA     NA     NA
LTR                  NA  1.0000  0.676 -0.0766 -0.4710  0.700  0.681
GDP                  NA  0.6757  1.000 -0.1896 -0.2976  0.674  0.703
UNEMP                NA -0.0766 -0.190  1.0000 -0.0577 -0.239 -0.380
URBGR                NA -0.4710 -0.298 -0.0577  1.0000 -0.325 -0.403
MOBILE               NA  0.7000  0.674 -0.2390 -0.3253  1.000  0.625
LEXP                 NA  0.6810  0.703 -0.3797 -0.4029  0.625  1.000

## Checking for non-normal errors




# QQ-plots for detecting nonnormality

par(mfrow=c(1,2))

qqnorm(residuals(g), ylab="Residuals")

qqline(residuals(g)) 

qqnorm(residuals(gB), ylab="Residuals")

qqline(residuals(gB)) 

plot of chunk unnamed-chunk-1





# The histogram is not suitable for detecting nonnormality



par(mfrow=c(1,1))

hist(residuals(g))

plot of chunk unnamed-chunk-1





#Non Constant Variance Test

ncvTest(g)
Non-constant Variance Score Test 
Variance formula: ~ fitted.values 
Chisquare = 43.1    Df = 1     p = 5.28e-11 

#Much Lower F after correction

ncvTest(gB)
Non-constant Variance Score Test 
Variance formula: ~ fitted.values 
Chisquare = 6.81    Df = 1     p = 0.00906 




# A test of normal versus nonnormal errors

shapiro.test(residuals(g))

    Shapiro-Wilk normality test

data:  residuals(g)
W = 0.944, p-value = 0.0005213




## Serial Correlation. Result: within lower and upper bounds, No serial correlation

dwtest(g)
Error: could not find function "dwtest"

## Checking for influential outliers




# The leverage measure for detecting influential outliers

library(faraway)
Attaching package: 'faraway'

The following object is masked from 'package:car':

logit, vif

par(mfrow=c(1,1))

countries <- ltrdata10$Country

halfnorm(lm.influence(g)$hat, labs=countries, ylab="Leverages")

plot of chunk unnamed-chunk-1


#Q-Q Plot of the Studentized residuals

ginf<-influence(g)

gs<- summary(g)

gs$sig
[1] 0.0883

stud<- residuals(g)/(gs$sig*sqrt(1-ginf$hat))

qqnorm(stud)

abline(0,1)

plot of chunk unnamed-chunk-1





ginf<-influence(gB)

gs<- summary(gB)

gs$sig
[1] 0.186

stud<- residuals(gB)/(gs$sig*sqrt(1-ginf$hat))

qqnorm(stud)

abline(0,1)

plot of chunk unnamed-chunk-1





# These data have influential outliers visible with scatterplot

plot( ltrdata10$LTR,ltrdata10$GDP, xlab="Literacy Rates", ylab="GDP")

plot of chunk unnamed-chunk-1


plot( ltrdata10$UNEMP,ltrdata10$GDP, xlab="Unemployment", ylab="GDP")

plot of chunk unnamed-chunk-1


plot( ltrdata10$MOBILE,ltrdata10$GDP, xlab="Mobile Subscribers", ylab="GDP")

plot of chunk unnamed-chunk-1


plot( ltrdata10$LEXP,ltrdata10$URBGR, xlab="Life Expectancy", ylab="Urban Growth Rate")







# The LS fitted line with outliers included in the data

gh <- lm(URBGR~ LEXP, ltrdata10)

abline(gh)

jack<- rstudent(gh,labs=countries)

jack[which.max(abs(jack))]
  64 
6.96 

range(jack)
[1] -1.89  6.96




# The LS fitted line with outliers excluded from the data

ga <- lm(ltrdata10$URBGR~ ltrdata10$LEXP, subset=(ltrdata10$URBGR<.045))

abline(ga, lty=2)

gs <- lm(ltrdata10$URBGR~ ltrdata10$LEXP, subset=(ltrdata10$LEXP>60))

abline(gs, lty=5)

plot of chunk unnamed-chunk-1





# Cook's Distance for detecting influential outliers

cook <- cooks.distance(g)

n<- length(cook)

sort(cook, partial=n-1)[n]
[1] 0.218

# Half normal plot of Cook's Distance with labels of three largest values

halfnorm(cook,3,labs=countries,ylab="Cook's distance")

plot of chunk unnamed-chunk-1





plot(ginf$coef[,3],ylab="Change in Urban Growth")

plot of chunk unnamed-chunk-1


plot(ginf$coef[,2],ylab="Change in Unemployment")

plot of chunk unnamed-chunk-1


plot(ginf$coef[,1],ylab="Change in GDP")

plot of chunk unnamed-chunk-1





# Model fit excluding observation with largest Cook's Distance

g1 <- lm(LTR ~ GDP +UNEMP +URBGR + MOBILE + LEXP , ltrdata10, subset=(cook < .15))

# Comparison of model fits with and without influential observation

coef(g); coef(g1); summary(g); summary(g1)

Call:
lm(formula = LTR ~ GDP + UNEMP + URBGR + MOBILE + LEXP, data = ltrdata10, 
    subset = (cook < 0.15))

Residuals:
     Min       1Q   Median       3Q      Max 
-0.18929 -0.03316  0.00579  0.02938  0.18359 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)
(Intercept) -0.00129    0.11014   -0.01   0.9907
GDP          0.01261    0.00918    1.37   0.1733
UNEMP        0.14492    0.09127    1.59   0.1161
URBGR       -1.44412    0.54393   -2.65   0.0095
MOBILE       0.11976    0.02341    5.12  1.9e-06
LEXP         0.00362    0.00150    2.41   0.0180

Residual standard error: 0.071 on 84 degrees of freedom
Multiple R-squared:  0.695, Adjusted R-squared:  0.677 
F-statistic: 38.3 on 5 and 84 DF,  p-value: <2e-16

## Checking wrong predictors (model structure)




# Added varaible plot for checking model structure

d <- residuals(lm(LTR ~ GDP + UNEMP + URBGR + MOBILE  , ltrdata10))

m <- residuals(lm(LEXP ~ GDP + UNEMP + URBGR + MOBILE  , ltrdata10))

plot(m,d,xlab="Life Expectancy Residuals", ylab="Literacy Rates Residuals")

# The slope of the plot is the same as the coeficient in the full model

coef(lm(d~m)); coef(g); abline(0,coef(g)['LEXP'])

plot of chunk unnamed-chunk-1





# Partial residual plot for checking model structure

plot(ltrdata10$LEXP, residuals(g)+coef(g)['LEXP']*ltrdata10$LEXP, xlab="Life Expectancy", ylab="Literacy Rates (Adjusted)")

abline(0,coef(g)['LEXP'])

plot of chunk unnamed-chunk-1


# Easy wasy to get the added variable plot

library(faraway); prplot(g,5)

plot of chunk unnamed-chunk-1





#Ceres Plot

library(car)

ceresPlots(g, terms= ~ . - type)

plot of chunk unnamed-chunk-1





# Fitting and comparing model within two groups

g1 <- lm(LTR ~ GDP + UNEMP + URBGR + MOBILE + LEXP , ltrdata10, subset=(LEXP>63))

g2 <- lm(LTR ~ GDP + UNEMP + URBGR + MOBILE + LEXP , ltrdata10, subset=(LEXP<63))

summary(g1); summary(g2)

Call:
lm(formula = LTR ~ GDP + UNEMP + URBGR + MOBILE + LEXP, data = ltrdata10, 
    subset = (LEXP < 63))

Residuals:
    Min      1Q  Median      3Q     Max 
-0.2766 -0.0608  0.0275  0.0682  0.1785 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)
(Intercept) -0.53377    0.42985   -1.24    0.236
GDP          0.06115    0.04385    1.39    0.187
UNEMP        0.47605    0.22470    2.12    0.054
URBGR        0.32790    3.39236    0.10    0.924
MOBILE       0.08482    0.09667    0.88    0.396
LEXP         0.00624    0.00582    1.07    0.303

Residual standard error: 0.13 on 13 degrees of freedom
Multiple R-squared:   0.6,  Adjusted R-squared:  0.447 
F-statistic: 3.91 on 5 and 13 DF,  p-value: 0.0221




## Checking for collinearity in predictors




# Signs of collinearity: The F test is highly significant and R-square is substantial, but none of the coefficents are significant

summary(g)

Call:
lm(formula = LTR ~ GDP + UNEMP + URBGR + MOBILE + LEXP, data = ltrdata10)

Residuals:
    Min      1Q  Median      3Q     Max 
-0.3358 -0.0402  0.0008  0.0334  0.2035 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)
(Intercept) -0.13939    0.11518   -1.21  0.22940
GDP          0.02100    0.01034    2.03  0.04531
UNEMP        0.24867    0.11122    2.24  0.02786
URBGR       -1.21459    0.52967   -2.29  0.02420
MOBILE       0.10561    0.02619    4.03  0.00012
LEXP         0.00518    0.00167    3.11  0.00252

Residual standard error: 0.0883 on 89 degrees of freedom
Multiple R-squared:  0.66,  Adjusted R-squared:  0.641 
F-statistic: 34.6 on 5 and 89 DF,  p-value: <2e-16




# The correlation matrix detects pairwise collinearity




# The Variance Inflation Factor (VIF)

library(faraway); 

x <- model.matrix(g)[,-1]

vif(x)
   GDP  UNEMP  URBGR MOBILE   LEXP 
  2.45   1.27   1.29   2.03   2.69 

round(cor(x),3)
          GDP  UNEMP  URBGR MOBILE   LEXP
GDP     1.000 -0.190 -0.298  0.674  0.703
UNEMP  -0.190  1.000 -0.058 -0.239 -0.380
URBGR  -0.298 -0.058  1.000 -0.325 -0.403
MOBILE  0.674 -0.239 -0.325  1.000  0.625
LEXP    0.703 -0.380 -0.403  0.625  1.000

# A solution: Amputate some predictors from the model

g2 <- lm(LTR ~ GDP + UNEMP+ URBGR + MOBILE, ltrdata10); summary(g2)

Call:
lm(formula = LTR ~ GDP + UNEMP + URBGR + MOBILE, data = ltrdata10)

Residuals:
    Min      1Q  Median      3Q     Max 
-0.3673 -0.0430  0.0064  0.0417  0.2295 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)
(Intercept)  0.04239    0.10390    0.41  0.68422
GDP          0.03681    0.00943    3.90  0.00018
UNEMP        0.11715    0.10769    1.09  0.27957
URBGR       -1.74062    0.52552   -3.31  0.00133
MOBILE       0.12190    0.02686    4.54  1.8e-05

Residual standard error: 0.0924 on 90 degrees of freedom
Multiple R-squared:  0.623, Adjusted R-squared:  0.606 
F-statistic: 37.2 on 4 and 90 DF,  p-value: <2e-16




#####

# Generalized Least Squares

# When errors are not independent (Errors must be normal)


#first we look at all of our variables for correlation
plot(~LTR+GDP+UNEMP+URBGR+MOBILE+LEXP,ltrdata10)

plot of chunk unnamed-chunk-1


cor(ltrdata10$LEXP,ltrdata10$GDP)
[1] 0.703
cor(ltrdata10$UNEMP,ltrdata10$GDP)
[1] -0.19
cor(ltrdata10$URBGR,ltrdata10$GDP)
[1] -0.298
cor(ltrdata10$MOBILE,ltrdata10$GDP) #
[1] 0.674
cor(ltrdata10$URBGR,ltrdata10$UNEMP) #
[1] -0.0577
cor(ltrdata10$MOBILE,ltrdata10$UNEMP)
[1] -0.239
cor(ltrdata10$LEXP,ltrdata10$UNEMP) #
[1] -0.38
cor(ltrdata10$MOBILE,ltrdata10$URBGR)
[1] -0.325
cor(ltrdata10$LEXP,ltrdata10$URBGR) #
[1] -0.403
cor(ltrdata10$LEXP,ltrdata10$MOBILE) #
[1] 0.625
#Strongest correlation is between GDP and Life Expectancy 
#now look at summary of correlation of coeficients
m <- lm(LTR ~ GDP +UNEMP+ URBGR + MOBILE + LEXP , ltrdata10)
summary(m,cor=T)

Call:
lm(formula = LTR ~ GDP + UNEMP + URBGR + MOBILE + LEXP, data = ltrdata10)

Residuals:
    Min      1Q  Median      3Q     Max 
-0.3358 -0.0402  0.0008  0.0334  0.2035 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)
(Intercept) -0.13939    0.11518   -1.21  0.22940
GDP          0.02100    0.01034    2.03  0.04531
UNEMP        0.24867    0.11122    2.24  0.02786
URBGR       -1.21459    0.52967   -2.29  0.02420
MOBILE       0.10561    0.02619    4.03  0.00012
LEXP         0.00518    0.00167    3.11  0.00252

Residual standard error: 0.0883 on 89 degrees of freedom
Multiple R-squared:  0.66,  Adjusted R-squared:  0.641 
F-statistic: 34.6 on 5 and 89 DF,  p-value: <2e-16

Correlation of Coefficients:
       (Intercept) GDP   UNEMP URBGR MOBILE
GDP     0.18                               
UNEMP  -0.50       -0.14                   
URBGR  -0.53       -0.06  0.26             
MOBILE -0.50       -0.43  0.09  0.12       
LEXP   -0.51       -0.49  0.38  0.32 -0.20 
#correlation of GDP~LEXP is 0.703
#Correlation of coeficients is -0.49

#run two variables in gls model
cm <- gls(LTR~GDP + LEXP, correlation=corAR1(form= ~1), data=ltrdata10)
Error: could not find function "gls"
summary(cm)
Error: object of type 'closure' is not subsettable
intervals(cm)
Error: could not find function "intervals"
#phi value is 0.08 but not significant from 0(null Hypoth) in 95%CI
#no evidence of serial correlation


# Weighted Least Squares

# When the errors are uncorrelated but have nonconstant variance (Errors must be normal)
#Look at GDP as a predictor
plot(ltrdata10$GDP, residuals(g)); abline(h=0)

plot of chunk unnamed-chunk-1

#variance much greater for low GDP countries
#quaity and reliability of data, globaization factors

#using model with weigts based on predictor GDP
#we want smaller weighted errors on smaller GDP contries
reg<- lm(LTR ~ GDP +UNEMP+ URBGR + MOBILE + LEXP,ltrdata10, weight=(1/GDP))

reg1 <- lm(LTR ~ GDP +UNEMP+ URBGR + MOBILE + LEXP,ltrdata10, weight=(1/sqrt(GDP)))

reg2 <- lm(LTR ~ GDP +UNEMP+ URBGR + MOBILE + LEXP,ltrdata10, weight=(35/GDP))

reg3 <- lm(LTR ~ GDP +UNEMP+ URBGR + MOBILE + LEXP,ltrdata10)

coef(reg)
(Intercept)         GDP       UNEMP       URBGR      MOBILE        LEXP 
   -0.19678     0.01780     0.29215    -1.24424     0.11279     0.00587 

coef(reg1)
(Intercept)         GDP       UNEMP       URBGR      MOBILE        LEXP 
   -0.16838     0.01947     0.26975    -1.23212     0.10921     0.00552 

coef(reg2)
(Intercept)         GDP       UNEMP       URBGR      MOBILE        LEXP 
   -0.19678     0.01780     0.29215    -1.24424     0.11279     0.00587 

coef(reg3)
(Intercept)         GDP       UNEMP       URBGR      MOBILE        LEXP 
   -0.13939     0.02100     0.24867    -1.21459     0.10561     0.00518 




#Test for Lack of Fit

plot(LTR ~ GDP, ltrdata10,xlab="GDP", ylab="Literacy Rates")

g <- lm(LTR ~ GDP, ltrdata10)

summary(g)

Call:
lm(formula = LTR ~ GDP, data = ltrdata10)

Residuals:
    Min      1Q  Median      3Q     Max 
-0.4176 -0.0507  0.0039  0.0617  0.2616 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)
(Intercept)  0.25845    0.07198    3.59  0.00053
GDP          0.07220    0.00817    8.84  5.8e-14

Residual standard error: 0.109 on 93 degrees of freedom
Multiple R-squared:  0.457, Adjusted R-squared:  0.451 
F-statistic: 78.1 on 1 and 93 DF,  p-value: 5.81e-14

abline(coef(g))

ga <- lm(LTR ~ GDP+UNEMP + URBGR + MOBILE + LEXP , ltrdata10)

summary(ga)$coef
            Estimate Std. Error t value Pr(>|t|)
(Intercept) -0.13939    0.11518   -1.21 0.229404
GDP          0.02100    0.01034    2.03 0.045313
UNEMP        0.24867    0.11122    2.24 0.027860
URBGR       -1.21459    0.52967   -2.29 0.024199
MOBILE       0.10561    0.02619    4.03 0.000116
LEXP         0.00518    0.00167    3.11 0.002525

summary(ga)$sigma
[1] 0.0883

summary(ga)$r.squared
[1] 0.66

summary(ga)

Call:
lm(formula = LTR ~ GDP + UNEMP + URBGR + MOBILE + LEXP, data = ltrdata10)

Residuals:
    Min      1Q  Median      3Q     Max 
-0.3358 -0.0402  0.0008  0.0334  0.2035 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)
(Intercept) -0.13939    0.11518   -1.21  0.22940
GDP          0.02100    0.01034    2.03  0.04531
UNEMP        0.24867    0.11122    2.24  0.02786
URBGR       -1.21459    0.52967   -2.29  0.02420
MOBILE       0.10561    0.02619    4.03  0.00012
LEXP         0.00518    0.00167    3.11  0.00252

Residual standard error: 0.0883 on 89 degrees of freedom
Multiple R-squared:  0.66,  Adjusted R-squared:  0.641 
F-statistic: 34.6 on 5 and 89 DF,  p-value: <2e-16

points(ltrdata10$GDP,fitted(ga), pch=18)

plot of chunk unnamed-chunk-1


anova(g,ga)
Analysis of Variance Table

Model 1: LTR ~ GDP
Model 2: LTR ~ GDP + UNEMP + URBGR + MOBILE + LEXP
  Res.Df   RSS Df Sum of Sq    F  Pr(>F)
1     93 1.109                          
2     89 0.694  4     0.415 13.3 1.5e-08


gt<- lm(LTR~ GDP + I(GDP^2), ltrdata10)
summary(gt)

Call:
lm(formula = LTR ~ GDP + I(GDP^2), data = ltrdata10)

Residuals:
    Min      1Q  Median      3Q     Max 
-0.3711 -0.0417  0.0095  0.0398  0.3007 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)
(Intercept) -1.15545    0.36855   -3.14  0.00231
GDP          0.41067    0.08709    4.72  8.5e-06
I(GDP^2)    -0.01973    0.00506   -3.90  0.00018

Residual standard error: 0.102 on 92 degrees of freedom
Multiple R-squared:  0.534, Adjusted R-squared:  0.524 
F-statistic: 52.7 on 2 and 92 DF,  p-value: 5.7e-16

plot(LTR ~ GDP, ltrdata10)

grid <- seq(6,11)

lines(grid,predict(gt,data.frame(GDP=grid)))

points(ltrdata10$GDP,fitted(ga), pch=18)

plot of chunk unnamed-chunk-1



##### 

#Robust Regression




######

#Discusses possibility of outliers that distort OLS estimates
library(faraway);# data(gala)
g1 <- lm(LTR ~ GDP+ UNEMP+ URBGR  + MOBILE  + LEXP + INTERNET, ltrdata10)

summary(g1)$coef
             Estimate Std. Error t value Pr(>|t|)
(Intercept) -0.213502   0.154620  -1.381 0.170833
GDP          0.027137   0.013418   2.022 0.046164
UNEMP        0.261146   0.112855   2.314 0.022997
URBGR       -1.202859   0.531359  -2.264 0.026049
MOBILE       0.105745   0.026259   4.027 0.000119
LEXP         0.005707   0.001824   3.129 0.002378
INTERNET    -0.000513   0.000712  -0.721 0.472901

qqnorm(residuals(g1))

qqline(residuals(g1))

plot of chunk unnamed-chunk-1


shapiro.test(residuals(g1))

    Shapiro-Wilk normality test

data:  residuals(g1)
W = 0.951, p-value = 0.001438




#######


#Demonstrates how outliers distort OLS estimates

row.names(ltrdata10) <- ltrdata10$Country
Country <- row.names(ltrdata10)

halfnorm(cooks.distance(g1), 3, labs=Country, ylab="Cook's distance")

plot of chunk unnamed-chunk-1


plot(influence(g1)$coef[,3], ylab="Change in GDP coef")

plot of chunk unnamed-chunk-1


#identify(1:95, influence(g1)$coef[,3], Country)




#######

##Compares OLS, Huber, LAD, and LTS methods 




# Huber M-estimation

library(MASS)

gr <- rlm(LTR ~ GDP+ UNEMP+ URBGR  + MOBILE  + LEXP + INTERNET, ltrdata10)

summary(gr)$coef
                Value Std. Error t value
(Intercept) -0.086505    0.12159  -0.711
GDP          0.016922    0.01055   1.604
UNEMP        0.239187    0.08875   2.695
URBGR       -0.906616    0.41785  -2.170
MOBILE       0.112367    0.02065   5.442
LEXP         0.004361    0.00143   3.041
INTERNET     0.000163    0.00056   0.292




# Least Absolution Deviation (LAD)

library(quantreg)
Warning: package 'quantreg' was built under R version 3.0.2
Loading required package: SparseM

Attaching package: 'SparseM'

The following object is masked from 'package:base':

backsolve

gq <- rq(LTR ~ GDP+ UNEMP+ URBGR  + MOBILE  + LEXP + INTERNET,data= ltrdata10)

summary(gq)$coef
            coefficients  lower bd upper bd
(Intercept)     0.070280 -0.384483  0.26503
GDP             0.003726 -0.009509  0.03775
UNEMP           0.122185  0.066406  0.52169
URBGR          -1.235583 -2.643607 -0.16531
MOBILE          0.122512  0.050372  0.15269
LEXP            0.003441  0.001638  0.00775
INTERNET        0.000316 -0.000945  0.00118




# Least Trimmed Squares (LTS)

library(robustbase)
Warning: package 'robustbase' was built under R version 3.0.2
Attaching package: 'robustbase'

The following object is masked from 'package:faraway':

epilepsy

ltsReg(LTR ~ GDP+ UNEMP+ URBGR  + MOBILE  + LEXP + INTERNET, ltrdata10)$coef
Intercept       GDP     UNEMP     URBGR    MOBILE      LEXP  INTERNET 
 1.161353 -0.006331 -0.125576 -1.365099 -0.011149 -0.001211  0.000819 

ltsReg(LTR ~ GDP+ UNEMP+ URBGR  + MOBILE  + LEXP + INTERNET, ltrdata10, nsamp="95")$coef
Intercept       GDP     UNEMP     URBGR    MOBILE      LEXP  INTERNET 
 1.161353 -0.006331 -0.125576 -1.365099 -0.011149 -0.001211  0.000819 




# Comparison of Huber, LAD, LTS

plot(LTR ~ GDP, ltrdata10)

abline(lm(LTR ~ GDP, ltrdata10)$coef) # LS

abline(rlm(LTR ~ GDP, ltrdata10)$coef, lty=2) # Huber

abline(rq(ltrdata10$LTR ~ ltrdata10$GDP)$coef, lty=5) # LAD

abline(ltsreg(LTR ~ GDP, ltrdata10)$coef, lty=7) # LTS

plot of chunk unnamed-chunk-1





# Print estimated coefficients and their standard errors in a table for several regression models




library(car)

library(faraway)

library(MASS)

#data()

gLS <- lm(LTR ~ GDP, ltrdata10)

gHub <- rlm(LTR ~ GDP, ltrdata10)

compareCoefs(gLS, gHub)

Call:
1:"lm(formula = LTR ~ GDP, data = ltrdata10)"
2:"rlm(formula = LTR ~ GDP, data = ltrdata10)"
             Est. 1    SE 1  Est. 2    SE 2
(Intercept) 0.25845 0.07198 0.34193 0.06404
GDP         0.07220 0.00817 0.06343 0.00727







############# 

##ITEM7

#Shows role of  ANOVA test of Big vs. Small Model

fit <- lm(LTR ~ GDP+ UNEMP+ URBGR  + MOBILE  + LEXP + INTERNET , data = ltrdata10)

summary(fit)

Call:
lm(formula = LTR ~ GDP + UNEMP + URBGR + MOBILE + LEXP + INTERNET, 
    data = ltrdata10)

Residuals:
    Min      1Q  Median      3Q     Max 
-0.3312 -0.0421 -0.0003  0.0307  0.2069 

Coefficients:
             Estimate Std. Error t value Pr(>|t|)
(Intercept) -0.213502   0.154620   -1.38  0.17083
GDP          0.027137   0.013418    2.02  0.04616
UNEMP        0.261146   0.112855    2.31  0.02300
URBGR       -1.202859   0.531359   -2.26  0.02605
MOBILE       0.105745   0.026259    4.03  0.00012
LEXP         0.005707   0.001824    3.13  0.00238
INTERNET    -0.000513   0.000712   -0.72  0.47290

Residual standard error: 0.0885 on 88 degrees of freedom
Multiple R-squared:  0.662, Adjusted R-squared:  0.639 
F-statistic: 28.7 on 6 and 88 DF,  p-value: <2e-16

fit2 <- lm(LTR ~ GDP + UNEMP + URBGR + MOBILE + LEXP, ltrdata10)

summary(fit2)

Call:
lm(formula = LTR ~ GDP + UNEMP + URBGR + MOBILE + LEXP, data = ltrdata10)

Residuals:
    Min      1Q  Median      3Q     Max 
-0.3358 -0.0402  0.0008  0.0334  0.2035 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)
(Intercept) -0.13939    0.11518   -1.21  0.22940
GDP          0.02100    0.01034    2.03  0.04531
UNEMP        0.24867    0.11122    2.24  0.02786
URBGR       -1.21459    0.52967   -2.29  0.02420
MOBILE       0.10561    0.02619    4.03  0.00012
LEXP         0.00518    0.00167    3.11  0.00252

Residual standard error: 0.0883 on 89 degrees of freedom
Multiple R-squared:  0.66,  Adjusted R-squared:  0.641 
F-statistic: 34.6 on 5 and 89 DF,  p-value: <2e-16

        anova(fit2,fit)
Analysis of Variance Table

Model 1: LTR ~ GDP + UNEMP + URBGR + MOBILE + LEXP
Model 2: LTR ~ GDP + UNEMP + URBGR + MOBILE + LEXP + INTERNET
  Res.Df   RSS Df Sum of Sq    F Pr(>F)
1     89 0.694                         
2     88 0.689  1   0.00407 0.52   0.47

        fit3 <- lm(LTR ~ UNEMP+ URBGR + MOBILE + LEXP + INTERNET, ltrdata10)

        summary(fit3)

Call:
lm(formula = LTR ~ UNEMP + URBGR + MOBILE + LEXP + INTERNET, 
    data = ltrdata10)

Residuals:
    Min      1Q  Median      3Q     Max 
-0.3432 -0.0449  0.0041  0.0360  0.2244 

Coefficients:
             Estimate Std. Error t value Pr(>|t|)
(Intercept) -0.114051   0.149116   -0.76   0.4464
UNEMP        0.263512   0.114791    2.30   0.0240
URBGR       -1.175200   0.540327   -2.17   0.0323
MOBILE       0.123083   0.025247    4.88  4.7e-06
LEXP         0.006054   0.001847    3.28   0.0015
INTERNET     0.000400   0.000559    0.72   0.4764

Residual standard error: 0.09 on 89 degrees of freedom
Multiple R-squared:  0.646, Adjusted R-squared:  0.626 
F-statistic: 32.5 on 5 and 89 DF,  p-value: <2e-16

        anova(fit3,fit)
Analysis of Variance Table

Model 1: LTR ~ UNEMP + URBGR + MOBILE + LEXP + INTERNET
Model 2: LTR ~ GDP + UNEMP + URBGR + MOBILE + LEXP + INTERNET
  Res.Df   RSS Df Sum of Sq    F Pr(>F)
1     89 0.722                         
2     88 0.689  1     0.032 4.09  0.046

        #####

        ##Demonstrates backward variable selection manually



        g <- lm(LTR ~ GDP+UNEMP+URBGR+MOBILE+INTERNET+LEXP+GINI, data=ltrdata10)

        summary(g)

Call:
lm(formula = LTR ~ GDP + UNEMP + URBGR + MOBILE + INTERNET + 
    LEXP + GINI, data = ltrdata10)

Residuals:
    Min      1Q  Median      3Q     Max 
-0.3221 -0.0406  0.0013  0.0384  0.2087 

Coefficients:
             Estimate Std. Error t value Pr(>|t|)
(Intercept) -0.233208   0.158564   -1.47    0.145
GDP          0.017096   0.015235    1.12    0.265
UNEMP        0.201159   0.117983    1.70    0.092
URBGR       -1.177464   0.550982   -2.14    0.036
MOBILE       0.125477   0.029899    4.20  6.9e-05
INTERNET     0.000178   0.000831    0.21    0.831
LEXP         0.004956   0.001972    2.51    0.014
GINI         0.001287   0.001198    1.07    0.286

Residual standard error: 0.0886 on 81 degrees of freedom
  (6 observations deleted due to missingness)
Multiple R-squared:  0.683, Adjusted R-squared:  0.656 
F-statistic: 24.9 on 7 and 81 DF,  p-value: <2e-16



        # Illustration of the Backward Method

        g <- update(g, . ~ . - INTERNET)

        summary(g)

Call:
lm(formula = LTR ~ GDP + UNEMP + URBGR + MOBILE + LEXP + GINI, 
    data = ltrdata10)

Residuals:
    Min      1Q  Median      3Q     Max 
-0.3216 -0.0419  0.0021  0.0393  0.2079 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)
(Intercept) -0.25237    0.13014   -1.94   0.0559
GDP          0.01942    0.01062    1.83   0.0710
UNEMP        0.20716    0.11394    1.82   0.0727
URBGR       -1.17178    0.54713   -2.14   0.0352
MOBILE       0.12468    0.02949    4.23  6.1e-05
LEXP         0.00512    0.00180    2.84   0.0056
GINI         0.00120    0.00112    1.07   0.2878

Residual standard error: 0.088 on 82 degrees of freedom
  (6 observations deleted due to missingness)
Multiple R-squared:  0.683, Adjusted R-squared:  0.66 
F-statistic: 29.4 on 6 and 82 DF,  p-value: <2e-16

        g <- update(g, . ~ . - GINI)

        summary(g)

Call:
lm(formula = LTR ~ GDP + UNEMP + URBGR + MOBILE + LEXP, data = ltrdata10)

Residuals:
    Min      1Q  Median      3Q     Max 
-0.3358 -0.0402  0.0008  0.0334  0.2035 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)
(Intercept) -0.13939    0.11518   -1.21  0.22940
GDP          0.02100    0.01034    2.03  0.04531
UNEMP        0.24867    0.11122    2.24  0.02786
URBGR       -1.21459    0.52967   -2.29  0.02420
MOBILE       0.10561    0.02619    4.03  0.00012
LEXP         0.00518    0.00167    3.11  0.00252

Residual standard error: 0.0883 on 89 degrees of freedom
Multiple R-squared:  0.66,  Adjusted R-squared:  0.641 
F-statistic: 34.6 on 5 and 89 DF,  p-value: <2e-16

        g <- update(g, . ~ . - UNEMP)

        summary(g)

Call:
lm(formula = LTR ~ GDP + URBGR + MOBILE + LEXP, data = ltrdata10)

Residuals:
    Min      1Q  Median      3Q     Max 
-0.3528 -0.0400  0.0061  0.0371  0.2073 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)
(Intercept) -0.01084    0.10200   -0.11  0.91562
GDP          0.02426    0.01047    2.32  0.02272
URBGR       -1.51737    0.52332   -2.90  0.00470
MOBILE       0.10056    0.02666    3.77  0.00029
LEXP         0.00376    0.00158    2.39  0.01898

Residual standard error: 0.0902 on 90 degrees of freedom
Multiple R-squared:  0.641, Adjusted R-squared:  0.625 
F-statistic: 40.2 on 4 and 90 DF,  p-value: <2e-16

        ######

        ###Effectively uses stepwise regression to obtain a model

        g <- lm(LTR ~ GDP+UNEMP+URBGR+MOBILE+INTERNET+LEXP, data = ltrdata10)

        step(g)
Start:  AIC=-454
LTR ~ GDP + UNEMP + URBGR + MOBILE + INTERNET + LEXP

           Df Sum of Sq   RSS  AIC
- INTERNET  1    0.0041 0.694 -455
<none>                  0.689 -454
- GDP       1    0.0320 0.722 -452
- URBGR     1    0.0402 0.730 -451
- UNEMP     1    0.0420 0.731 -450
- LEXP      1    0.0767 0.766 -446
- MOBILE    1    0.1271 0.817 -440

Step:  AIC=-455
LTR ~ GDP + UNEMP + URBGR + MOBILE + LEXP

         Df Sum of Sq   RSS  AIC
<none>                0.694 -455
- GDP     1    0.0321 0.726 -453
- UNEMP   1    0.0390 0.733 -452
- URBGR   1    0.0410 0.735 -452
- LEXP    1    0.0753 0.769 -448
- MOBILE  1    0.1267 0.820 -441

Call:
lm(formula = LTR ~ GDP + UNEMP + URBGR + MOBILE + LEXP, data = ltrdata10)

Coefficients:
(Intercept)          GDP        UNEMP        URBGR       MOBILE  
   -0.13939      0.02100      0.24867     -1.21459      0.10561  
       LEXP  
    0.00518  






        # Criterion-Based Procedures

        # Akaike Information Criterion nlog(SSE/n)+constant

        g <- lm(LTR ~ GDP+UNEMP+URBGR+MOBILE+LEXP+INTERNET, data = ltrdata10)

        step(g)
Start:  AIC=-454
LTR ~ GDP + UNEMP + URBGR + MOBILE + LEXP + INTERNET

           Df Sum of Sq   RSS  AIC
- INTERNET  1    0.0041 0.694 -455
<none>                  0.689 -454
- GDP       1    0.0320 0.722 -452
- URBGR     1    0.0402 0.730 -451
- UNEMP     1    0.0420 0.731 -450
- LEXP      1    0.0767 0.766 -446
- MOBILE    1    0.1271 0.817 -440

Step:  AIC=-455
LTR ~ GDP + UNEMP + URBGR + MOBILE + LEXP

         Df Sum of Sq   RSS  AIC
<none>                0.694 -455
- GDP     1    0.0321 0.726 -453
- UNEMP   1    0.0390 0.733 -452
- URBGR   1    0.0410 0.735 -452
- LEXP    1    0.0753 0.769 -448
- MOBILE  1    0.1267 0.820 -441

Call:
lm(formula = LTR ~ GDP + UNEMP + URBGR + MOBILE + LEXP, data = ltrdata10)

Coefficients:
(Intercept)          GDP        UNEMP        URBGR       MOBILE  
   -0.13939      0.02100      0.24867     -1.21459      0.10561  
       LEXP  
    0.00518  




        # Influential points can have an effect on selected model




        h <- lm.influence(g)$hat

        Country <- row.names(ltrdata10)



        rev(sort(h))
                 Qatar       Congo, Dem. Rep.                Namibia 
                0.3979                 0.2982                 0.2808 
  United Arab Emirates               Botswana                  Samoa 
                0.2576                 0.2361                 0.2353 
     Equatorial Guinea                  Kenya                   Chad 
                0.2260                 0.1616                 0.1199 
            Mozambique                 Angola                 Uganda 
                0.1167                 0.1155                 0.1088 
          South Africa         Macedonia, FYR       Papua New Guinea 
                0.1082                 0.1081                 0.1071 
               Vietnam    Antigua and Barbuda                Nigeria 
                0.1022                 0.0992                 0.0989 
                 Nepal                  Gabon           Turkmenistan 
                0.0977                 0.0959                 0.0834 
Bosnia and Herzegovina                 Canada            Puerto Rico 
                0.0820                 0.0783                 0.0780 
             Lithuania             Montenegro            Netherlands 
                0.0735                 0.0724                 0.0707 
                  Mali               Honduras             Bangladesh 
                0.0704                 0.0701                 0.0694 
                  Iraq             Tajikistan                 Latvia 
                0.0692                 0.0684                 0.0674 
              Tanzania                Armenia            Timor-Leste 
                0.0666                 0.0648                 0.0647 
             Guatemala                 Sweden                 Panama 
                0.0638                 0.0618                 0.0612 
               Bahrain     Russian Federation                Estonia 
                0.0588                 0.0588                 0.0576 
                Greece                 France                 Zambia 
                0.0571                 0.0562                 0.0561 
                 Japan            Switzerland                  Spain 
                0.0560                 0.0558                 0.0557 
               Finland             Costa Rica                Vanuatu 
                0.0551                 0.0547                 0.0538 
         United States                Germany   Syrian Arab Republic 
                0.0532                 0.0532                 0.0514 
        United Kingdom           Saudi Arabia              Sri Lanka 
                0.0505                 0.0500                 0.0499 
              Suriname             Uzbekistan                Ukraine 
                0.0494                 0.0486                 0.0477 
               Moldova            El Salvador                  Italy 
                0.0470                 0.0448                 0.0434 
                Cyprus                 Serbia      Brunei Darussalam 
                0.0413                 0.0407                 0.0403 
                 Sudan    Trinidad and Tobago             Kazakhstan 
                0.0399                 0.0395                 0.0391 
                Mexico               Slovenia               Mongolia 
                0.0377                 0.0376                 0.0375 
               Georgia                  India              Singapore 
                0.0374                 0.0374                 0.0370 
                 China                  Ghana                Hungary 
                0.0367                 0.0365                 0.0361 
           Yemen, Rep.                  Aruba               Malaysia 
                0.0356                 0.0351                 0.0349 
                Poland                Jamaica                Romania 
                0.0344                 0.0325                 0.0302 
               Ecuador                 Jordan               Paraguay 
                0.0299                 0.0286                 0.0279 
              Portugal                Croatia                Uruguay 
                0.0257                 0.0237                 0.0230 
             Argentina       Egypt, Arab Rep.                 Brazil 
                0.0220                 0.0196                 0.0194 
    Dominican Republic               Colombia 
                0.0167                 0.0133 

        # Qatar has high leverage, try removing it

        g <- lm(LTR ~ GDP+UNEMP+URBGR+MOBILE+INTERNET+LEXP, data = ltrdata10, subset=(Country != "Qatar"))

        step(g)
Start:  AIC=-450
LTR ~ GDP + UNEMP + URBGR + MOBILE + INTERNET + LEXP

           Df Sum of Sq   RSS  AIC
- INTERNET  1    0.0054 0.680 -451
<none>                  0.674 -450
- GDP       1    0.0268 0.701 -448
- UNEMP     1    0.0406 0.715 -447
- URBGR     1    0.0550 0.729 -445
- LEXP      1    0.0701 0.744 -443
- MOBILE    1    0.1266 0.801 -436

Step:  AIC=-451
LTR ~ GDP + UNEMP + URBGR + MOBILE + LEXP

         Df Sum of Sq   RSS  AIC
<none>                0.680 -451
- GDP     1    0.0227 0.702 -450
- UNEMP   1    0.0371 0.717 -448
- URBGR   1    0.0542 0.734 -446
- LEXP    1    0.0657 0.745 -445
- MOBILE  1    0.1262 0.806 -437

Call:
lm(formula = LTR ~ GDP + UNEMP + URBGR + MOBILE + LEXP, data = ltrdata10, 
    subset = (Country != "Qatar"))

Coefficients:
(Intercept)          GDP        UNEMP        URBGR       MOBILE  
   -0.08193      0.01805      0.24276     -1.73291      0.10540  
       LEXP  
    0.00488  

        # Transforming variables can have an effect

        ltrdata10$Country<-NULL

        ltrdata10$Region<-NULL

        stripchart (data.frame (scale (ltrdata10)), vertical=TRUE,method="jitter")

        g <- lm(LTR ~ GDP+ log(UNEMP)+ URBGR+ MOBILE+LEXP+INTERNET, data = ltrdata10)

        step(g)      
Start:  AIC=-449
LTR ~ GDP + log(UNEMP) + URBGR + MOBILE + LEXP + INTERNET

             Df Sum of Sq   RSS  AIC
- INTERNET    1    0.0007 0.731 -450
- log(UNEMP)  1    0.0016 0.731 -450
<none>                    0.730 -449
- LEXP        1    0.0305 0.760 -447
- GDP         1    0.0334 0.763 -446
- URBGR       1    0.0645 0.794 -442
- MOBILE      1    0.1143 0.844 -437

Step:  AIC=-450
LTR ~ GDP + log(UNEMP) + URBGR + MOBILE + LEXP

             Df Sum of Sq   RSS  AIC
- log(UNEMP)  1    0.0020 0.733 -452
<none>                    0.731 -450
- LEXP        1    0.0321 0.763 -448
- GDP         1    0.0457 0.776 -447
- URBGR       1    0.0654 0.796 -444
- MOBILE      1    0.1143 0.845 -439

Step:  AIC=-452
LTR ~ GDP + URBGR + MOBILE + LEXP

         Df Sum of Sq   RSS  AIC
<none>                0.733 -452
- GDP     1    0.0437 0.776 -449
- LEXP    1    0.0465 0.779 -448
- URBGR   1    0.0684 0.801 -446
- MOBILE  1    0.1158 0.848 -440

Call:
lm(formula = LTR ~ GDP + URBGR + MOBILE + LEXP, data = ltrdata10)

Coefficients:
(Intercept)          GDP        URBGR       MOBILE         LEXP  
   -0.01084      0.02426     -1.51737      0.10056      0.00376  


#####

# Cross-Validation for Linear Models

##Explains the usage of training and valitation dataset




g <- lm(LTR ~ GDP+UNEMP+URBGR+MOBILE+INTERNET+LEXP, data = ltrdata10)

g.step <- step(g)
Start:  AIC=-454
LTR ~ GDP + UNEMP + URBGR + MOBILE + INTERNET + LEXP

           Df Sum of Sq   RSS  AIC
- INTERNET  1    0.0041 0.694 -455
<none>                  0.689 -454
- GDP       1    0.0320 0.722 -452
- URBGR     1    0.0402 0.730 -451
- UNEMP     1    0.0420 0.731 -450
- LEXP      1    0.0767 0.766 -446
- MOBILE    1    0.1271 0.817 -440

Step:  AIC=-455
LTR ~ GDP + UNEMP + URBGR + MOBILE + LEXP

         Df Sum of Sq   RSS  AIC
<none>                0.694 -455
- GDP     1    0.0321 0.726 -453
- UNEMP   1    0.0390 0.733 -452
- URBGR   1    0.0410 0.735 -452
- LEXP    1    0.0753 0.769 -448
- MOBILE  1    0.1267 0.820 -441

summary(g.step)

Call:
lm(formula = LTR ~ GDP + UNEMP + URBGR + MOBILE + LEXP, data = ltrdata10)

Residuals:
    Min      1Q  Median      3Q     Max 
-0.3358 -0.0402  0.0008  0.0334  0.2035 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)
(Intercept) -0.13939    0.11518   -1.21  0.22940
GDP          0.02100    0.01034    2.03  0.04531
UNEMP        0.24867    0.11122    2.24  0.02786
URBGR       -1.21459    0.52967   -2.29  0.02420
MOBILE       0.10561    0.02619    4.03  0.00012
LEXP         0.00518    0.00167    3.11  0.00252

Residual standard error: 0.0883 on 89 degrees of freedom
Multiple R-squared:  0.66,  Adjusted R-squared:  0.641 
F-statistic: 34.6 on 5 and 89 DF,  p-value: <2e-16

library(DAAG)
Warning: package 'DAAG' was built under R version 3.0.2
Loading required package: lattice

Attaching package: 'lattice'

The following object is masked from 'package:faraway':

melanoma

Attaching package: 'DAAG'

The following object is masked from 'package:robustbase':

milk

The following object is masked from 'package:MASS':

hills

The following object is masked from 'package:faraway':

orings, ozone, vif

The following object is masked from 'package:car':

vif

plot of chunk unnamed-chunk-1


# Crossvalidation of model as a portion or "fold" is held out, default is 3 folds

par(mfrow=c(1,2))

CVlm(df=ltrdata10, form.lm=g.step)
Analysis of Variance Table

Response: LTR
          Df Sum Sq Mean Sq F value  Pr(>F)
GDP        1  0.932   0.932  119.54 < 2e-16
UNEMP      1  0.006   0.006    0.72  0.3989
URBGR      1  0.158   0.158   20.30 2.0e-05
MOBILE     1  0.176   0.176   22.57 7.7e-06
LEXP       1  0.075   0.075    9.66  0.0025
Residuals 89  0.694   0.008                
Warning:

As there is >1 explanatory variable, cross-validation predicted values for
a fold are not a linear function of corresponding overall predicted
values.  Lines that are shown for the different folds are approximate

fold 1 
Observations in test set: 31 
            Armenia   Aruba Bahrain Brazil Brunei Darussalam Colombia
Predicted    0.9737  0.9823  0.9195  0.937           0.95844   0.9131
cvpred       0.9846  0.9843  0.8971  0.933           0.94968   0.9101
LTR          0.9960  0.9680  0.9190  0.904           0.95200   0.9340
CV residual  0.0114 -0.0163  0.0219 -0.029           0.00232   0.0239
            El Salvador Estonia Germany   Ghana  Greece   India Jordan
Predicted        0.9125  1.0012   1.028  0.7515  1.0101  0.7678 0.9113
cvpred           0.9005  1.0152   1.035  0.7282  1.0209  0.7453 0.9046
LTR              0.8450  0.9980   0.990  0.6730  0.9720  0.7400 0.9260
CV residual     -0.0555 -0.0172  -0.045 -0.0552 -0.0489 -0.0053 0.0214
              Latvia Malaysia Mexico Namibia  Panama Papua New Guinea
Predicted    0.98123   0.9140 0.9056  0.9229  0.9819           0.6694
cvpred       1.00064   0.8957 0.8978  0.9664  0.9659           0.6521
LTR          0.99800   0.9310 0.9310  0.8880  0.9410           0.6060
CV residual -0.00264   0.0353 0.0332 -0.0784 -0.0249          -0.0461
            Paraguay  Poland Puerto Rico Qatar Saudi Arabia Slovenia
Predicted     0.8612 0.98637      0.9833 0.871        1.007  0.98938
cvpred        0.8433 0.99075      1.0035 0.825        1.002  0.99356
LTR           0.9390 0.99500      0.9040 0.963        0.866  0.99700
CV residual   0.0957 0.00425     -0.0995 0.138       -0.136  0.00344
            Tajikistan Tanzania Trinidad and Tobago Turkmenistan Ukraine
Predicted        0.794   0.6756              0.9322        0.793  0.9184
cvpred           0.766   0.6497              0.9205        0.774  0.9132
LTR              0.997   0.7320              0.9880        0.996  0.9970
CV residual      0.231   0.0823              0.0675        0.222  0.0838
            Vanuatu
Predicted    0.8060
cvpred       0.7799
LTR          0.8260
CV residual  0.0461

Sum of squares = 0.2    Mean square = 0.01    n = 31 

fold 2 
Observations in test set: 32 
            Angola Canada   Chad China Congo, Dem. Rep. Dominican Republic
Predicted   0.7081 0.9666  0.594 0.835            0.606             0.8948
cvpred      0.6854 0.9561  0.570 0.820            0.511             0.8831
LTR         0.7010 0.9900  0.345 0.943            0.668             0.8950
CV residual 0.0156 0.0339 -0.225 0.123            0.157             0.0119
            Egypt, Arab Rep. France Honduras Hungary    Iraq  Italy
Predicted              0.865 0.9882   0.8821  0.9714  0.8532  1.048
cvpred                 0.859 0.9795   0.8844  0.9762  0.8372  1.056
LTR                    0.720 0.9900   0.8480  0.9900  0.7820  0.989
CV residual           -0.139 0.0105  -0.0364  0.0138 -0.0552 -0.067
            Jamaica    Japan Kazakhstan Kenya Mozambique Portugal Romania
Predicted    0.9469  0.99898     0.9134 0.792     0.6020   0.9946  0.9492
cvpred       0.9478  0.99767     0.9317 0.737     0.5777   0.9922  0.9587
LTR          0.8660  0.99000     0.9970 0.874     0.5610   0.9520  0.9770
CV residual -0.0818 -0.00767     0.0653 0.137    -0.0167  -0.0402  0.0183
            Russian Federation Samoa South Africa   Sudan Suriname  Sweden
Predicted              0.96452 0.803       0.8518 0.72881   0.9584  1.0213
cvpred                 0.99102 0.743       0.8553 0.70432   0.9787  1.0228
LTR                    0.99600 0.988       0.9300 0.71100   0.9470  0.9900
CV residual            0.00498 0.245       0.0747 0.00668  -0.0317 -0.0328
            Syrian Arab Republic Uganda United Arab Emirates
Predicted                 0.8277  0.612               0.9129
cvpred                    0.8015  0.592               0.9021
LTR                       0.8340  0.732               0.9000
CV residual               0.0325  0.140              -0.0021
            United Kingdom  Uruguay Uzbekistan Zambia
Predicted           1.0207  0.98017      0.790 0.6737
cvpred              1.0267  0.98973      0.792 0.6528
LTR                 0.9900  0.98100      0.994 0.7120
CV residual        -0.0367 -0.00873      0.202 0.0592

Sum of squares = 0.29    Mean square = 0.01    n = 32 

fold 3 
Observations in test set: 32 
            Antigua and Barbuda Argentina Bangladesh
Predicted                1.0237    0.9528      0.739
cvpred                   1.0123    0.9502      0.796
LTR                      0.9900    0.9780      0.568
CV residual             -0.0223    0.0278     -0.228
            Bosnia and Herzegovina Botswana Costa Rica Croatia Cyprus
Predicted                   0.9535   0.8096      0.892  0.9826  0.964
cvpred                      0.9671   0.7518      0.920  0.9767  0.962
LTR                         0.9790   0.8450      0.962  0.9880  0.983
CV residual                 0.0119   0.0932      0.042  0.0113  0.021
             Ecuador Equatorial Guinea Finland  Gabon Georgia Guatemala
Predicted    0.89867             0.772  1.0460 0.8721  0.9128     0.873
cvpred       0.92582             0.722  1.0265 0.8523  0.9345     0.900
LTR          0.91900             0.939  0.9990 0.8840  0.9970     0.752
CV residual -0.00682             0.217 -0.0275 0.0317  0.0625    -0.148
            Lithuania Macedonia, FYR   Mali Moldova Mongolia Montenegro
Predicted     1.02530         0.9934  0.647   0.844    0.817     1.0265
cvpred        1.00228         0.9964  0.676   0.868    0.840     1.0212
LTR           0.99700         0.9730  0.311   0.985    0.974     0.9840
CV residual  -0.00528        -0.0234 -0.365   0.117    0.134    -0.0372
             Nepal Netherlands Nigeria  Serbia Singapore   Spain Sri Lanka
Predicted    0.675     1.00377   0.705 0.97553    1.0185  1.0417   0.87434
cvpred       0.735     0.99231   0.704 0.97779    1.0119  1.0321   0.90261
LTR          0.603     0.99000   0.613 0.97900    0.9590  0.9770   0.91200
CV residual -0.132    -0.00231  -0.091 0.00121   -0.0529 -0.0551   0.00939
            Switzerland Timor-Leste United States  Vietnam Yemen, Rep.
Predicted        1.0296       0.695        0.9799  0.88445       0.726
cvpred           1.0133       0.749        0.9645  0.93455       0.757
LTR              0.9900       0.583        0.9900  0.93200       0.639
CV residual     -0.0233      -0.166        0.0255 -0.00255      -0.118

Sum of squares = 0.38    Mean square = 0.01    n = 32 

Overall (Sum over all 32 folds) 
     ms 
0.00917 

CVlm(df=ltrdata10, form.lm=g)
Analysis of Variance Table

Response: LTR
          Df Sum Sq Mean Sq F value  Pr(>F)
GDP        1  0.932   0.932  118.89 < 2e-16
UNEMP      1  0.006   0.006    0.71  0.4002
URBGR      1  0.158   0.158   20.19 2.1e-05
MOBILE     1  0.176   0.176   22.45 8.2e-06
INTERNET   1  0.003   0.003    0.34  0.5624
LEXP       1  0.077   0.077    9.79  0.0024
Residuals 88  0.689   0.008                
Warning:

As there is >1 explanatory variable, cross-validation predicted values for
a fold are not a linear function of corresponding overall predicted
values.  Lines that are shown for the different folds are approximate

plot of chunk unnamed-chunk-1


fold 1 
Observations in test set: 31 
              Armenia   Aruba Bahrain  Brazil Brunei Darussalam Colombia
Predicted    0.978247  0.9794  0.9193  0.9411           0.96290   0.9148
cvpred       0.996596  0.9786  0.8971  0.9415           0.95937   0.9151
LTR          0.996000  0.9680  0.9190  0.9040           0.95200   0.9340
CV residual -0.000596 -0.0106  0.0219 -0.0375          -0.00737   0.0189
            El Salvador Estonia Germany   Ghana  Greece   India Jordan
Predicted        0.9197 0.99018    1.02  0.7515  1.0202  0.7702 0.9158
cvpred           0.9166 0.99368    1.02  0.7292  1.0436  0.7513 0.9159
LTR              0.8450 0.99800    0.99  0.6730  0.9720  0.7400 0.9260
CV residual     -0.0716 0.00432   -0.03 -0.0562 -0.0716 -0.0113 0.0101
            Latvia Malaysia Mexico Namibia  Panama Papua New Guinea
Predicted    0.971   0.9074 0.9131   0.935  0.9843           0.6729
cvpred       0.980   0.8822 0.9147   0.998  0.9719           0.6602
LTR          0.998   0.9310 0.9310   0.888  0.9410           0.6060
CV residual  0.018   0.0488 0.0163  -0.110 -0.0309          -0.0542
            Paraguay Poland Puerto Rico Qatar Saudi Arabia Slovenia
Predicted     0.8658 0.9801       0.992 0.867        1.013   0.9844
cvpred        0.8542 0.9786       1.024 0.816        1.016   0.9839
LTR           0.9390 0.9950       0.904 0.963        0.866   0.9970
CV residual   0.0848 0.0164      -0.120 0.147       -0.150   0.0131
            Tajikistan Tanzania Trinidad and Tobago Turkmenistan Ukraine
Predicted        0.791   0.6679              0.9308        0.804  0.9201
cvpred           0.761   0.6349              0.9177        0.798  0.9178
LTR              0.997   0.7320              0.9880        0.996  0.9970
CV residual      0.236   0.0971              0.0703        0.198  0.0792
            Vanuatu
Predicted    0.8154
cvpred       0.8004
LTR          0.8260
CV residual  0.0256

Sum of squares = 0.22    Mean square = 0.01    n = 31 

fold 2 
Observations in test set: 32 
            Angola Canada   Chad China Congo, Dem. Rep. Dominican Republic
Predicted   0.7110 0.9616  0.588 0.836            0.598            0.89786
cvpred      0.6816 0.9464  0.551 0.820            0.485            0.88741
LTR         0.7010 0.9900  0.345 0.943            0.668            0.89500
CV residual 0.0194 0.0436 -0.206 0.123            0.183            0.00759
            Egypt, Arab Rep. France Honduras Hungary    Iraq   Italy
Predicted              0.862 0.9827   0.8890   0.963  0.8682  1.0550
cvpred                 0.855 0.9699   0.8975   0.963  0.8603  1.0703
LTR                    0.720 0.9900   0.8480   0.990  0.7820  0.9890
CV residual           -0.135 0.0201  -0.0495   0.027 -0.0783 -0.0813
            Jamaica    Japan Kazakhstan Kenya Mozambique Portugal Romania
Predicted    0.9513  0.99525     0.9165 0.789    0.59095   0.9981  0.9497
cvpred       0.9564  0.99183     0.9369 0.727    0.55185   0.9987  0.9607
LTR          0.8660  0.99000     0.9970 0.874    0.56100   0.9520  0.9770
CV residual -0.0904 -0.00183     0.0601 0.147    0.00915  -0.0467  0.0163
            Russian Federation Samoa South Africa  Sudan Suriname  Sweden
Predicted              0.96324 0.816       0.8526 0.7256   0.9624  1.0121
cvpred                 0.99011 0.759       0.8521 0.6941   0.9869  1.0079
LTR                    0.99600 0.988       0.9300 0.7110   0.9470  0.9900
CV residual            0.00589 0.229       0.0779 0.0169  -0.0399 -0.0179
            Syrian Arab Republic Uganda United Arab Emirates
Predicted                 0.8329  0.602               0.9115
cvpred                    0.8088  0.568               0.8974
LTR                       0.8340  0.732               0.9000
CV residual               0.0252  0.164               0.0026
            United Kingdom Uruguay Uzbekistan Zambia
Predicted           1.0115  0.9816      0.787 0.6697
cvpred              1.0124  0.9938      0.786 0.6395
LTR                 0.9900  0.9810      0.994 0.7120
CV residual        -0.0224 -0.0128      0.208 0.0725

Sum of squares = 0.3    Mean square = 0.01    n = 32 

fold 3 
Observations in test set: 32 
            Antigua and Barbuda Argentina Bangladesh
Predicted                1.0085    0.9519      0.741
cvpred                   1.0219    0.9511      0.796
LTR                      0.9900    0.9780      0.568
CV residual             -0.0319    0.0269     -0.228
            Bosnia and Herzegovina Botswana Costa Rica Croatia Cyprus
Predicted                  0.94822   0.8144     0.8976  0.9802 0.9692
cvpred                     0.97231   0.7459     0.9177  0.9788 0.9593
LTR                        0.97900   0.8450     0.9620  0.9880 0.9830
CV residual                0.00669   0.0991     0.0443  0.0092 0.0237
             Ecuador Equatorial Guinea Finland Gabon Georgia Guatemala
Predicted    0.90272             0.786  1.0368 0.886   0.915     0.882
cvpred       0.92437             0.711  1.0322 0.843   0.935     0.896
LTR          0.91900             0.939  0.9990 0.884   0.997     0.752
CV residual -0.00537             0.228 -0.0332 0.041   0.062    -0.144
            Lithuania Macedonia, FYR   Mali Moldova Mongolia Montenegro
Predicted      1.0178         0.9883  0.642   0.837    0.822      1.030
cvpred         1.0076         1.0017  0.677   0.873    0.837      1.021
LTR            0.9970         0.9730  0.311   0.985    0.974      0.984
CV residual   -0.0106        -0.0287 -0.366   0.112    0.137     -0.037
             Nepal Netherlands Nigeria    Serbia Singapore   Spain
Predicted    0.673     0.99296  0.6938  0.974830    1.0177  1.0433
cvpred       0.737     0.99861  0.7089  0.979719    1.0126  1.0325
LTR          0.603     0.99000  0.6130  0.979000    0.9590  0.9770
CV residual -0.134    -0.00861 -0.0959 -0.000719   -0.0536 -0.0555
            Sri Lanka Switzerland Timor-Leste United States Vietnam
Predicted      0.8820      1.0256       0.697         0.977  0.8795
cvpred         0.8992      1.0156       0.748         0.966  0.9393
LTR            0.9120      0.9900       0.583         0.990  0.9320
CV residual    0.0128     -0.0256      -0.165         0.024 -0.0073
            Yemen, Rep.
Predicted         0.726
cvpred            0.757
LTR               0.639
CV residual      -0.118

Sum of squares = 0.39    Mean square = 0.01    n = 32 

Overall (Sum over all 32 folds) 
     ms 
0.00956 







# Use a different seed for choosing different random folds

(seed <- round(runif(1, min=0, max=100)))
[1] 16

CVlm(df=ltrdata10, form.lm=g.step, seed=seed)
Analysis of Variance Table

Response: LTR
          Df Sum Sq Mean Sq F value  Pr(>F)
GDP        1  0.932   0.932  119.54 < 2e-16
UNEMP      1  0.006   0.006    0.72  0.3989
URBGR      1  0.158   0.158   20.30 2.0e-05
MOBILE     1  0.176   0.176   22.57 7.7e-06
LEXP       1  0.075   0.075    9.66  0.0025
Residuals 89  0.694   0.008                
Warning:

As there is >1 explanatory variable, cross-validation predicted values for
a fold are not a linear function of corresponding overall predicted
values.  Lines that are shown for the different folds are approximate

fold 1 
Observations in test set: 31 
            Argentina  Brazil Croatia Dominican Republic  France Germany
Predicted      0.9528  0.9375  0.9826            0.89483 0.98818  1.0281
cvpred         0.9479  0.9328  0.9913            0.88747 0.98527  1.0331
LTR            0.9780  0.9040  0.9880            0.89500 0.99000  0.9900
CV residual    0.0301 -0.0288 -0.0033            0.00753 0.00473 -0.0431
             Greece Hungary    Iraq Jamaica Jordan Macedonia, FYR Malaysia
Predicted    1.0101  0.9714  0.8532  0.9469 0.9113         0.9934   0.9140
cvpred       1.0156  0.9767  0.8513  0.9544 0.8991         1.0209   0.8884
LTR          0.9720  0.9900  0.7820  0.8660 0.9260         0.9730   0.9310
CV residual -0.0436  0.0133 -0.0693 -0.0884 0.0269        -0.0479   0.0426
              Mali Mongolia Montenegro Nigeria  Panama Papua New Guinea
Predicted    0.647    0.817     1.0265  0.7050  0.9819            0.669
cvpred       0.628    0.796     1.0335  0.7085  0.9531            0.674
LTR          0.311    0.974     0.9840  0.6130  0.9410            0.606
CV residual -0.317    0.178    -0.0495 -0.0955 -0.0121           -0.068
             Poland Portugal Qatar Romania  Sweden Tajikistan
Predicted   0.98637   0.9946 0.871  0.9492  1.0213      0.794
cvpred      0.99342   0.9938 0.772  0.9564  1.0186      0.775
LTR         0.99500   0.9520 0.963  0.9770  0.9900      0.997
CV residual 0.00158  -0.0418 0.191  0.0206 -0.0286      0.222
            Trinidad and Tobago Turkmenistan Uganda United Arab Emirates
Predicted                0.9322        0.793  0.612               0.9129
cvpred                   0.9176        0.788  0.580               0.8378
LTR                      0.9880        0.996  0.732               0.9000
CV residual              0.0704        0.208  0.152               0.0622
            Vanuatu Vietnam
Predicted    0.8060  0.8844
cvpred       0.7794  0.8514
LTR          0.8260  0.9320
CV residual  0.0466  0.0806

Sum of squares = 0.34    Mean square = 0.01    n = 31 

fold 2 
Observations in test set: 32 
            Armenia   Aruba Bangladesh Brunei Darussalam China Colombia
Predicted    0.9737  0.9823      0.739           0.95844 0.835   0.9131
cvpred       0.9776  0.9805      0.726           0.95538 0.825   0.9132
LTR          0.9960  0.9680      0.568           0.95200 0.943   0.9340
CV residual  0.0184 -0.0125     -0.158          -0.00338 0.118   0.0208
            Costa Rica Ecuador Egypt, Arab Rep. El Salvador Finland
Predicted       0.8920  0.8987            0.865      0.9125  1.0460
cvpred          0.8692  0.9062            0.868      0.9295  1.0476
LTR             0.9620  0.9190            0.720      0.8450  0.9990
CV residual     0.0928  0.0128           -0.148     -0.0845 -0.0486
               Gabon Georgia   Ghana Guatemala Honduras   India  Japan
Predicted    0.87207  0.9128  0.7515     0.873   0.8821  0.7678 0.9990
cvpred       0.89124  0.9096  0.7696     0.902   0.9085  0.7686 0.9776
LTR          0.88400  0.9970  0.6730     0.752   0.8480  0.7400 0.9900
CV residual -0.00724  0.0874 -0.0966    -0.150  -0.0605 -0.0286 0.0124
            Kazakhstan Mexico Moldova Mozambique Russian Federation Samoa
Predicted       0.9134 0.9056   0.844     0.6020            0.96452 0.803
cvpred          0.9272 0.8933   0.853     0.5955            0.98862 0.729
LTR             0.9970 0.9310   0.985     0.5610            0.99600 0.988
CV residual     0.0698 0.0377   0.132    -0.0345            0.00738 0.259
            Saudi Arabia Singapore Slovenia United Kingdom United States
Predicted          1.007    1.0185   0.9894         1.0207          0.98
cvpred             1.033    1.0217   0.9747         1.0157          0.96
LTR                0.866    0.9590   0.9970         0.9900          0.99
CV residual       -0.167   -0.0627   0.0223        -0.0257          0.03
             Uruguay Uzbekistan Yemen, Rep.
Predicted    0.98017      0.790      0.7265
cvpred       0.98436      0.801      0.7213
LTR          0.98100      0.994      0.6390
CV residual -0.00336      0.193     -0.0823

Sum of squares = 0.29    Mean square = 0.01    n = 32 

fold 3 
Observations in test set: 32 
            Angola Antigua and Barbuda  Bahrain Bosnia and Herzegovina
Predicted   0.7081             1.02366  0.91953                 0.9535
cvpred      0.6092             0.99941  0.92231                 0.9233
LTR         0.7010             0.99000  0.91900                 0.9790
CV residual 0.0918            -0.00941 -0.00331                 0.0557
            Botswana    Canada   Chad Congo, Dem. Rep.   Cyprus
Predicted      0.810  0.966587  0.594            0.606  0.96431
cvpred         0.685  0.990849  0.569            0.489  0.98501
LTR            0.845  0.990000  0.345            0.668  0.98300
CV residual    0.160 -0.000849 -0.224            0.179 -0.00201
            Equatorial Guinea Estonia   Italy Kenya Latvia Lithuania
Predicted               0.772  1.0012  1.0478 0.792 0.9812   1.02530
cvpred                  0.676  0.9761  1.0519 0.686 0.9555   0.98945
LTR                     0.939  0.9980  0.9890 0.874 0.9980   0.99700
CV residual             0.263  0.0219 -0.0629 0.188 0.0425   0.00755
            Namibia  Nepal Netherlands Paraguay Puerto Rico Serbia
Predicted     0.923  0.675      1.0038   0.8612      0.9833  0.976
cvpred        0.768  0.735      1.0226   0.8759      0.9821  0.948
LTR           0.888  0.603      0.9900   0.9390      0.9040  0.979
CV residual   0.120 -0.132     -0.0326   0.0631     -0.0781  0.031
            South Africa   Spain Sri Lanka   Sudan Suriname Switzerland
Predicted          0.852  1.0417    0.8743  0.7288   0.9584      1.0296
cvpred             0.740  1.0247    0.9074  0.7201   0.9316      1.0469
LTR                0.930  0.9770    0.9120  0.7110   0.9470      0.9900
CV residual        0.190 -0.0477    0.0046 -0.0091   0.0154     -0.0569
            Syrian Arab Republic Tanzania Timor-Leste Ukraine Zambia
Predicted                 0.8277   0.6756       0.695  0.9184 0.6737
cvpred                    0.8617   0.6677       0.732  0.9173 0.6347
LTR                       0.8340   0.7320       0.583  0.9970 0.7120
CV residual              -0.0277   0.0643      -0.149  0.0797 0.0773

Sum of squares = 0.36    Mean square = 0.01    n = 32 

Overall (Sum over all 32 folds) 
    ms 
0.0105 

CVlm(df=ltrdata10, form.lm=g, seed=seed)
Analysis of Variance Table

Response: LTR
          Df Sum Sq Mean Sq F value  Pr(>F)
GDP        1  0.932   0.932  118.89 < 2e-16
UNEMP      1  0.006   0.006    0.71  0.4002
URBGR      1  0.158   0.158   20.19 2.1e-05
MOBILE     1  0.176   0.176   22.45 8.2e-06
INTERNET   1  0.003   0.003    0.34  0.5624
LEXP       1  0.077   0.077    9.79  0.0024
Residuals 88  0.689   0.008                
Warning:

As there is >1 explanatory variable, cross-validation predicted values for
a fold are not a linear function of corresponding overall predicted
values.  Lines that are shown for the different folds are approximate

plot of chunk unnamed-chunk-1


fold 1 
Observations in test set: 31 
            Argentina  Brazil  Croatia Dominican Republic France Germany
Predicted      0.9519  0.9411  0.98020            0.89786 0.9827  1.0207
cvpred         0.9467  0.9377  0.98915            0.89057 0.9771  1.0239
LTR            0.9780  0.9040  0.98800            0.89500 0.9900  0.9900
CV residual    0.0313 -0.0337 -0.00115            0.00443 0.0129 -0.0339
             Greece Hungary    Iraq Jamaica Jordan Macedonia, FYR Malaysia
Predicted    1.0202  0.9632  0.8682  0.9513 0.9158         0.9883   0.9074
cvpred       1.0292  0.9663  0.8706  0.9618 0.9038         1.0148   0.8774
LTR          0.9720  0.9900  0.7820  0.8660 0.9260         0.9730   0.9310
CV residual -0.0572  0.0237 -0.0886 -0.0958 0.0222        -0.0418   0.0536
              Mali Mongolia Montenegro Nigeria  Panama Papua New Guinea
Predicted    0.642    0.822     1.0296  0.6938  0.9843           0.6729
cvpred       0.620    0.802     1.0377  0.6918  0.9535           0.6809
LTR          0.311    0.974     0.9840  0.6130  0.9410           0.6060
CV residual -0.309    0.172    -0.0537 -0.0788 -0.0125          -0.0749
             Poland Portugal Qatar Romania  Sweden Tajikistan
Predicted   0.98010   0.9981 0.867  0.9497  1.0121      0.791
cvpred      0.98638   0.9981 0.752  0.9592  1.0055      0.772
LTR         0.99500   0.9520 0.963  0.9770  0.9900      0.997
CV residual 0.00862  -0.0461 0.211  0.0178 -0.0155      0.225
            Trinidad and Tobago Turkmenistan Uganda United Arab Emirates
Predicted                0.9308        0.804  0.602               0.9115
cvpred                   0.9139        0.804  0.564               0.8241
LTR                      0.9880        0.996  0.732               0.9000
CV residual              0.0741        0.192  0.168               0.0759
            Vanuatu Vietnam
Predicted    0.8154  0.8795
cvpred       0.7904  0.8431
LTR          0.8260  0.9320
CV residual  0.0356  0.0889

Sum of squares = 0.35    Mean square = 0.01    n = 31 

fold 2 
Observations in test set: 32 
            Armenia    Aruba Bangladesh Brunei Darussalam China Colombia
Predicted    0.9782  0.97944      0.741           0.96290 0.836   0.9148
cvpred       0.9847  0.97683      0.731           0.96073 0.827   0.9162
LTR          0.9960  0.96800      0.568           0.95200 0.943   0.9340
CV residual  0.0113 -0.00883     -0.163          -0.00873 0.116   0.0178
            Costa Rica Ecuador Egypt, Arab Rep. El Salvador Finland
Predicted       0.8976 0.90272            0.862      0.9197  1.0368
cvpred          0.8772 0.91246            0.867      0.9391  1.0367
LTR             0.9620 0.91900            0.720      0.8450  0.9990
CV residual     0.0848 0.00654           -0.147     -0.0941 -0.0377
              Gabon Georgia   Ghana Guatemala Honduras   India  Japan
Predicted    0.8862  0.9148  0.7515     0.882   0.8890  0.7702 0.9952
cvpred       0.9077  0.9137  0.7705     0.913   0.9185  0.7725 0.9734
LTR          0.8840  0.9970  0.6730     0.752   0.8480  0.7400 0.9900
CV residual -0.0237  0.0833 -0.0975    -0.161  -0.0705 -0.0325 0.0166
            Kazakhstan Mexico Moldova Mozambique Russian Federation Samoa
Predicted       0.9165 0.9131   0.837     0.5909            0.96324 0.816
cvpred          0.9308 0.9031   0.846     0.5828            0.98697 0.745
LTR             0.9970 0.9310   0.985     0.5610            0.99600 0.988
CV residual     0.0662 0.0279   0.139    -0.0218            0.00903 0.243
            Saudi Arabia Singapore Slovenia United Kingdom United States
Predicted          1.013    1.0177   0.9844         1.0115        0.9771
cvpred             1.041    1.0209   0.9691         1.0051        0.9566
LTR                0.866    0.9590   0.9970         0.9900        0.9900
CV residual       -0.175   -0.0619   0.0279        -0.0151        0.0334
             Uruguay Uzbekistan Yemen, Rep.
Predicted    0.98160      0.787      0.7263
cvpred       0.98667      0.798      0.7222
LTR          0.98100      0.994      0.6390
CV residual -0.00567      0.196     -0.0832

Sum of squares = 0.29    Mean square = 0.01    n = 32 

fold 3 
Observations in test set: 32 
            Angola Antigua and Barbuda  Bahrain Bosnia and Herzegovina
Predicted   0.7110             1.00851  0.91934                 0.9482
cvpred      0.6112             0.99496  0.92245                 0.9209
LTR         0.7010             0.99000  0.91900                 0.9790
CV residual 0.0898            -0.00496 -0.00345                 0.0581
            Botswana   Canada   Chad Congo, Dem. Rep.  Cyprus
Predicted      0.814 0.961566  0.588            0.598  0.9692
cvpred         0.688 0.989304  0.568            0.486  0.9864
LTR            0.845 0.990000  0.345            0.668  0.9830
CV residual    0.157 0.000696 -0.223            0.182 -0.0034
            Equatorial Guinea Estonia  Italy Kenya Latvia Lithuania
Predicted               0.786  0.9902  1.055 0.789 0.9706   1.01779
cvpred                  0.682  0.9728  1.054 0.685 0.9522   0.98718
LTR                     0.939  0.9980  0.989 0.874 0.9980   0.99700
CV residual             0.257  0.0252 -0.065 0.189 0.0458   0.00982
            Namibia  Nepal Netherlands Paraguay Puerto Rico Serbia
Predicted     0.935  0.673      0.9930    0.866      0.9922 0.9748
cvpred        0.772  0.734      1.0195    0.877      0.9846 0.9473
LTR           0.888  0.603      0.9900    0.939      0.9040 0.9790
CV residual   0.116 -0.131     -0.0295    0.062     -0.0806 0.0317
            South Africa   Spain Sri Lanka    Sudan Suriname Switzerland
Predicted          0.853  1.0433   0.88202  0.72559   0.9624      1.0256
cvpred             0.741  1.0248   0.90906  0.71902   0.9331      1.0458
LTR                0.930  0.9770   0.91200  0.71100   0.9470      0.9900
CV residual        0.189 -0.0478   0.00294 -0.00802   0.0139     -0.0558
            Syrian Arab Republic Tanzania Timor-Leste Ukraine Zambia
Predicted                 0.8329   0.6679       0.697  0.9201 0.6697
cvpred                    0.8625   0.6651       0.733  0.9176 0.6339
LTR                       0.8340   0.7320       0.583  0.9970 0.7120
CV residual              -0.0285   0.0669      -0.150  0.0794 0.0781

Sum of squares = 0.35    Mean square = 0.01    n = 32 

Overall (Sum over all 32 folds) 
    ms 
0.0105 




# Small dataset here, m = 4 folds

seed <- round(runif(1, min=0, max=100))

CVlm(df=ltrdata10, form.lm=g.step, m=4)
Analysis of Variance Table

Response: LTR
          Df Sum Sq Mean Sq F value  Pr(>F)
GDP        1  0.932   0.932  119.54 < 2e-16
UNEMP      1  0.006   0.006    0.72  0.3989
URBGR      1  0.158   0.158   20.30 2.0e-05
MOBILE     1  0.176   0.176   22.57 7.7e-06
LEXP       1  0.075   0.075    9.66  0.0025
Residuals 89  0.694   0.008                
Warning:

As there is >1 explanatory variable, cross-validation predicted values for
a fold are not a linear function of corresponding overall predicted
values.  Lines that are shown for the different folds are approximate

fold 1 
Observations in test set: 23 
            Brunei Darussalam China Cyprus Dominican Republic El Salvador
Predicted             0.95844 0.835 0.9643            0.89483      0.9125
cvpred                0.94636 0.822 0.9565            0.89142      0.9182
LTR                   0.95200 0.943 0.9830            0.89500      0.8450
CV residual           0.00564 0.121 0.0265            0.00358     -0.0732
             Ghana     Japan    Latvia Lithuania Macedonia, FYR Malaysia
Predicted    0.751  0.998979  0.981234    1.0253         0.9934   0.9140
cvpred       0.748  0.990961  0.998192    1.0488         1.0088   0.9028
LTR          0.673  0.990000  0.998000    0.9970         0.9730   0.9310
CV residual -0.075 -0.000961 -0.000192   -0.0518        -0.0358   0.0282
            Moldova Montenegro Mozambique   Nepal Netherlands Paraguay
Predicted     0.844     1.0265     0.6020  0.6750     1.00377   0.8612
cvpred        0.852     1.0394     0.6109  0.6708     0.99616   0.8562
LTR           0.985     0.9840     0.5610  0.6030     0.99000   0.9390
CV residual   0.133    -0.0554    -0.0499 -0.0678    -0.00616   0.0828
            Qatar Romania Singapore Suriname  Sweden Zambia
Predicted   0.871  0.9492    1.0185   0.9584  1.0213 0.6737
cvpred      0.791  0.9618    1.0067   0.9628  1.0145 0.6705
LTR         0.963  0.9770    0.9590   0.9470  0.9900 0.7120
CV residual 0.172  0.0152   -0.0477  -0.0158 -0.0245 0.0415

Sum of squares = 0.1    Mean square = 0    n = 23 

fold 2 
Observations in test set: 24 
             Bahrain Bosnia and Herzegovina  Brazil   Chad Costa Rica
Predicted    0.91953                 0.9535  0.9375  0.594     0.8920
cvpred       0.92217                 0.9286  0.9314  0.604     0.8701
LTR          0.91900                 0.9790  0.9040  0.345     0.9620
CV residual -0.00317                 0.0504 -0.0274 -0.259     0.0919
            Croatia Estonia France Georgia Guatemala Honduras Jordan
Predicted    0.9826 1.00116 0.9882   0.913     0.873   0.8821 0.9113
cvpred       0.9745 0.99465 0.9759   0.896     0.874   0.8759 0.9028
LTR          0.9880 0.99800 0.9900   0.997     0.752   0.8480 0.9260
CV residual  0.0135 0.00335 0.0141   0.101    -0.122  -0.0279 0.0232
            Kazakhstan Nigeria Poland Puerto Rico Samoa Switzerland
Predicted       0.9134   0.705 0.9864      0.9833 0.803      1.0296
cvpred          0.9247   0.724 0.9804      0.9688 0.766      1.0258
LTR             0.9970   0.613 0.9950      0.9040 0.988      0.9900
CV residual     0.0723  -0.111 0.0146     -0.0648 0.222     -0.0358
            Syrian Arab Republic Tanzania Timor-Leste Uganda Uzbekistan
Predicted                 0.8277   0.6756      0.6945  0.612      0.790
cvpred                    0.8067   0.6742      0.6827  0.616      0.787
LTR                       0.8340   0.7320      0.5830  0.732      0.994
CV residual               0.0273   0.0578     -0.0997  0.116      0.207
            Vanuatu
Predicted    0.8060
cvpred       0.8005
LTR          0.8260
CV residual  0.0255

Sum of squares = 0.25    Mean square = 0.01    n = 24 

fold 3 
Observations in test set: 24 
             Angola Armenia    Aruba Bangladesh Canada Ecuador
Predicted   0.70808  0.9737  0.98234      0.739 0.9666   0.899
cvpred      0.69377  0.9801  0.97653      0.759 0.9722   0.908
LTR         0.70100  0.9960  0.96800      0.568 0.9900   0.919
CV residual 0.00723  0.0159 -0.00853     -0.191 0.0178   0.011
            Egypt, Arab Rep.  Gabon  Greece   India Jamaica Mexico
Predicted              0.865 0.8721  1.0101  0.7678  0.9469  0.906
cvpred                 0.870 0.8585  1.0145  0.7739  0.9487  0.914
LTR                    0.720 0.8840  0.9720  0.7400  0.8660  0.931
CV residual           -0.150 0.0255 -0.0425 -0.0339 -0.0827  0.017
            Mongolia Portugal Russian Federation Saudi Arabia    Serbia
Predicted      0.817   0.9946             0.9645        1.007  0.975530
cvpred         0.819   0.9977             0.9514        1.001  0.979304
LTR            0.974   0.9520             0.9960        0.866  0.979000
CV residual    0.155  -0.0457             0.0446       -0.135 -0.000304
            South Africa Sri Lanka Trinidad and Tobago Ukraine
Predicted          0.852    0.8743              0.9322  0.9184
cvpred             0.829    0.8849              0.9215  0.9182
LTR                0.930    0.9120              0.9880  0.9970
CV residual        0.101    0.0271              0.0665  0.0788
            United States  Uruguay Yemen, Rep.
Predicted         0.97991 0.980174      0.7265
cvpred            0.98001 0.980739      0.7346
LTR               0.99000 0.981000      0.6390
CV residual       0.00999 0.000261     -0.0956

Sum of squares = 0.15    Mean square = 0.01    n = 24 

fold 4 
Observations in test set: 24 
            Antigua and Barbuda Argentina Botswana Colombia
Predicted                1.0237    0.9528   0.8096   0.9131
cvpred                   1.0232    0.9508   0.7719   0.9154
LTR                      0.9900    0.9780   0.8450   0.9340
CV residual             -0.0332    0.0272   0.0731   0.0186
            Congo, Dem. Rep. Equatorial Guinea Finland Germany Hungary
Predicted             0.6061             0.772  1.0460  1.0281  0.9714
cvpred                0.5943             0.742  1.0479  1.0275  0.9683
LTR                   0.6680             0.939  0.9990  0.9900  0.9900
CV residual           0.0737             0.197 -0.0489 -0.0375  0.0217
               Iraq   Italy  Kenya   Mali Namibia  Panama Papua New Guinea
Predicted    0.8532  1.0478 0.7916  0.647  0.9229  0.9819           0.6694
cvpred       0.8521  1.0538 0.7919  0.636  0.9196  0.9929           0.6571
LTR          0.7820  0.9890 0.8740  0.311  0.8880  0.9410           0.6060
CV residual -0.0701 -0.0648 0.0821 -0.325 -0.0316 -0.0519          -0.0511
            Slovenia   Spain    Sudan Tajikistan Turkmenistan
Predicted    0.98938  1.0417  0.72881      0.794        0.793
cvpred       0.99054  1.0486  0.71907      0.794        0.781
LTR          0.99700  0.9770  0.71100      0.997        0.996
CV residual  0.00646 -0.0716 -0.00807      0.203        0.215
            United Arab Emirates United Kingdom Vietnam
Predicted                 0.9129         1.0207  0.8844
cvpred                    0.9413         1.0247  0.8989
LTR                       0.9000         0.9900  0.9320
CV residual              -0.0413        -0.0347  0.0331

Sum of squares = 0.28    Mean square = 0.01    n = 24 

Overall (Sum over all 24 folds) 
     ms 
0.00819 

CVlm(df=ltrdata10, form.lm=g, m=4)
Analysis of Variance Table

Response: LTR
          Df Sum Sq Mean Sq F value  Pr(>F)
GDP        1  0.932   0.932  118.89 < 2e-16
UNEMP      1  0.006   0.006    0.71  0.4002
URBGR      1  0.158   0.158   20.19 2.1e-05
MOBILE     1  0.176   0.176   22.45 8.2e-06
INTERNET   1  0.003   0.003    0.34  0.5624
LEXP       1  0.077   0.077    9.79  0.0024
Residuals 88  0.689   0.008                
Warning:

As there is >1 explanatory variable, cross-validation predicted values for
a fold are not a linear function of corresponding overall predicted
values.  Lines that are shown for the different folds are approximate

plot of chunk unnamed-chunk-1


fold 1 
Observations in test set: 23 
            Brunei Darussalam China Cyprus Dominican Republic El Salvador
Predicted            0.962904 0.836 0.9692           8.98e-01      0.9197
cvpred               0.951347 0.822 0.9618           8.95e-01      0.9284
LTR                  0.952000 0.943 0.9830           8.95e-01      0.8450
CV residual          0.000653 0.121 0.0212           6.39e-05     -0.0834
              Ghana   Japan Latvia Lithuania Macedonia, FYR Malaysia
Predicted    0.7515 0.99525 0.9706    1.0178         0.9883   0.9074
cvpred       0.7477 0.98365 0.9813    1.0371         1.0004   0.8927
LTR          0.6730 0.99000 0.9980    0.9970         0.9730   0.9310
CV residual -0.0747 0.00635 0.0167   -0.0401        -0.0274   0.0383
            Moldova Montenegro Mozambique   Nepal Netherlands Paraguay
Predicted     0.837     1.0296     0.5909  0.6726      0.9930   0.8658
cvpred        0.841     1.0438     0.5936  0.6659      0.9789   0.8625
LTR           0.985     0.9840     0.5610  0.6030      0.9900   0.9390
CV residual   0.144    -0.0598    -0.0326 -0.0629      0.0111   0.0765
            Qatar Romania Singapore Suriname   Sweden Zambia
Predicted   0.867  0.9497    1.0177   0.9624  1.01213 0.6697
cvpred      0.785  0.9616    1.0044   0.9685  0.99949 0.6633
LTR         0.963  0.9770    0.9590   0.9470  0.99000 0.7120
CV residual 0.178  0.0154   -0.0454  -0.0215 -0.00949 0.0487

Sum of squares = 0.1    Mean square = 0    n = 23 

fold 2 
Observations in test set: 24 
             Bahrain Bosnia and Herzegovina  Brazil   Chad Costa Rica
Predicted    0.91934                 0.9482  0.9411  0.588     0.8976
cvpred       0.92198                 0.9262  0.9341  0.599     0.8751
LTR          0.91900                 0.9790  0.9040  0.345     0.9620
CV residual -0.00298                 0.0528 -0.0301 -0.254     0.0869
            Croatia Estonia France Georgia Guatemala Honduras Jordan
Predicted    0.9802  0.9902 0.9827  0.9148     0.882   0.8890  0.916
cvpred       0.9734  0.9878 0.9733  0.8975     0.880   0.8804  0.906
LTR          0.9880  0.9980 0.9900  0.9970     0.752   0.8480  0.926
CV residual  0.0146  0.0102 0.0167  0.0995    -0.128  -0.0324  0.020
            Kazakhstan Nigeria Poland Puerto Rico Samoa Switzerland
Predicted       0.9165   0.694 0.9801      0.9922 0.816      1.0256
cvpred          0.9261   0.716 0.9767      0.9755 0.776      1.0238
LTR             0.9970   0.613 0.9950      0.9040 0.988      0.9900
CV residual     0.0709  -0.103 0.0183     -0.0715 0.212     -0.0338
            Syrian Arab Republic Tanzania Timor-Leste Uganda Uzbekistan
Predicted                 0.8329   0.6679       0.697  0.602      0.787
cvpred                    0.8111   0.6688       0.685  0.608      0.785
LTR                       0.8340   0.7320       0.583  0.732      0.994
CV residual               0.0229   0.0632      -0.102  0.124      0.209
            Vanuatu
Predicted    0.8154
cvpred       0.8068
LTR          0.8260
CV residual  0.0192

Sum of squares = 0.25    Mean square = 0.01    n = 24 

fold 3 
Observations in test set: 24 
             Angola Armenia  Aruba Bangladesh Canada Ecuador
Predicted   0.71097 0.97825  0.979      0.741 0.9616 0.90272
cvpred      0.69812 0.98808  0.974      0.762 0.9655 0.91452
LTR         0.70100 0.99600  0.968      0.568 0.9900 0.91900
CV residual 0.00288 0.00792 -0.006     -0.194 0.0245 0.00448
            Egypt, Arab Rep.   Gabon  Greece   India Jamaica  Mexico
Predicted              0.862 0.88616  1.0202  0.7702  0.9513 0.91314
cvpred                 0.869 0.87829  1.0283  0.7784  0.9563 0.92451
LTR                    0.720 0.88400  0.9720  0.7400  0.8660 0.93100
CV residual           -0.149 0.00571 -0.0563 -0.0384 -0.0903 0.00649
            Mongolia Portugal Russian Federation Saudi Arabia   Serbia
Predicted      0.822   0.9981              0.963        1.013  0.97483
cvpred         0.826   1.0032              0.952        1.011  0.98023
LTR            0.974   0.9520              0.996        0.866  0.97900
CV residual    0.148  -0.0512              0.044       -0.145 -0.00123
            South Africa Sri Lanka Trinidad and Tobago Ukraine
Predicted         0.8526    0.8820              0.9308  0.9201
cvpred            0.8318    0.8964              0.9213  0.9226
LTR               0.9300    0.9120              0.9880  0.9970
CV residual       0.0982    0.0156              0.0667  0.0744
            United States  Uruguay Yemen, Rep.
Predicted          0.9771  0.98160       0.726
cvpred             0.9767  0.98414       0.735
LTR                0.9900  0.98100       0.639
CV residual        0.0133 -0.00314      -0.096

Sum of squares = 0.15    Mean square = 0.01    n = 24 

fold 4 
Observations in test set: 24 
            Antigua and Barbuda Argentina Botswana Colombia
Predicted                1.0085    0.9519   0.8144   0.9148
cvpred                   1.0247    0.9509   0.7709   0.9153
LTR                      0.9900    0.9780   0.8450   0.9340
CV residual             -0.0347    0.0271   0.0741   0.0187
            Congo, Dem. Rep. Equatorial Guinea Finland Germany Hungary
Predicted             0.5975             0.786  1.0368  1.0207   0.963
cvpred                0.5948             0.740  1.0487  1.0282   0.969
LTR                   0.6680             0.939  0.9990  0.9900   0.990
CV residual           0.0732             0.199 -0.0497 -0.0382   0.021
               Iraq   Italy  Kenya   Mali Namibia  Panama Papua New Guinea
Predicted    0.8682  1.0550 0.7887  0.642  0.9354  0.9843           0.6729
cvpred       0.8507  1.0532 0.7921  0.636  0.9182  0.9929           0.6566
LTR          0.7820  0.9890 0.8740  0.311  0.8880  0.9410           0.6060
CV residual -0.0687 -0.0642 0.0819 -0.325 -0.0302 -0.0519          -0.0506
            Slovenia   Spain    Sudan Tajikistan Turkmenistan
Predicted    0.98437  1.0433  0.72559      0.791        0.804
cvpred       0.99103  1.0485  0.71924      0.795        0.780
LTR          0.99700  0.9770  0.71100      0.997        0.996
CV residual  0.00597 -0.0715 -0.00824      0.202        0.216
            United Arab Emirates United Kingdom Vietnam
Predicted                 0.9115         1.0115  0.8795
cvpred                    0.9414         1.0256  0.8998
LTR                       0.9000         0.9900  0.9320
CV residual              -0.0414        -0.0356  0.0322

Sum of squares = 0.28    Mean square = 0.01    n = 24 

Overall (Sum over all 24 folds) 
     ms 
0.00822 




# Compare several cross-validation at one time

par(mfrow=c(2,3))

for(i in 1:3){

  seed <- round(runif(1, min=0, max=100))

  CVlm(df=ltrdata10, form.lm=g.step, m=4, seed=seed)

  CVlm(df=ltrdata10, form.lm=g, m=4, seed=seed)}
Analysis of Variance Table

Response: LTR
          Df Sum Sq Mean Sq F value  Pr(>F)
GDP        1  0.932   0.932  119.54 < 2e-16
UNEMP      1  0.006   0.006    0.72  0.3989
URBGR      1  0.158   0.158   20.30 2.0e-05
MOBILE     1  0.176   0.176   22.57 7.7e-06
LEXP       1  0.075   0.075    9.66  0.0025
Residuals 89  0.694   0.008                
Warning:

As there is >1 explanatory variable, cross-validation predicted values for
a fold are not a linear function of corresponding overall predicted
values.  Lines that are shown for the different folds are approximate

fold 1 
Observations in test set: 23 
             Brazil Brunei Darussalam Congo, Dem. Rep. Cyprus El Salvador
Predicted    0.9375          9.58e-01            0.606 0.9643      0.9125
cvpred       0.9399          9.52e-01            0.477 0.9498      0.9389
LTR          0.9040          9.52e-01            0.668 0.9830      0.8450
CV residual -0.0359         -3.43e-05            0.191 0.0332     -0.0939
            Equatorial Guinea Georgia Germany   Ghana Honduras   Italy
Predicted               0.772  0.9128  1.0281  0.7515   0.8821  1.0478
cvpred                  0.716  0.9126  1.0353  0.7439   0.9048  1.0583
LTR                     0.939  0.9970  0.9900  0.6730   0.8480  0.9890
CV residual             0.223  0.0844 -0.0453 -0.0709  -0.0568 -0.0693
            Jamaica Kenya Lithuania Montenegro Qatar Romania Samoa
Predicted    0.9469 0.792     1.025      1.027 0.871 0.94919 0.803
cvpred       0.9653 0.727     1.051      1.052 0.794 0.97253 0.728
LTR          0.8660 0.874     0.997      0.984 0.963 0.97700 0.988
CV residual -0.0993 0.147    -0.054     -0.068 0.169 0.00447 0.260
            Slovenia Sri Lanka United Arab Emirates Uzbekistan Zambia
Predicted    0.98938    0.8743                0.913      0.790 0.6737
cvpred       0.99035    0.8897                0.854      0.805 0.6283
LTR          0.99700    0.9120                0.900      0.994 0.7120
CV residual  0.00665    0.0223                0.046      0.189 0.0837

Sum of squares = 0.3    Mean square = 0.01    n = 23 

fold 2 
Observations in test set: 24 
              Angola  Bahrain Botswana Ecuador Egypt, Arab Rep.  Estonia
Predicted    0.70808  0.91953   0.8096  0.8987            0.865  1.00116
cvpred       0.70842  0.92541   0.7866  0.9003            0.863  1.00398
LTR          0.70100  0.91900   0.8450  0.9190            0.720  0.99800
CV residual -0.00742 -0.00641   0.0584  0.0187           -0.143 -0.00598
            Hungary  India Moldova Mongolia Mozambique Nigeria Poland
Predicted    0.9714  0.768   0.844    0.817      0.602  0.7050 0.9864
cvpred       0.9695  0.760   0.838    0.809      0.592  0.7004 0.9838
LTR          0.9900  0.740   0.985    0.974      0.561  0.6130 0.9950
CV residual  0.0205 -0.020   0.147    0.165     -0.031 -0.0874 0.0112
            Portugal Saudi Arabia    Serbia  Sweden Switzerland Tanzania
Predicted     0.9946        1.007  0.975530  1.0213       1.030   0.6756
cvpred        0.9992        1.006  0.979169  1.0263       1.032   0.6741
LTR           0.9520        0.866  0.979000  0.9900       0.990   0.7320
CV residual  -0.0472       -0.140 -0.000169 -0.0363      -0.042   0.0579
            Timor-Leste Trinidad and Tobago Turkmenistan United Kingdom
Predicted         0.695              0.9322        0.793         1.0207
cvpred            0.694              0.9248        0.780         1.0232
LTR               0.583              0.9880        0.996         0.9900
CV residual      -0.111              0.0632        0.216        -0.0332
            Yemen, Rep.
Predicted        0.7265
cvpred           0.7306
LTR              0.6390
CV residual     -0.0916

Sum of squares = 0.18    Mean square = 0.01    n = 24 

fold 3 
Observations in test set: 24 
            Argentina Armenia Bosnia and Herzegovina  Canada   Chad
Predicted      0.9528  0.9737                 0.9535 0.96659  0.594
cvpred         0.9513  0.9639                 0.9501 0.98305  0.620
LTR            0.9780  0.9960                 0.9790 0.99000  0.345
CV residual    0.0267  0.0321                 0.0289 0.00695 -0.275
            Croatia Dominican Republic Finland   France Guatemala    Iraq
Predicted   0.98260            0.89483  1.0460  0.98818     0.873  0.8532
cvpred      0.98602            0.89374  1.0493  0.99845     0.862  0.8573
LTR         0.98800            0.89500  0.9990  0.99000     0.752  0.7820
CV residual 0.00198            0.00126 -0.0503 -0.00845    -0.110 -0.0753
            Kazakhstan Mexico Netherlands  Panama Paraguay Puerto Rico
Predicted       0.9134 0.9056      1.0038  0.9819   0.8612      0.9833
cvpred          0.9181 0.9106      1.0129  0.9651   0.8566      0.9982
LTR             0.9970 0.9310      0.9900  0.9410   0.9390      0.9040
CV residual     0.0789 0.0204     -0.0229 -0.0241   0.0824     -0.0942
            Russian Federation Singapore   Sudan Suriname Uganda Uruguay
Predicted               0.9645    1.0185  0.7288  0.95836  0.612 0.98017
cvpred                  0.9644    1.0205  0.7417  0.95248  0.617 0.97914
LTR                     0.9960    0.9590  0.7110  0.94700  0.732 0.98100
CV residual             0.0316   -0.0615 -0.0307 -0.00548  0.115 0.00186
            Vietnam
Predicted    0.8844
cvpred       0.8623
LTR          0.9320
CV residual  0.0697

Sum of squares = 0.15    Mean square = 0.01    n = 24 

fold 4 
Observations in test set: 24 
            Antigua and Barbuda    Aruba Bangladesh  China Colombia
Predicted                1.0237  0.98234      0.739 0.8355   0.9131
cvpred                   1.0079  0.97725      0.760 0.8503   0.9145
LTR                      0.9900  0.96800      0.568 0.9430   0.9340
CV residual             -0.0179 -0.00925     -0.192 0.0927   0.0195
            Costa Rica  Gabon  Greece   Japan Jordan Latvia Macedonia, FYR
Predicted       0.8920 0.8721  1.0101  0.9990 0.9113 0.9812         0.9934
cvpred          0.9048 0.8699  1.0075  1.0015 0.9109 0.9759         0.9857
LTR             0.9620 0.8840  0.9720  0.9900 0.9260 0.9980         0.9730
CV residual     0.0572 0.0141 -0.0355 -0.0115 0.0151 0.0221        -0.0127
            Malaysia   Mali Namibia  Nepal Papua New Guinea South Africa
Predicted     0.9140  0.647  0.9229  0.675           0.6694       0.8518
cvpred        0.9141  0.667  0.9174  0.706           0.7006       0.8467
LTR           0.9310  0.311  0.8880  0.603           0.6060       0.9300
CV residual   0.0169 -0.356 -0.0294 -0.103          -0.0946       0.0833
              Spain Syrian Arab Republic Tajikistan Ukraine United States
Predicted    1.0417              0.82766      0.794  0.9184       0.97991
cvpred       1.0367              0.84356      0.801  0.9128       0.98249
LTR          0.9770              0.83400      0.997  0.9970       0.99000
CV residual -0.0597             -0.00956      0.196  0.0842       0.00751
            Vanuatu
Predicted   0.80602
cvpred      0.81906
LTR         0.82600
CV residual 0.00694

Sum of squares = 0.26    Mean square = 0.01    n = 24 

Overall (Sum over all 24 folds) 
     ms 
0.00931 
Analysis of Variance Table

Response: LTR
          Df Sum Sq Mean Sq F value  Pr(>F)
GDP        1  0.932   0.932  118.89 < 2e-16
UNEMP      1  0.006   0.006    0.71  0.4002
URBGR      1  0.158   0.158   20.19 2.1e-05
MOBILE     1  0.176   0.176   22.45 8.2e-06
INTERNET   1  0.003   0.003    0.34  0.5624
LEXP       1  0.077   0.077    9.79  0.0024
Residuals 88  0.689   0.008                
Warning:

As there is >1 explanatory variable, cross-validation predicted values for
a fold are not a linear function of corresponding overall predicted
values.  Lines that are shown for the different folds are approximate

fold 1 
Observations in test set: 23 
             Brazil Brunei Darussalam Congo, Dem. Rep. Cyprus El Salvador
Predicted    0.9411           0.96290            0.598  0.969       0.920
cvpred       0.9441           0.95637            0.468  0.955       0.946
LTR          0.9040           0.95200            0.668  0.983       0.845
CV residual -0.0401          -0.00437            0.200  0.028      -0.101
            Equatorial Guinea Georgia Germany   Ghana Honduras   Italy
Predicted               0.786  0.9148  1.0207  0.7515    0.889  1.0550
cvpred                  0.728  0.9148  1.0307  0.7436    0.910  1.0652
LTR                     0.939  0.9970  0.9900  0.6730    0.848  0.9890
CV residual             0.211  0.0822 -0.0407 -0.0706   -0.062 -0.0762
            Jamaica Kenya Lithuania Montenegro Qatar Romania Samoa
Predicted     0.951 0.789    1.0178     1.0296 0.867 0.94973 0.816
cvpred        0.971 0.721    1.0469     1.0546 0.783 0.97527 0.742
LTR           0.866 0.874    0.9970     0.9840 0.963 0.97700 0.988
CV residual  -0.105 0.153   -0.0499    -0.0706 0.180 0.00173 0.246
            Slovenia Sri Lanka United Arab Emirates Uzbekistan Zambia
Predicted    0.98437    0.8820               0.9115      0.787 0.6697
cvpred       0.98779    0.8979               0.8457      0.803 0.6247
LTR          0.99700    0.9120               0.9000      0.994 0.7120
CV residual  0.00921    0.0141               0.0543      0.191 0.0873

Sum of squares = 0.3    Mean square = 0.01    n = 23 

fold 2 
Observations in test set: 24 
              Angola Bahrain Botswana Ecuador Egypt, Arab Rep.   Estonia
Predicted    0.71097  0.9193   0.8144  0.9027            0.862  0.990179
cvpred       0.70923  0.9253   0.7883  0.9018            0.861  0.998903
LTR          0.70100  0.9190   0.8450  0.9190            0.720  0.998000
CV residual -0.00823 -0.0063   0.0567  0.0172           -0.141 -0.000903
            Hungary   India Moldova Mongolia Mozambique Nigeria Poland
Predicted    0.9632  0.7702   0.837    0.822      0.591  0.6938 0.9801
cvpred       0.9657  0.7609   0.835    0.811      0.587  0.6953 0.9808
LTR          0.9900  0.7400   0.985    0.974      0.561  0.6130 0.9950
CV residual  0.0243 -0.0209   0.150    0.163     -0.026 -0.0823 0.0142
            Portugal Saudi Arabia   Serbia  Sweden Switzerland Tanzania
Predicted     0.9981        1.013 0.974830  1.0121      1.0256   0.6679
cvpred        1.0004        1.009 0.978462  1.0221      1.0301   0.6706
LTR           0.9520        0.866 0.979000  0.9900      0.9900   0.7320
CV residual  -0.0484       -0.143 0.000538 -0.0321     -0.0401   0.0614
            Timor-Leste Trinidad and Tobago Turkmenistan United Kingdom
Predicted         0.697              0.9308        0.804          1.012
cvpred            0.695              0.9241        0.785          1.019
LTR               0.583              0.9880        0.996          0.990
CV residual      -0.112              0.0639        0.211         -0.029
            Yemen, Rep.
Predicted        0.7263
cvpred           0.7302
LTR              0.6390
CV residual     -0.0912

Sum of squares = 0.18    Mean square = 0.01    n = 24 

fold 3 
Observations in test set: 24 
            Argentina Armenia Bosnia and Herzegovina Canada   Chad Croatia
Predicted      0.9519  0.9782                 0.9482 0.9616  0.588 0.98020
cvpred         0.9504  0.9742                 0.9418 0.9717  0.607 0.98192
LTR            0.9780  0.9960                 0.9790 0.9900  0.345 0.98800
CV residual    0.0276  0.0218                 0.0372 0.0183 -0.262 0.00608
            Dominican Republic Finland  France Guatemala   Iraq Kazakhstan
Predicted              0.89786   1.037 0.98271     0.882  0.868     0.9165
cvpred                 0.89934   1.033 0.98722     0.878  0.883     0.9237
LTR                    0.89500   0.999 0.99000     0.752  0.782     0.9970
CV residual           -0.00434  -0.034 0.00278    -0.126 -0.101     0.0733
             Mexico Netherlands  Panama Paraguay Puerto Rico
Predicted   0.91314     0.99296  0.9843   0.8658       0.992
cvpred      0.92305     0.99259  0.9715   0.8654       1.012
LTR         0.93100     0.99000  0.9410   0.9390       0.904
CV residual 0.00795    -0.00259 -0.0305   0.0736      -0.108
            Russian Federation Singapore   Sudan Suriname Uganda  Uruguay
Predicted               0.9632    1.0177  0.7256   0.9624  0.602  0.98160
cvpred                  0.9634    1.0185  0.7348   0.9611  0.598  0.98224
LTR                     0.9960    0.9590  0.7110   0.9470  0.732  0.98100
CV residual             0.0326   -0.0595 -0.0238  -0.0141  0.134 -0.00124
            Vietnam
Predicted    0.8795
cvpred       0.8562
LTR          0.9320
CV residual  0.0758

Sum of squares = 0.15    Mean square = 0.01    n = 24 

fold 4 
Observations in test set: 24 
            Antigua and Barbuda    Aruba Bangladesh  China Colombia
Predicted              1.008506  0.97944      0.741 0.8362   0.9148
cvpred                 0.989708  0.97329      0.763 0.8516   0.9167
LTR                    0.990000  0.96800      0.568 0.9430   0.9340
CV residual            0.000292 -0.00529     -0.195 0.0914   0.0173
            Costa Rica    Gabon  Greece    Japan  Jordan Latvia
Predicted       0.8976  0.88616  1.0202  0.99525 0.91584 0.9706
cvpred          0.9121  0.88696  1.0198  0.99737 0.91672 0.9637
LTR             0.9620  0.88400  0.9720  0.99000 0.92600 0.9980
CV residual     0.0499 -0.00296 -0.0478 -0.00737 0.00928 0.0343
            Macedonia, FYR Malaysia   Mali Namibia  Nepal Papua New Guinea
Predicted          0.98826   0.9074  0.642  0.9354  0.673           0.6729
cvpred             0.98159   0.9062  0.662  0.9367  0.703           0.7045
LTR                0.97300   0.9310  0.311  0.8880  0.603           0.6060
CV residual       -0.00859   0.0248 -0.351 -0.0487 -0.100          -0.0985
            South Africa  Spain Syrian Arab Republic Tajikistan Ukraine
Predicted         0.8526  1.043               0.8329      0.791  0.9201
cvpred            0.8485  1.040               0.8505      0.796  0.9136
LTR               0.9300  0.977               0.8340      0.997  0.9970
CV residual       0.0815 -0.063              -0.0165      0.201  0.0834
            United States Vanuatu
Predicted          0.9771  0.8154
cvpred             0.9799  0.8299
LTR                0.9900  0.8260
CV residual        0.0101 -0.0039

Sum of squares = 0.26    Mean square = 0.01    n = 24 

Overall (Sum over all 24 folds) 
     ms 
0.00939 
Analysis of Variance Table

Response: LTR
          Df Sum Sq Mean Sq F value  Pr(>F)
GDP        1  0.932   0.932  119.54 < 2e-16
UNEMP      1  0.006   0.006    0.72  0.3989
URBGR      1  0.158   0.158   20.30 2.0e-05
MOBILE     1  0.176   0.176   22.57 7.7e-06
LEXP       1  0.075   0.075    9.66  0.0025
Residuals 89  0.694   0.008                
Warning:

As there is >1 explanatory variable, cross-validation predicted values for
a fold are not a linear function of corresponding overall predicted
values.  Lines that are shown for the different folds are approximate

fold 1 
Observations in test set: 23 
            Angola  Aruba Bangladesh Brunei Darussalam   Chad Ecuador
Predicted   0.7081  0.982      0.739            0.9584  0.594  0.8987
cvpred      0.6707  0.994      0.756            0.9415  0.620  0.8858
LTR         0.7010  0.968      0.568            0.9520  0.345  0.9190
CV residual 0.0303 -0.026     -0.188            0.0105 -0.275  0.0332
            Equatorial Guinea Georgia Germany    Iraq Kenya Montenegro
Predicted               0.772   0.913  1.0281  0.8532 0.792     1.0265
cvpred                  0.758   0.923  1.0388  0.8435 0.746     1.0249
LTR                     0.939   0.997  0.9900  0.7820 0.874     0.9840
CV residual             0.181   0.074 -0.0488 -0.0615 0.128    -0.0409
            Paraguay Qatar Romania Saudi Arabia Slovenia
Predicted     0.8612 0.871  0.9492        1.007  0.98938
cvpred        0.8529 0.687  0.9788        0.981  1.00213
LTR           0.9390 0.963  0.9770        0.866  0.99700
CV residual   0.0861 0.276 -0.0018       -0.115 -0.00513
            Syrian Arab Republic Uganda Ukraine United Arab Emirates
Predicted                 0.8277  0.612  0.9184                0.913
cvpred                    0.8181  0.588  0.9531                0.758
LTR                       0.8340  0.732  0.9970                0.900
CV residual               0.0159  0.144  0.0439                0.142
            Vanuatu Vietnam
Predicted    0.8060  0.8844
cvpred       0.7919  0.8683
LTR          0.8260  0.9320
CV residual  0.0341  0.0637

Sum of squares = 0.32    Mean square = 0.01    n = 23 

fold 2 
Observations in test set: 24 
             Bahrain Brazil China Colombia Croatia Cyprus  Estonia  Gabon
Predicted    0.91953  0.937 0.835   0.9131   0.983 0.9643 1.00e+00 0.8721
cvpred       0.92459  0.927 0.819   0.9072   0.974 0.9491 9.98e-01 0.8727
LTR          0.91900  0.904 0.943   0.9340   0.988 0.9830 9.98e-01 0.8840
CV residual -0.00559 -0.023 0.124   0.0268   0.014 0.0339 8.93e-05 0.0113
            Honduras Jamaica Kazakhstan Lithuania Moldova Netherlands
Predicted     0.8821  0.9469     0.9134    1.0253   0.844      1.0038
cvpred        0.8891  0.9431     0.9077    1.0237   0.837      0.9918
LTR           0.8480  0.8660     0.9970    0.9970   0.985      0.9900
CV residual  -0.0411 -0.0771     0.0893   -0.0267   0.148     -0.0018
            Papua New Guinea Samoa Singapore Tanzania Trinidad and Tobago
Predicted             0.6694 0.803    1.0185   0.6756              0.9322
cvpred                0.6246 0.753    1.0158   0.6618              0.9339
LTR                   0.6060 0.988    0.9590   0.7320              0.9880
CV residual          -0.0186 0.235   -0.0568   0.0702              0.0541
            Turkmenistan United Kingdom United States Yemen, Rep. Zambia
Predicted          0.793         1.0207        0.9799      0.7265 0.6737
cvpred             0.768         1.0146        0.9632      0.7099 0.6531
LTR                0.996         0.9900        0.9900      0.6390 0.7120
CV residual        0.228        -0.0246        0.0268     -0.0709 0.0589

Sum of squares = 0.18    Mean square = 0.01    n = 24 

fold 3 
Observations in test set: 24 
            Antigua and Barbuda Argentina Bosnia and Herzegovina Botswana
Predicted                1.0237    0.9528                 0.9535   0.8096
cvpred                   1.0234    0.9588                 0.9559   0.8135
LTR                      0.9900    0.9780                 0.9790   0.8450
CV residual             -0.0334    0.0192                 0.0231   0.0315
            Dominican Republic Egypt, Arab Rep. Finland  Ghana   India
Predicted               0.8948            0.865  1.0460  0.751  0.7678
cvpred                  0.9059            0.878  1.0446  0.773  0.7898
LTR                     0.8950            0.720  0.9990  0.673  0.7400
CV residual            -0.0109           -0.158 -0.0456 -0.100 -0.0498
              Italy   Japan Malaysia   Mali  Nepal  Panama Portugal
Predicted    1.0478  0.9990  0.91402  0.647  0.675  0.9819   0.9946
cvpred       1.0476  1.0034  0.92707  0.676  0.706  0.9904   0.9975
LTR          0.9890  0.9900  0.93100  0.311  0.603  0.9410   0.9520
CV residual -0.0586 -0.0134  0.00393 -0.365 -0.103 -0.0494  -0.0455
            Russian Federation Serbia   Spain Suriname Switzerland
Predicted               0.9645 0.9755  1.0417   0.9584      1.0296
cvpred                  0.9669 0.9768  1.0385   0.9634      1.0312
LTR                     0.9960 0.9790  0.9770   0.9470      0.9900
CV residual             0.0291 0.0022 -0.0615  -0.0164     -0.0412
            Timor-Leste  Uruguay Uzbekistan
Predicted         0.695  0.98017      0.790
cvpred            0.725  0.98468      0.813
LTR               0.583  0.98100      0.994
CV residual      -0.142 -0.00368      0.181

Sum of squares = 0.25    Mean square = 0.01    n = 24 

fold 4 
Observations in test set: 24 
            Armenia Canada Congo, Dem. Rep. Costa Rica El Salvador
Predicted    0.9737 0.9666           0.6061     0.8920      0.9125
cvpred       0.9682 0.9749           0.6164     0.8896      0.9022
LTR          0.9960 0.9900           0.6680     0.9620      0.8450
CV residual  0.0278 0.0151           0.0516     0.0724     -0.0572
              France  Greece Guatemala Hungary Jordan Latvia
Predicted    0.98818  1.0101     0.873  0.9714 0.9113 0.9812
cvpred       0.99525  1.0151     0.861  0.9714 0.9067 0.9844
LTR          0.99000  0.9720     0.752  0.9900 0.9260 0.9980
CV residual -0.00525 -0.0431    -0.109  0.0186 0.0193 0.0136
            Macedonia, FYR Mexico Mongolia Mozambique Namibia Nigeria
Predicted           0.9934 0.9056    0.817     0.6020  0.9229  0.7050
cvpred              0.9986 0.9018    0.805     0.5928  0.9443  0.7052
LTR                 0.9730 0.9310    0.974     0.5610  0.8880  0.6130
CV residual        -0.0256 0.0292    0.169    -0.0318 -0.0563 -0.0922
            Poland Puerto Rico South Africa Sri Lanka   Sudan Sweden
Predicted   0.9864      0.9833       0.8518    0.8743  0.7288  1.021
cvpred      0.9844      0.9917       0.8604    0.8617  0.7237  1.028
LTR         0.9950      0.9040       0.9300    0.9120  0.7110  0.990
CV residual 0.0106     -0.0877       0.0696    0.0503 -0.0127 -0.038
            Tajikistan
Predicted        0.794
cvpred           0.774
LTR              0.997
CV residual      0.223

Sum of squares = 0.14    Mean square = 0.01    n = 24 

Overall (Sum over all 24 folds) 
     ms 
0.00943 
Analysis of Variance Table

Response: LTR
          Df Sum Sq Mean Sq F value  Pr(>F)
GDP        1  0.932   0.932  118.89 < 2e-16
UNEMP      1  0.006   0.006    0.71  0.4002
URBGR      1  0.158   0.158   20.19 2.1e-05
MOBILE     1  0.176   0.176   22.45 8.2e-06
INTERNET   1  0.003   0.003    0.34  0.5624
LEXP       1  0.077   0.077    9.79  0.0024
Residuals 88  0.689   0.008                
Warning:

As there is >1 explanatory variable, cross-validation predicted values for
a fold are not a linear function of corresponding overall predicted
values.  Lines that are shown for the different folds are approximate

fold 1 
Observations in test set: 23 
            Angola   Aruba Bangladesh Brunei Darussalam   Chad Ecuador
Predicted   0.7110  0.9794      0.741           0.96290  0.588  0.9027
cvpred      0.6761  0.9917      0.757           0.94749  0.614  0.8902
LTR         0.7010  0.9680      0.568           0.95200  0.345  0.9190
CV residual 0.0249 -0.0237     -0.189           0.00451 -0.269  0.0288
            Equatorial Guinea Georgia Germany    Iraq Kenya Montenegro
Predicted               0.786  0.9148  1.0207  0.8682 0.789     1.0296
cvpred                  0.778  0.9254  1.0306  0.8627 0.742     1.0292
LTR                     0.939  0.9970  0.9900  0.7820 0.874     0.9840
CV residual             0.161  0.0716 -0.0406 -0.0807 0.132    -0.0452
            Paraguay Qatar  Romania Saudi Arabia Slovenia
Predicted     0.8658 0.867  0.94973        1.013 0.984373
cvpred        0.8584 0.679  0.98061        0.989 0.996675
LTR           0.9390 0.963  0.97700        0.866 0.997000
CV residual   0.0806 0.284 -0.00361       -0.123 0.000325
            Syrian Arab Republic Uganda Ukraine United Arab Emirates
Predicted                 0.8329  0.602  0.9201                0.912
cvpred                    0.8238  0.575  0.9561                0.754
LTR                       0.8340  0.732  0.9970                0.900
CV residual               0.0102  0.157  0.0409                0.146
            Vanuatu Vietnam
Predicted    0.8154  0.8795
cvpred       0.8032  0.8605
LTR          0.8260  0.9320
CV residual  0.0228  0.0715

Sum of squares = 0.32    Mean square = 0.01    n = 23 

fold 2 
Observations in test set: 24 
             Bahrain  Brazil China Colombia Croatia Cyprus Estonia  Gabon
Predicted    0.91934  0.9411 0.836   0.9148  0.9802 0.9692 0.99018 0.8862
cvpred       0.92457  0.9271 0.819   0.9072  0.9739 0.9492 0.99763 0.8731
LTR          0.91900  0.9040 0.943   0.9340  0.9880 0.9830 0.99800 0.8840
CV residual -0.00557 -0.0231 0.124   0.0268  0.0141 0.0338 0.00037 0.0109
            Honduras Jamaica Kazakhstan Lithuania Moldova Netherlands
Predicted     0.8890  0.9513     0.9165    1.0178   0.837     0.99296
cvpred        0.8893  0.9432     0.9077    1.0235   0.837     0.99154
LTR           0.8480  0.8660     0.9970    0.9970   0.985     0.99000
CV residual  -0.0413 -0.0772     0.0893   -0.0265   0.148    -0.00154
            Papua New Guinea Samoa Singapore Tanzania Trinidad and Tobago
Predicted             0.6729 0.816    1.0177   0.6679              0.9308
cvpred                0.6247 0.754    1.0158   0.6616              0.9338
LTR                   0.6060 0.988    0.9590   0.7320              0.9880
CV residual          -0.0187 0.234   -0.0568   0.0704              0.0542
            Turkmenistan United Kingdom United States Yemen, Rep. Zambia
Predicted          0.804         1.0115        0.9771       0.726 0.6697
cvpred             0.769         1.0144        0.9632       0.710 0.6531
LTR                0.996         0.9900        0.9900       0.639 0.7120
CV residual        0.227        -0.0244        0.0268      -0.071 0.0589

Sum of squares = 0.18    Mean square = 0.01    n = 24 

fold 3 
Observations in test set: 24 
            Antigua and Barbuda Argentina Bosnia and Herzegovina Botswana
Predicted                1.0085    0.9519                 0.9482   0.8144
cvpred                   1.0109    0.9576                 0.9512   0.8178
LTR                      0.9900    0.9780                 0.9790   0.8450
CV residual             -0.0209    0.0204                 0.0278   0.0272
            Dominican Republic Egypt, Arab Rep. Finland  Ghana   India
Predicted               0.8979            0.862  1.0368  0.752  0.7702
cvpred                  0.9079            0.876  1.0368  0.773  0.7915
LTR                     0.8950            0.720  0.9990  0.673  0.7400
CV residual            -0.0129           -0.156 -0.0378 -0.100 -0.0515
              Italy    Japan Malaysia   Mali  Nepal  Panama Portugal
Predicted    1.0550  0.99525  0.90740  0.642  0.673  0.9843   0.9981
cvpred       1.0527  0.99995  0.92144  0.672  0.704  0.9917   0.9998
LTR          0.9890  0.99000  0.93100  0.311  0.603  0.9410   0.9520
CV residual -0.0637 -0.00995  0.00956 -0.361 -0.101 -0.0507  -0.0478
            Russian Federation  Serbia   Spain Suriname Switzerland
Predicted               0.9632 0.97483  1.0433   0.9624      1.0256
cvpred                  0.9656 0.97574  1.0392   0.9662      1.0276
LTR                     0.9960 0.97900  0.9770   0.9470      0.9900
CV residual             0.0304 0.00326 -0.0622  -0.0192     -0.0376
            Timor-Leste Uruguay Uzbekistan
Predicted         0.697  0.9816      0.787
cvpred            0.727  0.9853      0.810
LTR               0.583  0.9810      0.994
CV residual      -0.144 -0.0043      0.184

Sum of squares = 0.25    Mean square = 0.01    n = 24 

fold 4 
Observations in test set: 24 
            Armenia Canada Congo, Dem. Rep. Costa Rica El Salvador  France
Predicted    0.9782 0.9616            0.598     0.8976      0.9197 0.98271
cvpred       0.9782 0.9643            0.593     0.9006      0.9172 0.98479
LTR          0.9960 0.9900            0.668     0.9620      0.8450 0.99000
CV residual  0.0178 0.0257            0.075     0.0614     -0.0722 0.00521
             Greece Guatemala Hungary Jordan Latvia Macedonia, FYR Mexico
Predicted    1.0202     0.882  0.9632 0.9158 0.9706          0.988 0.9131
cvpred       1.0342     0.879  0.9561 0.9167 0.9633          0.989 0.9163
LTR          0.9720     0.752  0.9900 0.9260 0.9980          0.973 0.9310
CV residual -0.0622    -0.127  0.0339 0.0093 0.0347         -0.016 0.0147
            Mongolia Mozambique Namibia Nigeria Poland Puerto Rico
Predicted      0.822    0.59095  0.9354   0.694 0.9801       0.992
cvpred         0.814    0.56682  0.9647   0.680 0.9732       1.007
LTR            0.974    0.56100  0.8880   0.613 0.9950       0.904
CV residual    0.160   -0.00582 -0.0767  -0.067 0.0218      -0.103
            South Africa Sri Lanka    Sudan Sweden Tajikistan
Predicted         0.8526    0.8820  0.72559  1.012      0.791
cvpred            0.8575    0.8772  0.71442  1.011      0.770
LTR               0.9300    0.9120  0.71100  0.990      0.997
CV residual       0.0725    0.0348 -0.00342 -0.021      0.227

Sum of squares = 0.14    Mean square = 0.01    n = 24 

Overall (Sum over all 24 folds) 
     ms 
0.00953 
Analysis of Variance Table

Response: LTR
          Df Sum Sq Mean Sq F value  Pr(>F)
GDP        1  0.932   0.932  119.54 < 2e-16
UNEMP      1  0.006   0.006    0.72  0.3989
URBGR      1  0.158   0.158   20.30 2.0e-05
MOBILE     1  0.176   0.176   22.57 7.7e-06
LEXP       1  0.075   0.075    9.66  0.0025
Residuals 89  0.694   0.008                
Warning:

As there is >1 explanatory variable, cross-validation predicted values for
a fold are not a linear function of corresponding overall predicted
values.  Lines that are shown for the different folds are approximate

fold 1 
Observations in test set: 23 
            Antigua and Barbuda Armenia Botswana China Costa Rica
Predicted                1.0237  0.9737    0.810 0.835     0.8920
cvpred                   1.0186  0.9803    0.754 0.841     0.9035
LTR                      0.9900  0.9960    0.845 0.943     0.9620
CV residual             -0.0286  0.0157    0.091 0.102     0.0585
            Equatorial Guinea Finland   France Georgia  Greece Honduras
Predicted               0.772  1.0460  0.98818   0.913  1.0101   0.8821
cvpred                  0.727  1.0424  0.99237   0.921  1.0145   0.8857
LTR                     0.939  0.9990  0.99000   0.997  0.9720   0.8480
CV residual             0.212 -0.0434 -0.00237   0.076 -0.0425  -0.0377
            Hungary   India    Iraq Jamaica Jordan Kazakhstan Latvia
Predicted    0.9714  0.7678  0.8532   0.947 0.9113      0.913 0.9812
cvpred       0.9658  0.7595  0.8498   0.945 0.9151      0.895 0.9781
LTR          0.9900  0.7400  0.7820   0.866 0.9260      0.997 0.9980
CV residual  0.0242 -0.0195 -0.0678  -0.079 0.0109      0.102 0.0199
            Macedonia, FYR   Nepal Singapore    Sudan Tajikistan
Predicted            0.993  0.6750    1.0185  0.72881      0.794
cvpred               1.007  0.6788    1.0179  0.71863      0.791
LTR                  0.973  0.6030    0.9590  0.71100      0.997
CV residual         -0.034 -0.0758   -0.0589 -0.00763      0.206

Sum of squares = 0.15    Mean square = 0.01    n = 23 

fold 2 
Observations in test set: 24 
             Angola Bangladesh  Brazil Brunei Darussalam  Canada   Chad
Predicted    0.7081      0.739  0.9375            0.9584  0.9666  0.594
cvpred       0.7416      0.749  0.9465            0.9739  1.0013  0.639
LTR          0.7010      0.568  0.9040            0.9520  0.9900  0.345
CV residual -0.0406     -0.181 -0.0425           -0.0219 -0.0113 -0.294
              Cyprus   Ghana Guatemala   Italy Moldova Papua New Guinea
Predicted    0.96431  0.7515     0.873  1.0478   0.844            0.669
cvpred       0.98513  0.7529     0.856  1.0492   0.840            0.715
LTR          0.98300  0.6730     0.752  0.9890   0.985            0.606
CV residual -0.00213 -0.0799    -0.104 -0.0602   0.145           -0.109
             Poland Portugal Puerto Rico Romania Slovenia   Spain
Predicted   0.98637   0.9946       0.983  0.9492  0.98938  1.0417
cvpred      0.99041   1.0039       1.013  0.9533  1.00557  1.0537
LTR         0.99500   0.9520       0.904  0.9770  0.99700  0.9770
CV residual 0.00459  -0.0519      -0.109  0.0237 -0.00857 -0.0767
            Switzerland Tanzania Trinidad and Tobago United States
Predicted        1.0296   0.6756              0.9322        0.9799
cvpred           1.0482   0.6826              0.9322        1.0079
LTR              0.9900   0.7320              0.9880        0.9900
CV residual     -0.0582   0.0494              0.0558       -0.0179
            Uzbekistan Vietnam
Predicted        0.790  0.8844
cvpred           0.789  0.8542
LTR              0.994  0.9320
CV residual      0.205  0.0778

Sum of squares = 0.26    Mean square = 0.01    n = 24 

fold 3 
Observations in test set: 24 
            Bahrain Bosnia and Herzegovina Colombia Dominican Republic
Predicted     0.920                 0.9535   0.9131            0.89483
cvpred        0.941                 0.9471   0.9192            0.90085
LTR           0.919                 0.9790   0.9340            0.89500
CV residual  -0.022                 0.0319   0.0148           -0.00585
            Egypt, Arab Rep.  Estonia   Gabon Germany   Japan Lithuania
Predicted              0.865  1.00116  0.8721  1.0281 0.99898    1.0253
cvpred                 0.873  1.00627  0.8963  1.0252 0.98445    1.0362
LTR                    0.720  0.99800  0.8840  0.9900 0.99000    0.9970
CV residual           -0.153 -0.00827 -0.0123 -0.0352 0.00555   -0.0392
             Malaysia Montenegro Mozambique Namibia Nigeria Panama Samoa
Predicted    0.914018     1.0265      0.602   0.923   0.705  0.982 0.803
cvpred       0.931984     1.0554      0.599   0.937   0.723  1.018 0.741
LTR          0.931000     0.9840      0.561   0.888   0.613  0.941 0.988
CV residual -0.000984    -0.0714     -0.038  -0.049  -0.110 -0.077 0.247
            Saudi Arabia Suriname Sweden Timor-Leste Ukraine  Uruguay
Predicted          1.007   0.9584  1.021       0.695  0.9184  0.98017
cvpred             1.038   0.9912  1.016       0.690  0.9343  0.99024
LTR                0.866   0.9470  0.990       0.583  0.9970  0.98100
CV residual       -0.172  -0.0442 -0.026      -0.107  0.0627 -0.00924
            Zambia
Predicted   0.6737
cvpred      0.6765
LTR         0.7120
CV residual 0.0355

Sum of squares = 0.17    Mean square = 0.01    n = 24 

fold 4 
Observations in test set: 24 
            Argentina   Aruba Congo, Dem. Rep. Croatia Ecuador El Salvador
Predicted      0.9528  0.9823           0.6061 0.98260  0.8987      0.9125
cvpred         0.9518  0.9852           0.5772 0.98444  0.8855      0.9121
LTR            0.9780  0.9680           0.6680 0.98800  0.9190      0.8450
CV residual    0.0262 -0.0172           0.0908 0.00356  0.0335     -0.0671
            Kenya   Mali Mexico Mongolia Netherlands Paraguay Qatar
Predicted   0.792  0.647 0.9056    0.817     1.00377    0.861 0.871
cvpred      0.760  0.630 0.8986    0.809     0.99568    0.850 0.779
LTR         0.874  0.311 0.9310    0.974     0.99000    0.939 0.963
CV residual 0.114 -0.319 0.0324    0.165    -0.00568    0.089 0.184
            Russian Federation  Serbia South Africa Sri Lanka
Predicted               0.9645 0.97553       0.8518     0.874
cvpred                  0.9718 0.97626       0.8471     0.878
LTR                     0.9960 0.97900       0.9300     0.912
CV residual             0.0242 0.00274       0.0829     0.034
            Syrian Arab Republic Turkmenistan Uganda United Arab Emirates
Predicted                 0.8277        0.793  0.612               0.9129
cvpred                    0.8102        0.796  0.588               0.8355
LTR                       0.8340        0.996  0.732               0.9000
CV residual               0.0238        0.200  0.144               0.0645
            United Kingdom Vanuatu Yemen, Rep.
Predicted           1.0207  0.8060      0.7265
cvpred              1.0133  0.7901      0.7056
LTR                 0.9900  0.8260      0.6390
CV residual        -0.0233  0.0359     -0.0666

Sum of squares = 0.28    Mean square = 0.01    n = 24 

Overall (Sum over all 24 folds) 
   ms 
0.009 
Analysis of Variance Table

Response: LTR
          Df Sum Sq Mean Sq F value  Pr(>F)
GDP        1  0.932   0.932  118.89 < 2e-16
UNEMP      1  0.006   0.006    0.71  0.4002
URBGR      1  0.158   0.158   20.19 2.1e-05
MOBILE     1  0.176   0.176   22.45 8.2e-06
INTERNET   1  0.003   0.003    0.34  0.5624
LEXP       1  0.077   0.077    9.79  0.0024
Residuals 88  0.689   0.008                
Warning:

As there is >1 explanatory variable, cross-validation predicted values for
a fold are not a linear function of corresponding overall predicted
values.  Lines that are shown for the different folds are approximate

fold 1 
Observations in test set: 23 
            Antigua and Barbuda Armenia Botswana China Costa Rica
Predicted                 1.009  0.9782   0.8144 0.836     0.8976
cvpred                    1.009  0.9822   0.7592 0.841     0.9066
LTR                       0.990  0.9960   0.8450 0.943     0.9620
CV residual              -0.019  0.0138   0.0858 0.102     0.0554
            Equatorial Guinea Finland  France Georgia  Greece Honduras
Predicted               0.786  1.0368 0.98271  0.9148  1.0202   0.8890
cvpred                  0.738  1.0366 0.98893  0.9215  1.0204   0.8895
LTR                     0.939  0.9990 0.99000  0.9970  0.9720   0.8480
CV residual             0.201 -0.0376 0.00107  0.0755 -0.0484  -0.0415
            Hungary   India    Iraq Jamaica  Jordan Kazakhstan Latvia
Predicted    0.9632  0.7702  0.8682  0.9513 0.91584     0.9165 0.9706
cvpred       0.9608  0.7612  0.8592  0.9473 0.91757     0.8976 0.9713
LTR          0.9900  0.7400  0.7820  0.8660 0.92600     0.9970 0.9980
CV residual  0.0292 -0.0212 -0.0772 -0.0813 0.00843     0.0994 0.0267
            Macedonia, FYR   Nepal Singapore    Sudan Tajikistan
Predicted           0.9883  0.6726    1.0177  0.72559      0.791
cvpred              1.0029  0.6774    1.0173  0.71724      0.789
LTR                 0.9730  0.6030    0.9590  0.71100      0.997
CV residual        -0.0299 -0.0744   -0.0583 -0.00624      0.208

Sum of squares = 0.15    Mean square = 0.01    n = 23 

fold 2 
Observations in test set: 24 
             Angola Bangladesh  Brazil Brunei Darussalam   Canada   Chad
Predicted    0.7110      0.741  0.9411            0.9629  0.96157  0.588
cvpred       0.7488      0.751  0.9556            0.9862  0.99221  0.622
LTR          0.7010      0.568  0.9040            0.9520  0.99000  0.345
CV residual -0.0478     -0.183 -0.0516           -0.0342 -0.00221 -0.277
             Cyprus   Ghana Guatemala   Italy Moldova Papua New Guinea
Predicted    0.9692  0.7515     0.882  1.0550   0.837            0.673
cvpred       0.9987  0.7507     0.874  1.0683   0.820            0.722
LTR          0.9830  0.6730     0.752  0.9890   0.985            0.606
CV residual -0.0157 -0.0777    -0.122 -0.0793   0.165           -0.116
            Poland Portugal Puerto Rico Romania Slovenia   Spain
Predicted    0.980   0.9981       0.992  0.9497  0.98437  1.0433
cvpred       0.976   1.0139       1.037  0.9544  0.99512  1.0604
LTR          0.995   0.9520       0.904  0.9770  0.99700  0.9770
CV residual  0.019  -0.0619      -0.133  0.0226  0.00188 -0.0834
            Switzerland Tanzania Trinidad and Tobago United States
Predicted        1.0256   0.6679               0.931         0.977
cvpred           1.0414   0.6612               0.929         1.004
LTR              0.9900   0.7320               0.988         0.990
CV residual     -0.0514   0.0708               0.059        -0.014
            Uzbekistan Vietnam
Predicted        0.787  0.8795
cvpred           0.779  0.8395
LTR              0.994  0.9320
CV residual      0.215  0.0925

Sum of squares = 0.28    Mean square = 0.01    n = 24 

fold 3 
Observations in test set: 24 
            Bahrain Bosnia and Herzegovina Colombia Dominican Republic
Predicted     0.919                 0.9482   0.9148            0.89786
cvpred        0.941                 0.9461   0.9198            0.90194
LTR           0.919                 0.9790   0.9340            0.89500
CV residual  -0.022                 0.0329   0.0142           -0.00694
            Egypt, Arab Rep.  Estonia   Gabon Germany   Japan Lithuania
Predicted              0.862  0.99018  0.8862  1.0207 0.99525    1.0178
cvpred                 0.872  1.00283  0.9009  1.0226 0.98305    1.0337
LTR                    0.720  0.99800  0.8840  0.9900 0.99000    0.9970
CV residual           -0.152 -0.00483 -0.0169 -0.0326 0.00695   -0.0367
            Malaysia Montenegro Mozambique Namibia Nigeria  Panama Samoa
Predicted    0.90740     1.0296     0.5909  0.9354   0.694  0.9843 0.816
cvpred       0.92966     1.0568     0.5951  0.9425   0.719  1.0189 0.745
LTR          0.93100     0.9840     0.5610  0.8880   0.613  0.9410 0.988
CV residual  0.00134    -0.0728    -0.0341 -0.0545  -0.106 -0.0779 0.243
            Saudi Arabia Suriname Sweden Timor-Leste Ukraine  Uruguay
Predicted          1.013   0.9624  1.012       0.697  0.9201  0.98160
cvpred             1.040   0.9924  1.013       0.690  0.9346  0.99054
LTR                0.866   0.9470  0.990       0.583  0.9970  0.98100
CV residual       -0.174  -0.0454 -0.023      -0.107  0.0624 -0.00954
            Zambia
Predicted    0.670
cvpred       0.675
LTR          0.712
CV residual  0.037

Sum of squares = 0.16    Mean square = 0.01    n = 24 

fold 4 
Observations in test set: 24 
            Argentina   Aruba Congo, Dem. Rep. Croatia Ecuador El Salvador
Predicted       0.952  0.9794           0.5975 0.98020  0.9027      0.9197
cvpred          0.952  0.9845           0.5682 0.98371  0.8879      0.9171
LTR             0.978  0.9680           0.6680 0.98800  0.9190      0.8450
CV residual     0.026 -0.0165           0.0998 0.00429  0.0311     -0.0721
            Kenya   Mali Mexico Mongolia Netherlands Paraguay Qatar
Predicted   0.789  0.642 0.9131    0.822    0.992957   0.8658 0.867
cvpred      0.755  0.627 0.9032    0.812    0.989663   0.8529 0.770
LTR         0.874  0.311 0.9310    0.974    0.990000   0.9390 0.963
CV residual 0.119 -0.316 0.0278    0.162    0.000337   0.0861 0.193
            Russian Federation  Serbia South Africa Sri Lanka
Predicted               0.9632 0.97483       0.8526    0.8820
cvpred                  0.9724 0.97615       0.8466    0.8837
LTR                     0.9960 0.97900       0.9300    0.9120
CV residual             0.0236 0.00285       0.0834    0.0283
            Syrian Arab Republic Turkmenistan Uganda United Arab Emirates
Predicted                 0.8329        0.804  0.602               0.9115
cvpred                    0.8126        0.804  0.581               0.8292
LTR                       0.8340        0.996  0.732               0.9000
CV residual               0.0214        0.192  0.151               0.0708
            United Kingdom Vanuatu Yemen, Rep.
Predicted           1.0115  0.8154      0.7263
cvpred              1.0082  0.7954      0.7042
LTR                 0.9900  0.8260      0.6390
CV residual        -0.0182  0.0306     -0.0652

Sum of squares = 0.28    Mean square = 0.01    n = 24 

Overall (Sum over all 24 folds) 
     ms 
0.00922 

par(mfrow=c(1,1))

plot of chunk unnamed-chunk-1





# Compare the mean squared errors for prediction

seed <- round(runif(1, min=0, max=100))

ms.g <- CVlm(df=ltrdata10, 

             form.lm=g.step, 

             m=4, 

             seed=seed,

             printit=T, 

             plotit=F)
Analysis of Variance Table

Response: LTR
          Df Sum Sq Mean Sq F value  Pr(>F)
GDP        1  0.932   0.932  119.54 < 2e-16
UNEMP      1  0.006   0.006    0.72  0.3989
URBGR      1  0.158   0.158   20.30 2.0e-05
MOBILE     1  0.176   0.176   22.57 7.7e-06
LEXP       1  0.075   0.075    9.66  0.0025
Residuals 89  0.694   0.008                


fold 1 
Observations in test set: 23 
            Antigua and Barbuda   Aruba Bosnia and Herzegovina
Predicted                1.0237  0.9823                 0.9535
cvpred                   1.0235  0.9948                 0.9307
LTR                      0.9900  0.9680                 0.9790
CV residual             -0.0335 -0.0268                 0.0483
            Congo, Dem. Rep. Finland  France Georgia Honduras   India
Predicted              0.606  1.0460  0.9882  0.9128   0.8821  0.7678
cvpred                 0.552  1.0538  0.9962  0.9048   0.8849  0.7812
LTR                    0.668  0.9990  0.9900  0.9970   0.8480  0.7400
CV residual            0.116 -0.0548 -0.0062  0.0922  -0.0369 -0.0412
            Jamaica Jordan Kazakhstan Kenya Latvia Lithuania
Predicted    0.9469 0.9113     0.9134 0.792 0.9812    1.0253
cvpred       0.9469 0.9069     0.9253 0.745 0.9767    1.0208
LTR          0.8660 0.9260     0.9970 0.874 0.9980    0.9970
CV residual -0.0809 0.0191     0.0717 0.129 0.0213   -0.0238
            Macedonia, FYR   Nepal Puerto Rico Sri Lanka Suriname
Predicted            0.993  0.6750      0.9833    0.8743   0.9584
cvpred               0.963  0.6903      0.9853    0.8848   0.9624
LTR                  0.973  0.6030      0.9040    0.9120   0.9470
CV residual          0.010 -0.0873     -0.0813    0.0272  -0.0154
            Timor-Leste United Kingdom Yemen, Rep.
Predicted         0.695         1.0207      0.7265
cvpred            0.705         1.0295      0.7225
LTR               0.583         0.9900      0.6390
CV residual      -0.122        -0.0395     -0.0835

Sum of squares = 0.1    Mean square = 0    n = 23 

fold 2 
Observations in test set: 24 
            Armenia Brunei Darussalam   Chad Dominican Republic Ecuador
Predicted    0.9737             0.958  0.594            0.89483  0.8987
cvpred       0.9644             0.964  0.649            0.89802  0.8927
LTR          0.9960             0.952  0.345            0.89500  0.9190
CV residual  0.0316            -0.012 -0.304           -0.00302  0.0263
            Egypt, Arab Rep. El Salvador  Estonia    Gabon   Ghana  Greece
Predicted              0.865      0.9125  1.00116  0.87207  0.7515  1.0101
cvpred                 0.868      0.9079  1.00276  0.89368  0.7687  1.0111
LTR                    0.720      0.8450  0.99800  0.88400  0.6730  0.9720
CV residual           -0.148     -0.0629 -0.00476 -0.00968 -0.0957 -0.0391
               Iraq   Japan Mexico Moldova Mozambique Namibia Nigeria
Predicted    0.8532  0.9990 0.9056   0.844     0.6020  0.9229   0.705
cvpred       0.8663  1.0026 0.9102   0.847     0.6489  0.9416   0.744
LTR          0.7820  0.9900 0.9310   0.985     0.5610  0.8880   0.613
CV residual -0.0843 -0.0126 0.0208   0.138    -0.0879 -0.0536  -0.131
            Panama Papua New Guinea Singapore Uruguay Uzbekistan    Zambia
Predicted    0.982            0.669    1.0185 0.98017      0.790  0.673672
cvpred       0.963            0.709    1.0141 0.97669      0.795  0.712897
LTR          0.941            0.606    0.9590 0.98100      0.994  0.712000
CV residual -0.022           -0.103   -0.0551 0.00431      0.199 -0.000897

Sum of squares = 0.24    Mean square = 0.01    n = 24 

fold 3 
Observations in test set: 24 
            Argentina Bangladesh Botswana  Brazil Costa Rica Hungary
Predicted     0.95283      0.739  0.80965  0.9375     0.8920  0.9714
cvpred        0.96849      0.732  0.85223  0.9392     0.8765  0.9767
LTR           0.97800      0.568  0.84500  0.9040     0.9620  0.9900
CV residual   0.00951     -0.164 -0.00723 -0.0352     0.0855  0.0133
              Italy Malaysia   Mali Montenegro  Poland Portugal
Predicted    1.0478  0.91402  0.647     1.0265 0.98637   0.9946
cvpred       1.0534  0.93319  0.668     1.0474 0.98848   0.9928
LTR          0.9890  0.93100  0.311     0.9840 0.99500   0.9520
CV residual -0.0644 -0.00219 -0.357    -0.0634 0.00652  -0.0408
            Russian Federation Samoa Saudi Arabia Slovenia   Spain
Predicted              0.96452 0.803        1.007   0.9894  1.0417
cvpred                 0.99143 0.740        1.035   0.9815  1.0289
LTR                    0.99600 0.988        0.866   0.9970  0.9770
CV residual            0.00457 0.248       -0.169   0.0155 -0.0519
               Sudan Sweden Switzerland Syrian Arab Republic Tanzania
Predicted    0.72881  1.021       1.030               0.8277   0.6756
cvpred       0.71989  1.016       1.027               0.8186   0.6871
LTR          0.71100  0.990       0.990               0.8340   0.7320
CV residual -0.00889 -0.026      -0.037               0.0154   0.0449
            Uganda United Arab Emirates
Predicted    0.612               0.9129
cvpred       0.626               0.9566
LTR          0.732               0.9000
CV residual  0.106              -0.0566

Sum of squares = 0.28    Mean square = 0.01    n = 24 

fold 4 
Observations in test set: 24 
            Angola Bahrain Canada China Colombia Croatia Cyprus
Predicted   0.7081  0.9195 0.9666 0.835   0.9131  0.9826 0.9643
cvpred      0.6514  0.8795 0.9445 0.815   0.9007  0.9753 0.9423
LTR         0.7010  0.9190 0.9900 0.943   0.9340  0.9880 0.9830
CV residual 0.0496  0.0395 0.0455 0.128   0.0333  0.0127 0.0407
            Equatorial Guinea Germany Guatemala Mongolia Netherlands
Predicted               0.772  1.0281    0.8735    0.817      1.0038
cvpred                  0.701  1.0107    0.8487    0.786      0.9782
LTR                     0.939  0.9900    0.7520    0.974      0.9900
CV residual             0.238 -0.0207   -0.0967    0.188      0.0118
            Paraguay Qatar Romania   Serbia South Africa Tajikistan
Predicted     0.8612 0.871  0.9492  0.97553        0.852      0.794
cvpred        0.8427 0.791  0.9365  0.98334        0.809      0.778
LTR           0.9390 0.963  0.9770  0.97900        0.930      0.997
CV residual   0.0963 0.172  0.0405 -0.00434        0.121      0.219
            Trinidad and Tobago Turkmenistan Ukraine United States Vanuatu
Predicted                0.9322        0.793  0.9184        0.9799  0.8060
cvpred                   0.8909        0.750  0.9103        0.9551  0.7761
LTR                      0.9880        0.996  0.9970        0.9900  0.8260
CV residual              0.0971        0.246  0.0867        0.0349  0.0499
            Vietnam
Predicted    0.8844
cvpred       0.8822
LTR          0.9320
CV residual  0.0498

Sum of squares = 0.31    Mean square = 0.01    n = 24 

Overall (Sum over all 24 folds) 
     ms 
0.00989 

ms.g.step <- CVlm(df=ltrdata10, form.lm=g, m=4, seed=seed, plotit=F, printit=T) 
Analysis of Variance Table

Response: LTR
          Df Sum Sq Mean Sq F value  Pr(>F)
GDP        1  0.932   0.932  118.89 < 2e-16
UNEMP      1  0.006   0.006    0.71  0.4002
URBGR      1  0.158   0.158   20.19 2.1e-05
MOBILE     1  0.176   0.176   22.45 8.2e-06
INTERNET   1  0.003   0.003    0.34  0.5624
LEXP       1  0.077   0.077    9.79  0.0024
Residuals 88  0.689   0.008                


fold 1 
Observations in test set: 23 
            Antigua and Barbuda  Aruba Bosnia and Herzegovina
Predicted               1.00851  0.979                 0.9482
cvpred                  0.99366  0.989                 0.9121
LTR                     0.99000  0.968                 0.9790
CV residual            -0.00366 -0.021                 0.0669
            Congo, Dem. Rep. Finland  France Georgia Honduras  India
Predicted              0.598  1.0368 0.98271  0.9148   0.8890  0.770
cvpred                 0.522  1.0352 0.98378  0.9044   0.8986  0.788
LTR                    0.668  0.9990 0.99000  0.9970   0.8480  0.740
CV residual            0.146 -0.0362 0.00622  0.0926  -0.0506 -0.048
            Jamaica Jordan Kazakhstan Kenya Latvia Lithuania
Predicted    0.9513 0.9158      0.916 0.789  0.971    1.0178
cvpred       0.9527 0.9129      0.932 0.728  0.952    1.0023
LTR          0.8660 0.9260      0.997 0.874  0.998    0.9970
CV residual -0.0867 0.0131      0.065 0.146  0.046   -0.0053
            Macedonia, FYR  Nepal Puerto Rico Sri Lanka Suriname
Predicted           0.9883  0.673      0.9922    0.8820   0.9624
cvpred              0.9429  0.688      0.9967    0.8993   0.9697
LTR                 0.9730  0.603      0.9040    0.9120   0.9470
CV residual         0.0301 -0.085     -0.0927    0.0127  -0.0227
            Timor-Leste United Kingdom Yemen, Rep.
Predicted         0.697          1.012      0.7263
cvpred            0.713          1.011      0.7206
LTR               0.583          0.990      0.6390
CV residual      -0.130         -0.021     -0.0816

Sum of squares = 0.12    Mean square = 0.01    n = 23 

fold 2 
Observations in test set: 24 
            Armenia Brunei Darussalam   Chad Dominican Republic Ecuador
Predicted    0.9782            0.9629  0.588             0.8979  0.9027
cvpred       0.9748            0.9716  0.633             0.9043  0.9001
LTR          0.9960            0.9520  0.345             0.8950  0.9190
CV residual  0.0212           -0.0196 -0.288            -0.0093  0.0189
            Egypt, Arab Rep. El Salvador Estonia   Gabon   Ghana  Greece
Predicted              0.862      0.9197  0.9902  0.8862  0.7515  1.0202
cvpred                 0.864      0.9197  0.9879  0.9167  0.7667  1.0298
LTR                    0.720      0.8450  0.9980  0.8840  0.6730  0.9720
CV residual           -0.144     -0.0747  0.0101 -0.0327 -0.0937 -0.0578
              Iraq    Japan  Mexico Moldova Mozambique Namibia Nigeria
Predicted    0.868  0.99525 0.91314   0.837     0.5909  0.9354   0.694
cvpred       0.891  0.99782 0.92221   0.834     0.6258  0.9702   0.725
LTR          0.782  0.99000 0.93100   0.985     0.5610  0.8880   0.613
CV residual -0.109 -0.00782 0.00879   0.151    -0.0648 -0.0822  -0.112
             Panama Papua New Guinea Singapore Uruguay Uzbekistan  Zambia
Predicted    0.9843            0.673    1.0177 0.98160      0.787 0.66966
cvpred       0.9699            0.708    1.0147 0.97993      0.787 0.70329
LTR          0.9410            0.606    0.9590 0.98100      0.994 0.71200
CV residual -0.0289           -0.102   -0.0557 0.00107      0.207 0.00871

Sum of squares = 0.24    Mean square = 0.01    n = 24 

fold 3 
Observations in test set: 24 
            Argentina Bangladesh Botswana  Brazil Costa Rica Hungary
Predicted      0.9519      0.741  0.81443  0.9411     0.8976   0.963
cvpred         0.9674      0.733  0.85366  0.9418     0.8812   0.971
LTR            0.9780      0.568  0.84500  0.9040     0.9620   0.990
CV residual    0.0106     -0.165 -0.00866 -0.0378     0.0808   0.019
              Italy Malaysia   Mali Montenegro Poland Portugal
Predicted    1.0550   0.9074  0.642     1.0296 0.9801   0.9981
cvpred       1.0588   0.9277  0.663     1.0497 0.9843   0.9957
LTR          0.9890   0.9310  0.311     0.9840 0.9950   0.9520
CV residual -0.0698   0.0033 -0.352    -0.0657 0.0107  -0.0437
            Russian Federation Samoa Saudi Arabia Slovenia   Spain
Predicted              0.96324 0.816        1.013   0.9844  1.0433
cvpred                 0.98966 0.752        1.039   0.9785  1.0313
LTR                    0.99600 0.988        0.866   0.9970  0.9770
CV residual            0.00634 0.236       -0.173   0.0185 -0.0543
               Sudan Sweden Switzerland Syrian Arab Republic Tanzania
Predicted    0.72559   1.01      1.0256               0.8329   0.6679
cvpred       0.71765   1.01      1.0245               0.8227   0.6807
LTR          0.71100   0.99      0.9900               0.8340   0.7320
CV residual -0.00665  -0.02     -0.0345               0.0113   0.0513
            Uganda United Arab Emirates
Predicted    0.602               0.9115
cvpred       0.617               0.9537
LTR          0.732               0.9000
CV residual  0.115              -0.0537

Sum of squares = 0.28    Mean square = 0.01    n = 24 

fold 4 
Observations in test set: 24 
            Angola Bahrain Canada China Colombia Croatia Cyprus
Predicted   0.7110  0.9193 0.9616 0.836    0.915  0.9802  0.969
cvpred      0.6483  0.8798 0.9472 0.815    0.900  0.9765  0.940
LTR         0.7010  0.9190 0.9900 0.943    0.934  0.9880  0.983
CV residual 0.0527  0.0392 0.0428 0.128    0.034  0.0115  0.043
            Equatorial Guinea Germany Guatemala Mongolia Netherlands
Predicted               0.786  1.0207    0.8818    0.822     0.99296
cvpred                  0.692  1.0143    0.8446    0.783     0.98359
LTR                     0.939  0.9900    0.7520    0.974     0.99000
CV residual             0.247 -0.0243   -0.0926    0.191     0.00641
            Paraguay Qatar Romania  Serbia South Africa Tajikistan
Predicted     0.8658 0.867  0.9497  0.9748        0.853      0.791
cvpred        0.8405 0.794  0.9359  0.9839        0.807      0.779
LTR           0.9390 0.963  0.9770  0.9790        0.930      0.997
CV residual   0.0985 0.169  0.0411 -0.0049        0.123      0.218
            Trinidad and Tobago Turkmenistan Ukraine United States Vanuatu
Predicted                 0.931        0.804  0.9201        0.9771  0.8154
cvpred                    0.891        0.743  0.9091        0.9564  0.7714
LTR                       0.988        0.996  0.9970        0.9900  0.8260
CV residual               0.097        0.253  0.0879        0.0336  0.0546
            Vietnam
Predicted    0.8795
cvpred       0.8853
LTR          0.9320
CV residual  0.0467

Sum of squares = 0.32    Mean square = 0.01    n = 24 

Overall (Sum over all 24 folds) 
    ms 
0.0101 

attr(ms.g, "ms"); attr(ms.g.step, "ms")
[1] 0.0101