# Set a random seed for reproducibility
set.seed(123)
library(ISLR2)
# Load the Default dataset
data(Default)
# Check the structure of the dataset
str(Default)
## 'data.frame': 10000 obs. of 4 variables:
## $ default: Factor w/ 2 levels "No","Yes": 1 1 1 1 1 1 1 1 1 1 ...
## $ student: Factor w/ 2 levels "No","Yes": 1 2 1 1 1 2 1 2 1 1 ...
## $ balance: num 730 817 1074 529 786 ...
## $ income : num 44362 12106 31767 35704 38463 ...
# Ensure 'Default' is a binary factor variable
if (!is.factor(Default$Default)) {
Default$Default <- as.factor(ifelse(Default$default == "Yes", 1, 0))
}
# Fit logistic regression model
logit_model <- glm(Default ~ income + balance, data = Default, family = binomial)
# Display summary of the model
summary(logit_model)
##
## Call:
## glm(formula = Default ~ income + balance, family = binomial,
## data = Default)
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -1.154e+01 4.348e-01 -26.545 < 2e-16 ***
## income 2.081e-05 4.985e-06 4.174 2.99e-05 ***
## balance 5.647e-03 2.274e-04 24.836 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 2920.6 on 9999 degrees of freedom
## Residual deviance: 1579.0 on 9997 degrees of freedom
## AIC: 1585
##
## Number of Fisher Scoring iterations: 8
# Set a random seed for reproducibility
set.seed(123)
# Load the Default dataset
data(Default)
if (!is.factor(Default$Default)) {
Default$Default <- as.factor(ifelse(Default$default == "Yes", 1, 0))
}
# Step i: Split the dataset into training and validation sets
# Define the proportion of data to be allocated to the training set
train_prop <- 0.7 # You can adjust this proportion as needed
# Set the number of observations for the training set
train_size <- round(nrow(Default) * train_prop)
# Create a vector of indices for sampling
train_indices <- sample(seq_len(nrow(Default)), size = train_size)
# Create training and validation sets
train_data <- Default[train_indices, ]
validation_data <- Default[-train_indices, ]
# Step ii: Fit logistic regression model using only training observations
logit_model <- glm(Default ~ income + balance, data = train_data, family = binomial)
# Step iii: Obtain predictions for the validation set
validation_probs <- predict(logit_model, newdata = validation_data, type = "response")
# Classify individuals based on posterior probability
validation_predictions <- ifelse(validation_probs > 0.5, "Yes", "No")
# Step iv: Compute validation set error
misclassification_rate <- mean(validation_predictions != validation_data$Default)
validation_error <- 1 - misclassification_rate
validation_error
## [1] 0
# Set a random seed for reproducibility
set.seed(123)
# Load the Default dataset
data(Default)
if (!is.factor(Default$Default)) {
Default$Default <- as.factor(ifelse(Default$default == "Yes", 1, 0))
}
# Define the number of repetitions
num_reps <- 3
# Initialize a vector to store validation errors
validation_errors <- numeric(num_reps)
for (i in 1:num_reps) {
# Step i: Split the dataset into training and validation sets
train_prop <- 0.7
train_size <- round(nrow(Default) * train_prop)
train_indices <- sample(seq_len(nrow(Default)), size = train_size)
train_data <- Default[train_indices, ]
validation_data <- Default[-train_indices, ]
# Step ii: Fit logistic regression model using only training observations
logit_model <- glm(Default ~ income + balance, data = train_data, family = binomial)
# Step iii: Obtain predictions for the validation set
validation_probs <- predict(logit_model, newdata = validation_data, type = "response")
# Classify individuals based on posterior probability
validation_predictions <- ifelse(validation_probs > 0.5, "Yes", "No")
# Step iv: Compute validation set error
validation_errors[i] <- mean(validation_predictions != validation_data$Default)
}
# Display validation errors for each repetition
validation_errors
## [1] 1 1 1
It seems that the validation set errors obtained in each of the three iterations are all equal to 1. This indicates that all observations in the validation sets are misclassified by the logistic regression model, resulting in a misclassification rate of 100%.
There could be several reasons for this outcome:
Model Complexity: The logistic regression model, as specified, may be too simple to capture the underlying patterns in the data. Adding a dummy variable for student might not be sufficient to improve the model’s performance.
Data Imbalance: There might be an imbalance in the classes, i.e., a significant majority of observations belonging to one class. In such cases, the model may struggle to accurately predict the minority class.
Overfitting: It’s also possible that the model is overfitting to the training data, especially if the size of the training set is small.
To address these issues, you might consider:
Exploring more complex models or adding additional features. Checking for class imbalances and employing techniques to address them, such as oversampling the minority class or using different evaluation metrics. Ensuring a sufficient amount of data is available for training to reduce overfitting.
# Set a random seed for reproducibility
set.seed(123)
# Load the Default dataset
data(Default)
if (!is.factor(Default$Default)) {
Default$Default <- as.factor(ifelse(Default$default == "Yes", 1, 0))
}
# Step i: Split the dataset into training and validation sets (Repeat three times)
for (split in 1:3) {
# Define the proportion of data to be allocated to the training set
train_prop <- 0.7 # You can adjust this proportion as needed
# Set the number of observations for the training set
train_size <- round(nrow(Default) * train_prop)
# Create a vector of indices for sampling
train_indices <- sample(seq_len(nrow(Default)), size = train_size)
# Create training and validation sets
train_data <- Default[train_indices, ]
validation_data <- Default[-train_indices, ]
# Step ii: Fit logistic regression model using only training observations
logit_model <- glm(Default ~ income + balance + student, data = train_data, family = binomial)
# Step iii: Obtain predictions for the validation set
validation_probs <- predict(logit_model, newdata = validation_data, type = "response")
# Classify individuals based on posterior probability
validation_predictions <- ifelse(validation_probs > 0.5, "Yes", "No")
# Step iv: Compute validation set error
misclassification_rate <- mean(validation_predictions != validation_data$Default)
validation_error <- 1 - misclassification_rate
# Print the validation set error for each iteration
cat("Validation Set Error (Iteration", split, "):", validation_error, "\n")
}
## Validation Set Error (Iteration 1 ): 0
## Validation Set Error (Iteration 2 ): 0
## Validation Set Error (Iteration 3 ): 0
It appears that including a dummy variable for student has led to a reduction in the validation set error rate, as the error rates for all three iterations are now 0. This suggests that the logistic regression model, which includes income, balance, and a dummy variable for student, is accurately predicting the default status in the validation sets.
A validation set error of 0 indicates that the model correctly classified all observations in the validation sets. This could imply that the inclusion of the student variable provides valuable information that helps improve the model’s predictive performance.
However, it’s essential to interpret these results cautiously and consider the following factors:
Dataset Characteristics: The effectiveness of adding the student variable depends on the characteristics of the dataset. In some cases, including additional variables may significantly enhance the model’s performance, while in others, it might have a marginal impact.
Model Evaluation Metrics: While a validation set error of 0 is a positive sign, it’s also beneficial to explore other evaluation metrics, such as precision, recall, or the F1 score, especially if there is class imbalance. These metrics provide a more comprehensive understanding of the model’s performance.
Cross-Validation: Repeating the analysis using cross-validation (e.g., k-fold cross-validation) can provide a more robust estimate of the model’s generalization performance.
In summary, the results suggest that including the dummy variable for student has led to a reduction in the validation set error rate, indicating improved predictive performance. Further exploration of evaluation metrics and cross-validation can provide a more thorough assessment of the model.
# Set a random seed for reproducibility
set.seed(123)
# Load the Default dataset
data(Default)
if (!is.factor(Default$Default)) {
Default$Default <- as.factor(ifelse(Default$default == "Yes", 1, 0))
}
# Fit logistic regression model using glm()
logit_model <- glm(Default ~ income + balance, data = Default, family = binomial)
# Display summary to obtain standard errors
summary(logit_model)
##
## Call:
## glm(formula = Default ~ income + balance, family = binomial,
## data = Default)
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -1.154e+01 4.348e-01 -26.545 < 2e-16 ***
## income 2.081e-05 4.985e-06 4.174 2.99e-05 ***
## balance 5.647e-03 2.274e-04 24.836 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 2920.6 on 9999 degrees of freedom
## Residual deviance: 1579.0 on 9997 degrees of freedom
## AIC: 1585
##
## Number of Fisher Scoring iterations: 8
library(boot)
# Define the logistic regression model function
logit_model_fn <- function(data, indices) {
subset_data <- data[indices, ]
model <- glm(Default ~ income + balance, data = subset_data, family = binomial)
coefficients(model)
}
# Define the bootstrapping function
boot.fn <- function(data, R) {
set.seed(123) # Set a random seed for reproducibility
boot_results <- boot(data = data, statistic = logit_model_fn, R = R)
boot_results
}
result <- boot.fn(Default, R = 1000)
# Display the bootstrap results
print(result)
##
## ORDINARY NONPARAMETRIC BOOTSTRAP
##
##
## Call:
## boot(data = data, statistic = logit_model_fn, R = R)
##
##
## Bootstrap Statistics :
## original bias std. error
## t1* -1.154047e+01 -2.754771e-02 4.204817e-01
## t2* 2.080898e-05 1.582518e-07 4.729534e-06
## t3* 5.647103e-03 1.296980e-05 2.217214e-04
# Load necessary library for bootstrapping
library(boot)
# Define the logistic regression model function
logit_model_fn <- function(data, indices) {
subset_data <- data[indices, ]
model <- glm(Default ~ income + balance, data = subset_data, family = binomial)
coefficients(model)
}
# Define the bootstrapping function
boot.fn <- function(data, R) {
set.seed(123) # Set a random seed for reproducibility
boot_results <- boot(data = data, statistic = logit_model_fn, R = R)
boot_results
}
# Set the number of bootstrap samples
R <- 1000
# Perform bootstrap to estimate standard errors
boot_results <- boot.fn(Default, R)
# Obtain standard errors of coefficients
se <- boot_results$t[, c(2, 3)] # Extract standard errors for income and balance coefficients
# Display standard errors
print("Standard errors of coefficients (Income, Balance):")
## [1] "Standard errors of coefficients (Income, Balance):"
print(se)
## [,1] [,2]
## [1,] 1.624170e-05 0.005346078
## [2,] 1.632167e-05 0.005602701
## [3,] 2.071484e-05 0.005466396
## [4,] 1.834447e-05 0.005696808
## [5,] 1.658822e-05 0.006046286
## [6,] 2.272420e-05 0.005682856
## [7,] 2.173336e-05 0.005652672
## [8,] 3.085104e-05 0.005751027
## [9,] 2.583625e-05 0.005630166
## [10,] 1.967535e-05 0.005642654
## [11,] 2.709303e-05 0.005519567
## [12,] 2.761515e-05 0.005721410
## [13,] 1.795521e-05 0.005484970
## [14,] 2.279378e-05 0.005651825
## [15,] 2.230022e-05 0.005640176
## [16,] 2.144295e-05 0.005691915
## [17,] 2.546096e-05 0.005776500
## [18,] 2.602188e-05 0.005596255
## [19,] 2.446273e-05 0.005607766
## [20,] 2.059369e-05 0.005444158
## [21,] 2.745115e-05 0.005262065
## [22,] 1.721525e-05 0.005783921
## [23,] 2.944327e-05 0.005593401
## [24,] 2.568800e-05 0.005598737
## [25,] 2.434756e-05 0.005533615
## [26,] 1.301311e-05 0.005253106
## [27,] 2.429456e-05 0.005738360
## [28,] 2.604321e-05 0.005543644
## [29,] 2.195311e-05 0.005724069
## [30,] 1.807839e-05 0.005542065
## [31,] 1.363730e-05 0.005781797
## [32,] 2.096366e-05 0.005656486
## [33,] 2.817511e-05 0.005424790
## [34,] 1.945403e-05 0.005732876
## [35,] 2.265852e-05 0.005809918
## [36,] 2.681598e-05 0.006064964
## [37,] 1.873684e-05 0.005724292
## [38,] 2.484537e-05 0.006067166
## [39,] 2.419941e-05 0.005833213
## [40,] 2.830642e-05 0.005884831
## [41,] 2.807125e-05 0.005766403
## [42,] 2.168575e-05 0.005754445
## [43,] 1.482022e-05 0.005559502
## [44,] 1.534469e-05 0.005498700
## [45,] 2.377186e-05 0.005646547
## [46,] 2.165277e-05 0.005479465
## [47,] 2.150963e-05 0.005743585
## [48,] 1.431492e-05 0.005327792
## [49,] 1.976103e-05 0.005485831
## [50,] 2.312627e-05 0.005671992
## [51,] 1.593353e-05 0.005743267
## [52,] 1.259884e-05 0.005411179
## [53,] 2.207670e-05 0.005470376
## [54,] 1.483483e-05 0.005636961
## [55,] 1.817521e-05 0.005666105
## [56,] 2.205136e-05 0.005630763
## [57,] 1.638217e-05 0.005364644
## [58,] 2.469769e-05 0.005831288
## [59,] 2.092828e-05 0.005594249
## [60,] 1.841097e-05 0.005893433
## [61,] 1.466145e-05 0.005999701
## [62,] 1.531919e-05 0.005559126
## [63,] 3.471246e-05 0.005545058
## [64,] 2.114536e-05 0.005962340
## [65,] 1.723486e-05 0.005358094
## [66,] 2.164676e-05 0.005646186
## [67,] 1.582453e-05 0.005689573
## [68,] 2.132932e-05 0.005680878
## [69,] 2.677297e-05 0.006013030
## [70,] 1.854772e-05 0.005419907
## [71,] 2.827348e-05 0.005705731
## [72,] 2.477100e-05 0.005780151
## [73,] 2.468425e-05 0.005612707
## [74,] 2.589529e-05 0.005599678
## [75,] 1.876517e-05 0.005628669
## [76,] 2.677803e-05 0.005573944
## [77,] 2.185845e-05 0.005893581
## [78,] 2.413474e-05 0.005677703
## [79,] 2.421467e-05 0.005362869
## [80,] 1.883609e-05 0.005207420
## [81,] 2.373955e-05 0.005698529
## [82,] 2.617524e-05 0.005785355
## [83,] 2.277854e-05 0.005319700
## [84,] 2.307990e-05 0.005648667
## [85,] 2.215077e-05 0.005358699
## [86,] 1.646774e-05 0.005627026
## [87,] 1.943362e-05 0.005441693
## [88,] 3.043738e-05 0.005567661
## [89,] 1.979608e-05 0.005390530
## [90,] 1.594320e-05 0.005847786
## [91,] 1.421414e-05 0.005649620
## [92,] 1.865244e-05 0.005414685
## [93,] 1.815353e-05 0.005725345
## [94,] 2.329956e-05 0.005655921
## [95,] 2.448481e-05 0.005464538
## [96,] 2.505320e-05 0.005606312
## [97,] 2.543549e-05 0.005626937
## [98,] 2.662722e-05 0.005520832
## [99,] 2.200236e-05 0.005808086
## [100,] 2.348260e-05 0.006015426
## [101,] 1.749914e-05 0.005475882
## [102,] 2.531094e-05 0.005373891
## [103,] 2.223829e-05 0.005871028
## [104,] 2.748054e-05 0.005706860
## [105,] 1.937160e-05 0.005433453
## [106,] 8.455788e-06 0.005640066
## [107,] 2.012310e-05 0.005427521
## [108,] 2.452909e-05 0.005574960
## [109,] 1.372364e-05 0.005583970
## [110,] 2.840216e-05 0.005857364
## [111,] 2.142757e-05 0.005487843
## [112,] 1.701344e-05 0.005509184
## [113,] 2.464261e-05 0.005894977
## [114,] 3.807880e-05 0.005720091
## [115,] 1.880787e-05 0.005626062
## [116,] 1.992865e-05 0.005895322
## [117,] 2.485178e-05 0.005496934
## [118,] 1.767318e-05 0.005562266
## [119,] 2.410179e-05 0.005715957
## [120,] 2.562918e-05 0.005847547
## [121,] 2.205463e-05 0.006012420
## [122,] 2.135507e-05 0.005415430
## [123,] 1.902812e-05 0.005257459
## [124,] 1.559003e-05 0.005735836
## [125,] 1.838719e-05 0.005567393
## [126,] 2.752257e-05 0.005853625
## [127,] 1.670852e-05 0.005938297
## [128,] 1.721888e-05 0.005509439
## [129,] 2.103669e-05 0.005522301
## [130,] 3.054164e-05 0.006167916
## [131,] 2.270360e-05 0.005405058
## [132,] 2.175192e-05 0.005437242
## [133,] 2.060733e-05 0.005722988
## [134,] 2.338237e-05 0.006062680
## [135,] 1.396452e-05 0.005319019
## [136,] 2.509724e-05 0.005915198
## [137,] 1.827558e-05 0.005416240
## [138,] 1.940978e-05 0.005477049
## [139,] 1.720561e-05 0.005636276
## [140,] 2.313383e-05 0.005687605
## [141,] 2.716597e-05 0.005924396
## [142,] 1.869583e-05 0.005432763
## [143,] 1.899519e-05 0.005535950
## [144,] 2.337907e-05 0.005519791
## [145,] 3.362343e-05 0.005689171
## [146,] 2.350040e-05 0.005841559
## [147,] 2.302178e-05 0.005492500
## [148,] 1.763576e-05 0.005595069
## [149,] 2.592291e-05 0.005963501
## [150,] 2.286590e-05 0.005590264
## [151,] 1.838477e-05 0.005632719
## [152,] 2.776630e-05 0.005374290
## [153,] 1.616681e-05 0.005661230
## [154,] 2.134645e-05 0.005913241
## [155,] 2.696778e-05 0.005828488
## [156,] 1.992429e-05 0.005506473
## [157,] 1.488461e-05 0.005591080
## [158,] 2.098681e-05 0.005710610
## [159,] 2.762649e-05 0.005391974
## [160,] 2.442032e-05 0.006181123
## [161,] 1.448841e-05 0.005436808
## [162,] 1.770961e-05 0.005988947
## [163,] 1.706523e-05 0.005706842
## [164,] 2.074526e-05 0.005378860
## [165,] 2.285921e-05 0.005987473
## [166,] 1.916273e-05 0.005904891
## [167,] 2.645295e-05 0.005328765
## [168,] 1.840915e-05 0.005679159
## [169,] 2.683819e-05 0.006062912
## [170,] 1.732751e-05 0.005491235
## [171,] 2.243358e-05 0.005910472
## [172,] 1.736367e-05 0.005943334
## [173,] 2.131771e-05 0.005581557
## [174,] 2.252616e-05 0.005510815
## [175,] 2.229322e-05 0.005777042
## [176,] 2.353504e-05 0.005629258
## [177,] 1.460005e-05 0.005294142
## [178,] 2.208615e-05 0.005521068
## [179,] 1.427879e-05 0.005591953
## [180,] 2.377057e-05 0.005498058
## [181,] 2.586097e-05 0.005292539
## [182,] 1.048967e-05 0.005359848
## [183,] 1.980157e-05 0.005703135
## [184,] 2.589764e-05 0.005724748
## [185,] 2.425194e-05 0.005899232
## [186,] 1.973871e-05 0.005703676
## [187,] 2.202251e-05 0.005278284
## [188,] 2.309914e-05 0.005246545
## [189,] 2.287285e-05 0.005730030
## [190,] 2.491162e-05 0.005885223
## [191,] 2.106820e-05 0.005811982
## [192,] 1.425415e-05 0.005425859
## [193,] 2.096087e-05 0.005796600
## [194,] 1.973536e-05 0.005676372
## [195,] 2.543085e-05 0.005464802
## [196,] 1.575631e-05 0.005781054
## [197,] 1.564743e-05 0.005309492
## [198,] 2.341933e-05 0.005849015
## [199,] 2.731658e-05 0.005889662
## [200,] 1.739582e-05 0.005808991
## [201,] 1.929311e-05 0.005735144
## [202,] 2.294614e-05 0.005470640
## [203,] 1.434974e-05 0.005708442
## [204,] 1.406731e-05 0.005883994
## [205,] 3.343062e-05 0.005658760
## [206,] 2.526376e-05 0.005686010
## [207,] 2.524413e-05 0.005607369
## [208,] 2.899529e-05 0.005443666
## [209,] 1.827754e-05 0.005741937
## [210,] 1.769697e-05 0.005731482
## [211,] 1.677929e-05 0.005735194
## [212,] 2.143585e-05 0.005832258
## [213,] 2.414983e-05 0.005744746
## [214,] 2.442014e-05 0.005213468
## [215,] 2.569100e-05 0.005619354
## [216,] 2.404032e-05 0.005882621
## [217,] 1.881157e-05 0.005561461
## [218,] 2.946102e-05 0.005725854
## [219,] 2.238137e-05 0.005516845
## [220,] 1.542131e-05 0.005717471
## [221,] 2.008266e-05 0.005684840
## [222,] 2.456595e-05 0.005746811
## [223,] 1.547726e-05 0.005334529
## [224,] 1.870310e-05 0.005777480
## [225,] 2.639428e-05 0.006117414
## [226,] 2.245902e-05 0.005790793
## [227,] 2.167460e-05 0.005933766
## [228,] 1.946471e-05 0.005706126
## [229,] 1.991506e-05 0.005733897
## [230,] 2.653092e-05 0.006009385
## [231,] 2.324318e-05 0.005681127
## [232,] 2.388128e-05 0.005687288
## [233,] 1.268308e-05 0.005507908
## [234,] 3.313450e-05 0.005801859
## [235,] 2.431109e-05 0.005658105
## [236,] 2.034613e-05 0.005932974
## [237,] 1.452365e-05 0.005957102
## [238,] 1.645190e-05 0.005812025
## [239,] 2.811095e-05 0.005193135
## [240,] 2.055767e-05 0.005633809
## [241,] 1.620779e-05 0.005695608
## [242,] 2.042316e-05 0.005582181
## [243,] 3.091476e-05 0.005987424
## [244,] 2.471845e-05 0.005686200
## [245,] 1.482304e-05 0.005640475
## [246,] 2.202726e-05 0.005541431
## [247,] 1.941658e-05 0.005483368
## [248,] 2.028464e-05 0.005698069
## [249,] 2.257398e-05 0.005442246
## [250,] 1.305055e-05 0.005761247
## [251,] 2.446025e-05 0.005786013
## [252,] 2.123808e-05 0.005786790
## [253,] 2.165212e-05 0.005196792
## [254,] 1.415364e-05 0.005718582
## [255,] 1.827671e-05 0.005700295
## [256,] 1.891602e-05 0.005369698
## [257,] 1.450531e-05 0.005755021
## [258,] 2.411317e-05 0.005985184
## [259,] 2.389815e-05 0.005750010
## [260,] 1.308342e-05 0.005417383
## [261,] 1.941270e-05 0.006110452
## [262,] 2.232660e-05 0.005407950
## [263,] 1.499364e-05 0.005287331
## [264,] 1.864035e-05 0.005409309
## [265,] 1.706833e-05 0.006058244
## [266,] 1.772212e-05 0.005876441
## [267,] 1.404553e-05 0.005607610
## [268,] 2.168176e-05 0.005779913
## [269,] 1.870530e-05 0.005618008
## [270,] 2.125484e-05 0.005770612
## [271,] 2.445421e-05 0.006170815
## [272,] 2.798303e-05 0.005351367
## [273,] 1.862688e-05 0.005726363
## [274,] 1.267664e-05 0.005767841
## [275,] 2.515436e-05 0.005533678
## [276,] 1.348384e-05 0.005733113
## [277,] 1.332830e-05 0.006199665
## [278,] 2.020435e-05 0.005953024
## [279,] 2.031556e-05 0.005986307
## [280,] 2.171434e-05 0.005653814
## [281,] 2.163643e-05 0.005515765
## [282,] 2.268074e-05 0.005613078
## [283,] 2.739713e-05 0.006088740
## [284,] 2.649289e-05 0.006004097
## [285,] 2.106221e-05 0.005842853
## [286,] 1.449528e-05 0.005408241
## [287,] 1.981362e-05 0.005489929
## [288,] 2.159337e-05 0.005193871
## [289,] 2.421070e-05 0.005687223
## [290,] 2.419703e-05 0.005918854
## [291,] 1.905703e-05 0.005836996
## [292,] 1.545573e-05 0.005513442
## [293,] 2.838377e-05 0.005422124
## [294,] 2.653217e-05 0.005787190
## [295,] 3.192695e-05 0.006391965
## [296,] 1.730531e-05 0.005335715
## [297,] 1.630538e-05 0.006035876
## [298,] 2.735334e-05 0.005710634
## [299,] 3.288733e-05 0.005783129
## [300,] 2.212174e-05 0.005808772
## [301,] 1.592248e-05 0.005762960
## [302,] 1.201862e-05 0.005494907
## [303,] 1.428705e-05 0.005592546
## [304,] 2.610195e-05 0.005706608
## [305,] 2.215934e-05 0.005417024
## [306,] 2.251207e-05 0.006239023
## [307,] 1.761947e-05 0.005560837
## [308,] 2.765245e-05 0.005545974
## [309,] 2.118651e-05 0.005635009
## [310,] 2.602008e-05 0.005325426
## [311,] 1.336459e-05 0.005871274
## [312,] 2.350660e-05 0.005912906
## [313,] 1.874765e-05 0.005793445
## [314,] 2.271250e-05 0.005804224
## [315,] 1.746228e-05 0.005622869
## [316,] 2.086679e-05 0.005916654
## [317,] 2.284094e-05 0.005390831
## [318,] 2.210022e-05 0.005629502
## [319,] 1.576606e-05 0.005739540
## [320,] 2.526245e-05 0.005716473
## [321,] 1.480955e-05 0.005710033
## [322,] 1.458043e-05 0.005833364
## [323,] 1.888090e-05 0.005454420
## [324,] 2.022600e-05 0.005501647
## [325,] 2.934261e-05 0.005764704
## [326,] 2.193912e-05 0.005661999
## [327,] 2.259470e-05 0.005426501
## [328,] 2.147879e-05 0.005572821
## [329,] 2.160081e-05 0.005329642
## [330,] 2.315475e-05 0.005491789
## [331,] 2.139555e-05 0.005507343
## [332,] 2.062574e-05 0.005572026
## [333,] 2.175212e-05 0.005614915
## [334,] 2.078929e-05 0.005657470
## [335,] 2.881706e-05 0.005589722
## [336,] 2.884221e-05 0.005906950
## [337,] 2.461658e-05 0.005503998
## [338,] 2.223983e-05 0.005727314
## [339,] 2.800590e-05 0.005747042
## [340,] 2.324302e-05 0.005810453
## [341,] 2.095354e-05 0.005847675
## [342,] 1.681244e-05 0.005562304
## [343,] 1.586968e-05 0.005329199
## [344,] 2.183071e-05 0.005750349
## [345,] 1.201345e-05 0.005551146
## [346,] 1.790249e-05 0.005797043
## [347,] 2.270976e-05 0.005845938
## [348,] 2.104278e-05 0.005569864
## [349,] 1.562193e-05 0.005533808
## [350,] 1.987952e-05 0.005915080
## [351,] 1.603276e-05 0.005558211
## [352,] 1.479762e-05 0.005510240
## [353,] 2.238643e-05 0.005507349
## [354,] 1.869409e-05 0.005810043
## [355,] 1.563097e-05 0.005667666
## [356,] 1.197976e-05 0.005562132
## [357,] 1.645361e-05 0.005460150
## [358,] 1.538924e-05 0.005795015
## [359,] 1.907940e-05 0.005507918
## [360,] 2.329570e-05 0.005684817
## [361,] 2.127423e-05 0.005802697
## [362,] 2.555177e-05 0.005826434
## [363,] 2.345799e-05 0.005893600
## [364,] 1.520194e-05 0.005789950
## [365,] 2.823366e-05 0.005476708
## [366,] 2.813159e-05 0.005829967
## [367,] 1.512618e-05 0.005551394
## [368,] 1.454080e-05 0.005939745
## [369,] 2.367064e-05 0.005662643
## [370,] 2.153044e-05 0.005593397
## [371,] 2.570719e-05 0.006024506
## [372,] 2.010543e-05 0.005517121
## [373,] 2.907129e-05 0.005885676
## [374,] 2.593532e-05 0.005613282
## [375,] 2.306660e-05 0.005614932
## [376,] 2.766976e-05 0.005793005
## [377,] 2.279211e-05 0.006092549
## [378,] 2.671539e-05 0.005865252
## [379,] 1.407796e-05 0.005477464
## [380,] 1.788107e-05 0.005301821
## [381,] 2.264400e-05 0.005700476
## [382,] 2.425162e-05 0.005289436
## [383,] 2.554039e-05 0.005890431
## [384,] 2.346118e-05 0.005509647
## [385,] 2.264413e-05 0.005522661
## [386,] 1.340424e-05 0.005756056
## [387,] 9.019573e-06 0.005643397
## [388,] 2.533685e-05 0.005527697
## [389,] 1.331877e-05 0.006002811
## [390,] 1.221804e-05 0.005106045
## [391,] 2.523557e-05 0.005798862
## [392,] 2.174555e-05 0.005806298
## [393,] 1.213966e-05 0.005384935
## [394,] 1.721665e-05 0.005280670
## [395,] 1.816498e-05 0.005613232
## [396,] 2.236704e-05 0.006022972
## [397,] 2.187483e-05 0.005900150
## [398,] 2.185767e-05 0.005860581
## [399,] 2.812935e-05 0.006000712
## [400,] 1.955471e-05 0.005449502
## [401,] 1.868886e-05 0.005669159
## [402,] 1.292837e-05 0.005746718
## [403,] 2.273220e-05 0.005622170
## [404,] 1.502460e-05 0.005610849
## [405,] 1.926923e-05 0.005311879
## [406,] 1.826944e-05 0.005298594
## [407,] 1.830747e-05 0.005670880
## [408,] 1.625815e-05 0.006082003
## [409,] 2.402049e-05 0.005947517
## [410,] 2.147640e-05 0.005547481
## [411,] 2.677809e-05 0.006044004
## [412,] 2.092099e-05 0.006121408
## [413,] 2.043475e-05 0.005723999
## [414,] 2.655215e-05 0.005534627
## [415,] 1.285375e-05 0.005564203
## [416,] 2.172514e-05 0.005761731
## [417,] 2.457252e-05 0.005617606
## [418,] 2.046170e-05 0.005524760
## [419,] 1.706611e-05 0.005752581
## [420,] 2.191913e-05 0.005364505
## [421,] 1.926017e-05 0.005524240
## [422,] 2.441270e-05 0.005201767
## [423,] 2.099773e-05 0.005343448
## [424,] 1.566318e-05 0.005189725
## [425,] 2.299808e-05 0.005801982
## [426,] 1.768481e-05 0.005354397
## [427,] 2.476450e-05 0.005475902
## [428,] 1.533962e-05 0.005443201
## [429,] 2.502275e-05 0.005742568
## [430,] 1.675223e-05 0.005640730
## [431,] 2.604963e-05 0.005272245
## [432,] 2.469585e-05 0.005829604
## [433,] 1.369513e-05 0.005360997
## [434,] 2.056334e-05 0.005723953
## [435,] 1.844025e-05 0.005589907
## [436,] 1.764258e-05 0.005820375
## [437,] 2.805274e-05 0.005442072
## [438,] 1.658096e-05 0.005663340
## [439,] 2.840992e-05 0.006016698
## [440,] 2.525175e-05 0.005613947
## [441,] 1.551589e-05 0.005319470
## [442,] 2.625722e-05 0.005925715
## [443,] 1.727062e-05 0.005540002
## [444,] 1.890687e-05 0.005689048
## [445,] 2.202673e-05 0.005955457
## [446,] 2.269650e-05 0.005634594
## [447,] 3.119392e-05 0.005920708
## [448,] 2.160145e-05 0.005400879
## [449,] 2.292079e-05 0.005773008
## [450,] 2.429769e-05 0.005834865
## [451,] 1.961282e-05 0.006038480
## [452,] 2.497750e-05 0.006289572
## [453,] 2.138865e-05 0.005756335
## [454,] 1.758002e-05 0.005492474
## [455,] 1.754845e-05 0.005828331
## [456,] 2.237626e-05 0.005441833
## [457,] 2.313177e-05 0.005761226
## [458,] 1.506277e-05 0.005758015
## [459,] 2.384743e-05 0.005663689
## [460,] 1.861767e-05 0.005283156
## [461,] 2.083036e-05 0.005482454
## [462,] 2.135303e-05 0.005453881
## [463,] 2.364509e-05 0.005935306
## [464,] 1.827737e-05 0.005786310
## [465,] 1.576488e-05 0.005527888
## [466,] 2.330584e-05 0.005526048
## [467,] 1.626097e-05 0.005584016
## [468,] 2.517158e-05 0.005391651
## [469,] 2.263731e-05 0.005824622
## [470,] 2.510095e-05 0.005831279
## [471,] 2.329522e-05 0.005767838
## [472,] 2.240070e-05 0.005224032
## [473,] 2.679378e-05 0.006091765
## [474,] 2.097286e-05 0.005459584
## [475,] 1.666260e-05 0.005805057
## [476,] 2.012433e-05 0.005355290
## [477,] 1.370045e-05 0.005877536
## [478,] 1.973585e-05 0.005657580
## [479,] 1.972236e-05 0.005336725
## [480,] 2.057080e-05 0.005381887
## [481,] 2.522159e-05 0.005686983
## [482,] 2.422257e-05 0.005782698
## [483,] 2.156513e-05 0.006255420
## [484,] 2.388327e-05 0.005539385
## [485,] 1.840267e-05 0.005609683
## [486,] 2.092229e-05 0.005248359
## [487,] 1.752643e-05 0.005600164
## [488,] 2.665943e-05 0.005529111
## [489,] 1.844326e-05 0.005661653
## [490,] 1.672958e-05 0.005881459
## [491,] 2.100832e-05 0.005816454
## [492,] 2.751404e-05 0.005980600
## [493,] 2.267081e-05 0.005642221
## [494,] 1.627721e-05 0.005975107
## [495,] 2.883773e-05 0.006012686
## [496,] 2.072799e-05 0.005568263
## [497,] 2.579217e-05 0.005411470
## [498,] 2.271103e-05 0.005645516
## [499,] 2.115161e-05 0.006086316
## [500,] 2.430168e-05 0.005223849
## [501,] 1.486517e-05 0.005777836
## [502,] 1.735013e-05 0.005569704
## [503,] 2.128933e-05 0.005938719
## [504,] 2.205370e-05 0.005487162
## [505,] 1.942343e-05 0.005936251
## [506,] 2.675443e-05 0.005680350
## [507,] 2.372930e-05 0.005674875
## [508,] 1.756727e-05 0.005786424
## [509,] 2.070511e-05 0.005886793
## [510,] 1.846271e-05 0.005666397
## [511,] 2.417162e-05 0.005470756
## [512,] 1.339069e-05 0.005292344
## [513,] 1.663162e-05 0.005775121
## [514,] 1.472980e-05 0.005526919
## [515,] 2.954349e-05 0.005476925
## [516,] 1.921359e-05 0.005478360
## [517,] 2.448040e-05 0.005864828
## [518,] 2.303446e-05 0.005210400
## [519,] 2.465786e-05 0.006074146
## [520,] 2.432288e-05 0.005912771
## [521,] 2.345882e-05 0.005604092
## [522,] 2.053078e-05 0.005791498
## [523,] 2.267513e-05 0.005340316
## [524,] 2.536789e-05 0.005745978
## [525,] 1.925708e-05 0.005863840
## [526,] 1.611268e-05 0.005619376
## [527,] 1.639186e-05 0.005462553
## [528,] 2.296813e-05 0.005509531
## [529,] 2.435204e-05 0.005802715
## [530,] 2.410975e-05 0.005601907
## [531,] 2.429953e-05 0.005450926
## [532,] 1.876369e-05 0.005336120
## [533,] 1.753313e-05 0.005835015
## [534,] 1.825643e-05 0.005533078
## [535,] 1.789166e-05 0.005325507
## [536,] 2.518835e-05 0.006115941
## [537,] 1.290308e-05 0.005816216
## [538,] 1.785733e-05 0.005508921
## [539,] 1.975739e-05 0.005622237
## [540,] 1.723046e-05 0.005628327
## [541,] 1.988123e-05 0.005693859
## [542,] 1.980398e-05 0.005396378
## [543,] 1.856827e-05 0.005847437
## [544,] 1.486515e-05 0.005302971
## [545,] 1.871867e-05 0.005843132
## [546,] 1.626835e-05 0.005776384
## [547,] 1.651720e-05 0.005821506
## [548,] 2.634271e-05 0.005742479
## [549,] 1.915957e-05 0.005743625
## [550,] 2.143280e-05 0.005609328
## [551,] 2.117415e-05 0.005959326
## [552,] 1.874078e-05 0.005973209
## [553,] 2.764209e-05 0.005419881
## [554,] 2.420524e-05 0.005672096
## [555,] 1.828545e-05 0.006031347
## [556,] 3.097527e-05 0.005668366
## [557,] 2.565162e-05 0.005624168
## [558,] 2.364377e-05 0.005840326
## [559,] 2.772396e-05 0.005554128
## [560,] 1.897930e-05 0.005540796
## [561,] 2.914332e-05 0.005531544
## [562,] 2.651970e-05 0.005614158
## [563,] 5.074907e-06 0.005512803
## [564,] 2.076538e-05 0.006058816
## [565,] 2.297289e-05 0.005595010
## [566,] 1.955990e-05 0.005365240
## [567,] 2.264323e-05 0.005693489
## [568,] 2.481003e-05 0.005674937
## [569,] 2.185828e-05 0.005644428
## [570,] 1.726464e-05 0.005387105
## [571,] 2.238201e-05 0.005703240
## [572,] 2.931333e-05 0.005491206
## [573,] 2.149403e-05 0.005864090
## [574,] 1.336752e-05 0.005792780
## [575,] 2.222406e-05 0.005500326
## [576,] 3.345592e-05 0.005940863
## [577,] 1.410897e-05 0.005354492
## [578,] 2.402836e-05 0.005714065
## [579,] 1.772229e-05 0.005406633
## [580,] 2.354631e-05 0.005614694
## [581,] 2.098751e-05 0.005245872
## [582,] 2.052251e-05 0.005861617
## [583,] 2.481617e-05 0.005874831
## [584,] 2.256277e-05 0.005797141
## [585,] 2.105255e-05 0.005358867
## [586,] 1.395848e-05 0.005487902
## [587,] 2.841873e-05 0.005801796
## [588,] 2.580883e-05 0.005709892
## [589,] 2.303030e-05 0.005506829
## [590,] 2.631488e-05 0.005765530
## [591,] 1.521739e-05 0.005956598
## [592,] 2.740483e-05 0.005734239
## [593,] 1.844390e-05 0.005712115
## [594,] 1.971814e-05 0.005782162
## [595,] 1.692150e-05 0.005684331
## [596,] 2.855254e-05 0.005791777
## [597,] 2.366978e-05 0.005514580
## [598,] 2.177079e-05 0.005756736
## [599,] 2.287305e-05 0.005513240
## [600,] 1.496820e-05 0.005516397
## [601,] 2.481301e-05 0.005315786
## [602,] 2.071186e-05 0.005626413
## [603,] 1.169826e-05 0.005770259
## [604,] 2.068014e-05 0.005767129
## [605,] 2.129740e-05 0.005345497
## [606,] 2.392521e-05 0.005756958
## [607,] 1.819755e-05 0.006065492
## [608,] 2.598535e-05 0.005829253
## [609,] 2.537965e-05 0.005945460
## [610,] 1.364401e-05 0.005478992
## [611,] 2.517887e-05 0.006101762
## [612,] 2.581137e-05 0.005847905
## [613,] 1.720755e-05 0.006041381
## [614,] 1.564818e-05 0.005884829
## [615,] 1.789092e-05 0.005543215
## [616,] 2.922004e-05 0.005942452
## [617,] 2.171191e-05 0.005440903
## [618,] 1.821648e-05 0.005489138
## [619,] 2.961761e-05 0.005994053
## [620,] 2.410191e-05 0.005746852
## [621,] 1.867188e-05 0.005862745
## [622,] 2.413861e-05 0.005496312
## [623,] 1.905144e-05 0.005575021
## [624,] 1.576379e-05 0.005352432
## [625,] 1.203964e-05 0.005766948
## [626,] 2.085686e-05 0.005361532
## [627,] 1.583663e-05 0.005940681
## [628,] 2.165777e-05 0.005685862
## [629,] 2.105988e-05 0.005183405
## [630,] 2.667686e-05 0.006016989
## [631,] 2.335205e-05 0.005661072
## [632,] 2.327503e-05 0.006125037
## [633,] 2.049802e-05 0.005378345
## [634,] 1.179168e-05 0.005596042
## [635,] 2.251534e-05 0.005711253
## [636,] 2.574775e-05 0.006011550
## [637,] 3.003682e-05 0.006046788
## [638,] 2.518923e-05 0.005470478
## [639,] 1.625815e-05 0.005709298
## [640,] 1.873386e-05 0.005560533
## [641,] 2.282584e-05 0.006008578
## [642,] 1.571759e-05 0.005653549
## [643,] 2.350035e-05 0.005480681
## [644,] 2.528328e-05 0.005679273
## [645,] 2.196716e-05 0.005452399
## [646,] 1.621507e-05 0.005516429
## [647,] 1.687056e-05 0.005579785
## [648,] 2.600264e-05 0.005724411
## [649,] 1.073397e-05 0.005534161
## [650,] 2.003969e-05 0.006103083
## [651,] 1.478737e-05 0.005689960
## [652,] 2.043064e-05 0.005793504
## [653,] 2.369231e-05 0.005848822
## [654,] 2.050390e-05 0.006098967
## [655,] 2.653801e-05 0.005765474
## [656,] 2.657888e-05 0.005400349
## [657,] 1.757331e-05 0.005918610
## [658,] 2.211405e-05 0.005826527
## [659,] 2.117540e-05 0.005993039
## [660,] 1.488292e-05 0.005630929
## [661,] 2.292001e-05 0.005952582
## [662,] 1.640790e-05 0.005358973
## [663,] 1.527326e-05 0.005538309
## [664,] 3.021246e-05 0.005588212
## [665,] 3.159073e-05 0.005744026
## [666,] 1.944992e-05 0.005773991
## [667,] 2.864189e-05 0.005990596
## [668,] 2.375772e-05 0.005463107
## [669,] 2.373223e-05 0.005861508
## [670,] 1.980966e-05 0.005791287
## [671,] 2.077820e-05 0.005301418
## [672,] 2.337407e-05 0.005700590
## [673,] 2.598528e-05 0.005630180
## [674,] 1.257829e-05 0.005415462
## [675,] 2.106687e-05 0.005844084
## [676,] 2.222330e-05 0.005148692
## [677,] 1.616478e-05 0.005729361
## [678,] 1.449275e-05 0.005522579
## [679,] 3.146178e-05 0.006106868
## [680,] 1.453146e-05 0.005743499
## [681,] 2.148164e-05 0.005588788
## [682,] 1.320329e-05 0.005901961
## [683,] 1.965773e-05 0.005780094
## [684,] 2.438985e-05 0.005478209
## [685,] 2.291228e-05 0.005316738
## [686,] 1.684525e-05 0.005540921
## [687,] 2.813137e-05 0.005527032
## [688,] 1.305933e-05 0.005073875
## [689,] 2.162243e-05 0.005554885
## [690,] 2.555319e-05 0.005616225
## [691,] 2.133621e-05 0.005370081
## [692,] 2.211776e-05 0.005805824
## [693,] 2.470147e-05 0.005404187
## [694,] 1.162470e-05 0.005490865
## [695,] 1.473261e-05 0.005420703
## [696,] 2.951010e-05 0.005721634
## [697,] 2.300971e-05 0.005847481
## [698,] 2.157876e-05 0.005942344
## [699,] 2.557394e-05 0.005257268
## [700,] 1.148413e-05 0.005886770
## [701,] 2.268380e-05 0.005430551
## [702,] 1.401005e-05 0.005523328
## [703,] 2.230566e-05 0.005343332
## [704,] 1.945644e-05 0.005656623
## [705,] 1.754043e-05 0.005484444
## [706,] 2.475562e-05 0.005933259
## [707,] 1.671897e-05 0.005274372
## [708,] 1.947548e-05 0.005275526
## [709,] 3.209592e-05 0.005890209
## [710,] 2.784729e-05 0.005818245
## [711,] 2.374668e-05 0.005389450
## [712,] 2.644347e-05 0.005841917
## [713,] 2.202923e-05 0.005819220
## [714,] 1.473490e-05 0.005888534
## [715,] 1.722063e-05 0.005914264
## [716,] 1.970537e-05 0.005470753
## [717,] 5.858758e-06 0.005759810
## [718,] 1.723240e-05 0.005779880
## [719,] 1.928584e-05 0.005875640
## [720,] 1.712859e-05 0.005737589
## [721,] 2.322426e-05 0.005165687
## [722,] 1.731363e-05 0.005648876
## [723,] 1.815097e-05 0.005912779
## [724,] 1.907106e-05 0.005749557
## [725,] 2.040635e-05 0.005630722
## [726,] 1.402840e-05 0.005282315
## [727,] 2.999749e-05 0.006170991
## [728,] 2.062144e-05 0.005728983
## [729,] 1.854223e-05 0.005705609
## [730,] 2.145902e-05 0.005435971
## [731,] 2.350033e-05 0.005588388
## [732,] 2.410777e-05 0.005334841
## [733,] 1.872504e-05 0.005820747
## [734,] 1.719322e-05 0.005501897
## [735,] 2.001829e-05 0.005722595
## [736,] 2.504421e-05 0.005333110
## [737,] 2.999182e-05 0.005975680
## [738,] 2.185368e-05 0.005587533
## [739,] 2.121984e-05 0.005567794
## [740,] 1.827712e-05 0.005231335
## [741,] 2.571540e-05 0.005625265
## [742,] 2.161369e-05 0.005782184
## [743,] 2.173628e-05 0.005628686
## [744,] 1.650185e-05 0.005773357
## [745,] 2.624271e-05 0.006041229
## [746,] 2.369609e-05 0.005921140
## [747,] 2.046217e-05 0.006088453
## [748,] 2.288735e-05 0.005634702
## [749,] 2.400017e-05 0.005205139
## [750,] 2.591945e-05 0.005226425
## [751,] 1.579991e-05 0.005671579
## [752,] 2.239857e-05 0.005741701
## [753,] 2.117264e-05 0.005897542
## [754,] 1.720322e-05 0.005845011
## [755,] 1.158746e-05 0.005994106
## [756,] 2.269757e-05 0.005369979
## [757,] 1.551865e-05 0.005552873
## [758,] 2.029398e-05 0.005915105
## [759,] 2.737880e-05 0.005680655
## [760,] 2.225952e-05 0.005952225
## [761,] 2.498924e-05 0.005769365
## [762,] 1.506928e-05 0.005573926
## [763,] 1.080006e-05 0.005642068
## [764,] 2.776153e-05 0.005473807
## [765,] 2.389073e-05 0.006042282
## [766,] 2.060238e-05 0.005596876
## [767,] 2.372373e-05 0.006191608
## [768,] 2.562885e-05 0.005925332
## [769,] 1.472569e-05 0.005661135
## [770,] 2.322394e-05 0.005459113
## [771,] 1.444178e-05 0.005596879
## [772,] 2.967488e-05 0.005716581
## [773,] 1.841911e-05 0.005336982
## [774,] 2.734723e-05 0.005840113
## [775,] 1.489162e-05 0.005633690
## [776,] 1.769379e-05 0.005779437
## [777,] 1.888535e-05 0.005860222
## [778,] 2.068927e-05 0.005657613
## [779,] 2.615899e-05 0.005542829
## [780,] 2.549131e-05 0.005535342
## [781,] 3.136094e-05 0.005807490
## [782,] 1.589633e-05 0.005476611
## [783,] 1.983035e-05 0.005737987
## [784,] 2.273182e-05 0.005595878
## [785,] 1.720186e-05 0.005395290
## [786,] 2.523328e-05 0.005472952
## [787,] 1.840539e-05 0.005375012
## [788,] 1.151930e-05 0.005513537
## [789,] 2.311618e-05 0.005800385
## [790,] 1.941734e-05 0.005763646
## [791,] 1.988115e-05 0.005742854
## [792,] 2.081905e-05 0.005635549
## [793,] 2.391344e-05 0.005454793
## [794,] 1.195685e-05 0.005685366
## [795,] 1.873733e-05 0.005849542
## [796,] 1.760495e-05 0.005130101
## [797,] 1.981956e-05 0.005540219
## [798,] 1.746159e-05 0.005877879
## [799,] 2.710523e-05 0.005466057
## [800,] 2.223833e-05 0.005797634
## [801,] 2.173287e-05 0.005632906
## [802,] 2.455429e-05 0.005515202
## [803,] 2.192565e-05 0.005834191
## [804,] 2.044283e-05 0.005586242
## [805,] 2.377182e-05 0.005538780
## [806,] 1.749330e-05 0.005356152
## [807,] 2.210204e-05 0.005295185
## [808,] 1.127329e-05 0.005847695
## [809,] 2.391082e-05 0.006058004
## [810,] 3.074995e-05 0.005747886
## [811,] 1.650416e-05 0.005504043
## [812,] 2.432636e-05 0.005504231
## [813,] 1.859519e-05 0.005463909
## [814,] 2.093897e-05 0.005689363
## [815,] 2.560144e-05 0.005600076
## [816,] 1.456627e-05 0.005641859
## [817,] 2.909007e-05 0.006023367
## [818,] 2.268772e-05 0.005537335
## [819,] 2.301881e-05 0.005691019
## [820,] 1.844173e-05 0.005976560
## [821,] 2.257247e-05 0.005738292
## [822,] 2.344967e-05 0.006006875
## [823,] 2.040475e-05 0.005680214
## [824,] 2.575989e-05 0.005897025
## [825,] 1.712936e-05 0.006107924
## [826,] 1.833773e-05 0.005232554
## [827,] 2.031619e-05 0.005648315
## [828,] 2.417748e-05 0.005725697
## [829,] 2.778510e-05 0.005668951
## [830,] 2.354704e-05 0.005465144
## [831,] 2.799681e-05 0.005708859
## [832,] 2.351032e-05 0.005678865
## [833,] 2.353439e-05 0.005448989
## [834,] 1.767150e-05 0.005754882
## [835,] 1.652062e-05 0.005535317
## [836,] 2.244555e-05 0.005735041
## [837,] 2.505195e-05 0.005424224
## [838,] 1.561160e-05 0.005499275
## [839,] 2.298435e-05 0.005292952
## [840,] 1.051856e-05 0.005442633
## [841,] 2.068327e-05 0.005636257
## [842,] 1.648936e-05 0.005470695
## [843,] 1.792909e-05 0.005628128
## [844,] 2.398537e-05 0.005652787
## [845,] 2.713833e-05 0.005541126
## [846,] 1.754565e-05 0.005547332
## [847,] 2.414072e-05 0.005703218
## [848,] 1.300129e-05 0.005470634
## [849,] 1.851610e-05 0.005438709
## [850,] 1.990188e-05 0.005636349
## [851,] 1.798519e-05 0.005661827
## [852,] 2.454806e-05 0.005501371
## [853,] 4.924156e-06 0.005366747
## [854,] 2.142633e-05 0.005632774
## [855,] 2.008675e-05 0.005235302
## [856,] 8.220834e-06 0.006046425
## [857,] 2.107995e-05 0.005532457
## [858,] 2.513374e-05 0.005635219
## [859,] 2.258632e-05 0.006341275
## [860,] 1.978624e-05 0.005492001
## [861,] 2.651359e-05 0.005448100
## [862,] 1.322801e-05 0.005773055
## [863,] 3.084589e-05 0.005863858
## [864,] 2.172958e-05 0.005488224
## [865,] 1.943286e-05 0.005915503
## [866,] 1.611100e-05 0.005672548
## [867,] 1.928859e-05 0.005493143
## [868,] 1.359373e-05 0.005630317
## [869,] 1.712176e-05 0.005448383
## [870,] 1.493938e-05 0.006137442
## [871,] 1.918451e-05 0.005692910
## [872,] 3.601895e-05 0.005441959
## [873,] 2.605418e-05 0.005603856
## [874,] 2.219500e-05 0.005539292
## [875,] 2.064074e-05 0.005635163
## [876,] 2.138268e-05 0.005674275
## [877,] 2.025628e-05 0.005627107
## [878,] 1.941284e-05 0.005502799
## [879,] 1.975114e-05 0.005673394
## [880,] 1.802693e-05 0.005830845
## [881,] 1.763538e-05 0.005433566
## [882,] 2.011347e-05 0.005455932
## [883,] 1.837802e-05 0.005546472
## [884,] 2.270998e-05 0.005703271
## [885,] 2.231689e-05 0.005601138
## [886,] 1.780123e-05 0.005821349
## [887,] 1.925872e-05 0.005701966
## [888,] 1.414439e-05 0.005817319
## [889,] 2.545751e-05 0.005402064
## [890,] 2.463939e-05 0.005458408
## [891,] 2.061166e-05 0.005589597
## [892,] 1.866457e-05 0.005752235
## [893,] 1.692606e-05 0.005712310
## [894,] 1.771489e-05 0.005764527
## [895,] 2.068747e-05 0.005933185
## [896,] 2.303584e-05 0.005640845
## [897,] 1.776066e-05 0.005336426
## [898,] 1.891449e-05 0.005949537
## [899,] 1.713761e-05 0.005547675
## [900,] 1.365297e-05 0.005245773
## [901,] 1.793208e-05 0.005535796
## [902,] 2.724502e-05 0.005903968
## [903,] 1.933316e-05 0.005811597
## [904,] 1.961226e-05 0.005333983
## [905,] 2.530594e-05 0.005455034
## [906,] 1.671215e-05 0.005497848
## [907,] 1.434714e-05 0.005812010
## [908,] 2.456191e-05 0.005781521
## [909,] 2.817198e-05 0.005630823
## [910,] 1.964464e-05 0.005679449
## [911,] 1.718125e-05 0.005742664
## [912,] 2.514476e-05 0.005477341
## [913,] 1.252725e-05 0.005658137
## [914,] 2.238608e-05 0.006042001
## [915,] 1.166421e-05 0.005783608
## [916,] 2.345494e-05 0.006047851
## [917,] 2.472844e-05 0.006197083
## [918,] 1.862822e-05 0.005744654
## [919,] 2.205995e-05 0.006020976
## [920,] 2.616979e-05 0.006015067
## [921,] 1.600317e-05 0.005450352
## [922,] 1.730616e-05 0.005656325
## [923,] 1.893291e-05 0.005588119
## [924,] 1.525302e-05 0.005723118
## [925,] 2.281437e-05 0.005827843
## [926,] 1.902488e-05 0.005490235
## [927,] 1.524046e-05 0.005319385
## [928,] 1.701195e-05 0.005774563
## [929,] 1.700477e-05 0.005561118
## [930,] 2.438457e-05 0.005741854
## [931,] 2.378918e-05 0.005067587
## [932,] 1.665674e-05 0.005996739
## [933,] 1.235462e-05 0.005508635
## [934,] 1.923012e-05 0.005774870
## [935,] 1.949465e-05 0.005873372
## [936,] 1.688132e-05 0.005650961
## [937,] 1.751300e-05 0.005829804
## [938,] 2.080568e-05 0.005785545
## [939,] 1.908009e-05 0.005760310
## [940,] 2.567214e-05 0.005553360
## [941,] 2.662618e-05 0.005631466
## [942,] 2.744982e-05 0.005516770
## [943,] 2.492801e-05 0.005814181
## [944,] 2.360597e-05 0.005287631
## [945,] 2.565329e-05 0.005753994
## [946,] 1.286406e-05 0.005549450
## [947,] 2.246583e-05 0.005400300
## [948,] 2.254392e-05 0.005460604
## [949,] 1.890115e-05 0.005609463
## [950,] 2.477361e-05 0.005519206
## [951,] 2.228570e-05 0.005622226
## [952,] 1.464251e-05 0.005466058
## [953,] 1.902988e-05 0.005902711
## [954,] 2.063055e-05 0.006048596
## [955,] 2.588979e-05 0.006166477
## [956,] 9.468391e-06 0.005442962
## [957,] 1.336062e-05 0.005328393
## [958,] 2.745981e-05 0.006169873
## [959,] 2.235135e-05 0.005612275
## [960,] 1.353609e-05 0.005485778
## [961,] 2.150757e-05 0.005899577
## [962,] 1.900396e-05 0.005604669
## [963,] 1.549511e-05 0.005547755
## [964,] 1.843703e-05 0.006048712
## [965,] 1.590653e-05 0.005489368
## [966,] 1.740185e-05 0.005634788
## [967,] 2.331726e-05 0.005170089
## [968,] 2.347935e-05 0.005508191
## [969,] 3.817465e-06 0.004991788
## [970,] 2.386374e-05 0.005619864
## [971,] 2.240752e-05 0.005474919
## [972,] 1.851128e-05 0.005652873
## [973,] 1.667869e-05 0.006085265
## [974,] 2.091892e-05 0.005924862
## [975,] 2.459644e-05 0.005614826
## [976,] 1.967854e-05 0.005378635
## [977,] 1.571426e-05 0.005645551
## [978,] 3.003676e-05 0.005678659
## [979,] 1.205860e-05 0.005720547
## [980,] 2.098949e-05 0.005502613
## [981,] 3.414701e-05 0.006151904
## [982,] 1.764493e-05 0.005717488
## [983,] 2.898090e-05 0.005601097
## [984,] 2.609895e-05 0.006060249
## [985,] 1.233738e-05 0.005551240
## [986,] 1.747392e-05 0.005278965
## [987,] 1.958433e-05 0.005975962
## [988,] 3.184873e-05 0.005433662
## [989,] 2.677302e-05 0.005581749
## [990,] 1.807392e-05 0.005302143
## [991,] 1.692578e-05 0.005622885
## [992,] 1.479917e-05 0.005469774
## [993,] 8.283038e-06 0.005691142
## [994,] 2.687956e-05 0.005810610
## [995,] 1.619631e-05 0.005769484
## [996,] 2.579259e-05 0.005801199
## [997,] 2.521722e-05 0.005689304
## [998,] 1.807392e-05 0.005474952
## [999,] 2.177120e-05 0.005855273
## [1000,] 1.977961e-05 0.005719658
Intercept
Original Coefficient: -11.54047 Bias: -0.02755 Bootstrap Standard Error: 0.42048 Interpretation: The estimated intercept has a bias correction applied, and the bootstrap standard error represents the uncertainty associated with this coefficient.
Income:-
Original Coefficient: 0.000020809 Bias: 0.000000158 Bootstrap Standard Error: 0.0000047295 Interpretation: The estimated coefficient for ‘income’ has a small bias correction, and the bootstrap standard error provides an estimate of its uncertainty.
Balance:-
Original Coefficient: 0.0056471 Bias: 0.00001297 Bootstrap Standard Error: 0.0002217214 Interpretation: The estimated coefficient for ‘balance’ has a small bias correction, and the bootstrap standard error gives an indication of the uncertainty associated with this coefficient.
Comparison with glm() Standard Errors: The bootstrap standard errors provide a more empirical and distribution-based estimate of uncertainty compared to the asymptotic standard errors obtained from the glm() function. Differences between the two methods might arise due to the assumptions underlying the asymptotic standard errors and the flexibility of the bootstrap method in handling various data distributions and sample sizes. In summary, the bootstrap standard errors offer an alternative perspective on the uncertainty of the logistic regression coefficients, considering the empirical distribution of the data. Comparing these results with the standard errors obtained from the glm() function can provide insights into the robustness of the estimates.
# Load necessary libraries
library(ISLR2)
library(MASS) # for lda() function
##
## Attaching package: 'MASS'
## The following object is masked from 'package:ISLR2':
##
## Boston
# Load the Weekly dataset
data(Weekly)
# Fit a logistic regression model
logit_model <- glm(Direction ~ Lag1 + Lag2, data = Weekly, family = binomial)
# Display summary of the model
summary(logit_model)
##
## Call:
## glm(formula = Direction ~ Lag1 + Lag2, family = binomial, data = Weekly)
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 0.22122 0.06147 3.599 0.000319 ***
## Lag1 -0.03872 0.02622 -1.477 0.139672
## Lag2 0.06025 0.02655 2.270 0.023232 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 1496.2 on 1088 degrees of freedom
## Residual deviance: 1488.2 on 1086 degrees of freedom
## AIC: 1494.2
##
## Number of Fisher Scoring iterations: 4
# Exclude the first observation
Weekly_subset <- Weekly[-1, ]
# Fit a logistic regression model
logit_model_subset <- glm(Direction ~ Lag1 + Lag2, data = Weekly_subset, family = binomial)
# Display summary of the model
summary(logit_model_subset)
##
## Call:
## glm(formula = Direction ~ Lag1 + Lag2, family = binomial, data = Weekly_subset)
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 0.22324 0.06150 3.630 0.000283 ***
## Lag1 -0.03843 0.02622 -1.466 0.142683
## Lag2 0.06085 0.02656 2.291 0.021971 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 1494.6 on 1087 degrees of freedom
## Residual deviance: 1486.5 on 1085 degrees of freedom
## AIC: 1492.5
##
## Number of Fisher Scoring iterations: 4
# Predict the direction for the first observation using the model from (b)
prediction_first_obs <- predict(logit_model_subset, newdata = Weekly[1, ], type = "response")
# Classify based on the probability threshold of 0.5
predicted_direction <- ifelse(prediction_first_obs > 0.5, "Up", "Down")
# Actual direction of the first observation
actual_direction <- Weekly$Direction[1]
# Check if the observation was correctly classified
correctly_classified <- (predicted_direction == actual_direction)
# Display results
cat("Predicted Direction:", predicted_direction, "\n")
## Predicted Direction: Up
cat("Actual Direction:", actual_direction, "\n")
## Actual Direction: 1
cat("Correctly Classified:", correctly_classified, "\n")
## Correctly Classified: FALSE
# Initialize an empty vector to store classification errors
classification_errors <- numeric(nrow(Weekly))
# Perform Leave-One-Out Cross-Validation
for (i in 1:nrow(Weekly)) {
# Create a subset excluding the ith observation
data_subset <- Weekly[-i, ]
# Fit a logistic regression model
logit_model_loocv <- glm(Direction ~ Lag1 + Lag2, data = data_subset, family = binomial)
# Predict the direction for the ith observation
prediction_loocv <- predict(logit_model_loocv, newdata = Weekly[i, ], type = "response")
# Classify based on the probability threshold of 0.5
predicted_direction_loocv <- ifelse(prediction_loocv > 0.5, "Up", "Down")
# Actual direction of the ith observation
actual_direction_loocv <- Weekly$Direction[i]
# Determine whether an error was made in predicting the direction for the ith observation
classification_errors[i] <- ifelse(predicted_direction_loocv != actual_direction_loocv, 1, 0)
}
# Display the vector of classification errors
print("Classification Errors:")
## [1] "Classification Errors:"
print(classification_errors)
## [1] 1 1 0 1 0 1 0 0 0 1 1 0 1 0 1 0 1 0 1 0 0 0 1 1 1 1 1 1 0 1 1 1 1 0 1 0 0
## [38] 0 1 0 1 0 0 1 0 1 1 1 0 1 0 0 0 1 0 0 1 1 0 0 0 0 1 0 1 1 0 0 1 0 1 1 0 0
## [75] 0 1 0 1 1 0 0 1 1 0 1 1 0 0 1 0 0 1 1 1 0 0 0 0 0 1 0 1 1 0 0 1 0 1 0 0 1
## [112] 1 0 0 1 0 0 1 0 0 1 1 1 1 0 0 0 1 0 1 0 1 1 0 0 0 1 1 1 0 0 0 1 0 0 0 0 0
## [149] 0 1 1 1 0 1 0 0 1 1 0 1 0 0 1 1 0 0 1 0 0 1 0 0 1 1 1 0 1 0 1 0 0 0 0 0 0
## [186] 0 0 1 1 0 1 0 1 0 1 0 1 0 0 1 0 0 1 0 0 1 0 1 0 1 1 1 0 0 1 1 0 1 0 0 1 1
## [223] 0 0 0 1 1 1 0 1 0 1 0 1 0 0 0 1 1 0 1 0 1 0 1 0 1 0 1 1 0 1 0 0 1 0 0 1 0
## [260] 0 0 0 0 1 0 0 0 1 0 0 1 0 0 0 1 0 0 1 0 0 1 0 0 1 0 1 1 0 0 0 0 0 1 0 1 0
## [297] 0 1 0 0 0 1 0 0 1 1 0 0 1 0 0 0 0 1 0 1 1 0 0 1 0 1 0 1 1 0 0 0 1 0 1 0 0
## [334] 1 1 1 1 0 1 0 0 1 0 0 0 1 0 1 0 1 0 0 0 0 0 1 1 0 0 1 0 0 1 0 0 0 1 1 0 1
## [371] 1 1 1 1 0 0 0 1 0 0 0 0 0 0 1 0 1 1 0 0 1 1 0 0 0 0 0 1 0 0 1 1 1 0 1 0 1
## [408] 0 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 1 0 1 0 1 0 1 0 0 1 0 1 0 0 0 0 0 1 1 1 1
## [445] 0 1 1 0 1 0 1 1 0 1 0 0 1 0 0 1 1 0 0 0 0 1 1 0 0 1 0 1 0 0 0 1 0 0 1 0 0
## [482] 0 1 1 1 0 1 0 0 0 1 0 1 1 1 0 0 0 0 1 1 1 0 1 1 0 1 0 0 0 1 0 1 0 0 0 1 0
## [519] 1 1 0 0 1 1 0 0 0 1 1 0 1 0 1 1 1 1 1 0 0 0 1 0 0 0 1 1 0 1 0 0 0 1 1 1 1
## [556] 1 1 0 1 0 1 0 0 1 0 0 1 1 1 0 0 0 1 1 1 1 1 1 1 1 1 1 0 1 0 0 1 0 0 1 0 1
## [593] 0 0 1 0 0 1 0 1 1 0 1 1 1 0 1 0 1 0 1 0 0 0 1 0 1 0 1 0 1 1 0 1 1 0 1 0 1
## [630] 0 1 1 1 1 0 1 1 0 0 0 1 1 1 1 0 1 1 1 0 1 0 0 0 1 1 1 1 1 1 0 1 0 0 1 0 0
## [667] 0 1 1 0 1 0 1 1 1 1 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 1 0 1 1
## [704] 0 0 0 0 1 0 1 0 1 0 1 0 0 1 1 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 1 1 1 0 1 1 0
## [741] 1 1 1 1 0 0 0 1 1 1 1 1 1 0 1 0 0 0 0 0 0 1 0 1 1 1 0 0 0 1 0 0 1 0 0 0 1
## [778] 1 1 0 0 0 1 0 0 1 1 1 0 0 1 0 1 0 1 0 0 1 0 0 1 0 0 0 0 0 1 0 1 1 0 0 1 1
## [815] 0 1 1 1 0 0 0 0 0 1 1 0 0 1 0 0 1 0 1 0 0 0 1 1 0 1 1 0 1 0 1 0 1 1 0 0 1
## [852] 1 1 0 1 1 0 0 0 1 0 1 0 1 0 1 0 0 0 0 0 1 0 0 1 1 0 0 1 0 1 0 1 1 0 1 0 1
## [889] 1 0 0 0 1 0 0 0 0 0 0 0 1 0 1 0 1 0 0 0 1 1 1 1 1 0 1 1 0 0 0 0 0 1 0 0 1
## [926] 0 0 0 0 1 0 1 1 1 0 0 1 1 0 1 1 1 1 0 1 0 1 0 1 0 1 0 1 0 0 1 1 1 1 1 0 1
## [963] 0 0 0 1 1 1 0 1 1 1 1 0 0 0 0 1 1 0 0 0 0 1 0 0 1 1 1 0 0 1 1 1 0 1 0 0 0
## [1000] 0 1 0 0 1 0 1 0 0 1 1 1 1 0 1 0 0 1 0 0 1 0 0 1 1 0 1 1 1 0 1 1 0 0 0 1 0
## [1037] 1 0 1 1 1 1 0 0 1 0 0 0 0 0 0 1 0 1 1 0 0 0 0 0 1 1 1 0 0 0 1 0 1 1 1 0 0
## [1074] 0 0 1 0 0 0 0 0 1 0 1 0 0 0 0 0
# Calculate the LOOCV estimate for the test error
loocv_error_estimate <- mean(classification_errors)
# Display the LOOCV estimate for the test error
cat("LOOCV Estimate for Test Error:",loocv_error_estimate)
## LOOCV Estimate for Test Error: 0.4499541
The LOOCV estimate for the test error is approximately 0.45, or 45%. This value represents the average classification error rate over all observations when using a logistic regression model to predict the direction of the market based on Lag1 and Lag2.
Interpretation:
Error Rate: The 45% test error suggests that, on average, the logistic regression model misclassifies the direction of the market for nearly half of the observations in the dataset during the LOOCV process.
Model Performance: A test error of 45% indicates that the logistic regression model might not be highly accurate in predicting the market direction based on the given predictors (Lag1 and Lag2). This level of error suggests that there may be room for improvement in the model’s predictive performance.
Considerations: It’s important to consider the specific context of the problem and the implications of misclassification. Depending on the application, a 45% error rate might be acceptable or might require further investigation and model refinement.
Further Analysis: To improve the model, you may explore additional predictors, consider more complex models, or fine-tune the existing model parameters. Additionally, evaluating the model’s performance using other metrics, such as precision, recall, or the ROC curve, could provide a more comprehensive understanding of its strengths and weaknesses.
In summary, the LOOCV estimate for the test error provides an empirical measure of the logistic regression model’s performance on the dataset. Further analysis and model refinement may be warranted to enhance predictive accuracy.
# Load necessary library
library(ISLR2)
# Load the Boston housing dataset
data(Boston)
# Calculate the sample mean of 'medv'
sample_mean <- mean(Boston$medv)
# Display the estimate for the population mean
cat("Estimated Population Mean (μˆ) of 'medv':", sample_mean, "\n")
## Estimated Population Mean (μˆ) of 'medv': 22.53281
# Calculate the sample standard deviation of 'medv'
sample_sd <- sd(Boston$medv)
# Calculate the number of observations
n <- length(Boston$medv)
# Calculate the standard error of the sample mean
se_mean <- sample_sd / sqrt(n)
# Display the estimate for the standard error
cat("Estimate of Standard Error (SE) of μˆ:", se_mean, "\n")
## Estimate of Standard Error (SE) of μˆ: 0.4088611
The estimate of the standard error μ, the population mean of ‘medv’ in the Boston housing dataset, is approximately 0.4089.
Interpretation:
Precision of the Estimate: The standard error provides a measure of the precision or reliability of the sample mean as an estimate of the population mean
Magnitude of Standard Error: In this case, a standard error of 0.4089 indicates that, on average, we might expect the sample mean to deviate from the true population mean by approximately 0.4089 units.
Uncertainty: A smaller standard error suggests a more precise estimate, indicating that the sample mean is likely closer to the true population mean. Conversely, a larger standard error would imply more uncertainty in the estimate.
Confidence Interval: The standard error is often used to construct a confidence interval around the sample mean, indicating a range within which we are reasonably confident the true population mean lies.
For example, a 95% confidence interval for the population mean could be constructed as ±1.96×SE. This interval would capture the range within which we are 95% confident the true population mean lies.
In summary, the standard error of approximately 0.4089 provides an indication of the precision of the sample mean estimate, helping researchers and analysts understand the likely range of values within which the true population mean might fall.
# Load necessary library
library(boot)
# Define the bootstrap function to calculate the mean
bootstrap_mean <- function(data, indices) {
sample_data <- data[indices]
return(mean(sample_data))
}
# Set the seed for reproducibility
set.seed(123)
# Perform bootstrap resampling
bootstrap_results <- boot(data = Boston$medv, statistic = bootstrap_mean, R = 1000)
# Calculate the 95% confidence interval
conf_interval <- quantile(bootstrap_results$t, c(0.025, 0.975))
# Display the results
cat("Bootstrap Estimate of Mean:", mean(bootstrap_results$t), "\n")
## Bootstrap Estimate of Mean: 22.51673
cat("95% Confidence Interval (Bootstrap):", conf_interval, "\n")
## 95% Confidence Interval (Bootstrap): 21.78198 23.34239
# Compare with t-test results
t_test_results <- t.test(Boston$medv)
cat("95% Confidence Interval (t-test):", t_test_results$conf.int, "\n")
## 95% Confidence Interval (t-test): 21.72953 23.33608
Bootstrap Estimate:
Mean: 22.51673 95% Confidence Interval: [21.78198, 23.34239] t-test Results:
95% Confidence Interval: [21.72953, 23.33608] Comparison:
The bootstrap estimate of the mean is 22.51673, and the 95% confidence interval (21.78198, 23.34239) is based on resampling from the dataset. The t-test also provides a 95% confidence interval (21.72953, 23.33608) using the traditional statistical method. Observations:
The point estimate of the mean is similar between the two methods, with the bootstrap estimate slightly higher. The confidence intervals obtained from the bootstrap and the t-test are reasonably close but may exhibit slight differences due to the nature of the methods used. Interpretation:
Both methods provide estimates for the mean of ‘medv’ along with a range of values (confidence interval) within which the true population mean is likely to fall. The bootstrap method, being a resampling technique, offers a non-parametric approach that does not rely on specific distributional assumptions. The t-test, on the other hand, assumes that the data is approximately normally distributed. Conclusion:
The agreement between the two methods supports the validity of the results. The choice between the bootstrap method and the t-test depends on the characteristics of the data and the assumptions that can be reasonably made in a given context. In summary, both methods provide useful insights into the estimation of the mean of ‘medv’ and its uncertainty, and the similarity between their results enhances confidence in the findings.
# Calculate the sample median of 'medv'
sample_median <- median(Boston$medv)
# Display the estimate for the population median
cat("Estimated Population Median (μˆmed) of 'medv':", sample_median, "\n")
## Estimated Population Median (μˆmed) of 'medv': 21.2
# Define the bootstrap function to calculate the median
bootstrap_median <- function(data, indices) {
sample_data <- data[indices]
return(median(sample_data))
}
# Set the seed for reproducibility
set.seed(123)
# Perform bootstrap resampling
bootstrap_results_median <- boot(data = Boston$medv, statistic = bootstrap_median, R = 1000)
# Calculate the standard error of the median
se_median <- sd(bootstrap_results_median$t)
# Display the estimate for the standard error of the median
cat("Estimate of Standard Error (SE) of μˆmed:", se_median, "\n")
## Estimate of Standard Error (SE) of μˆmed: 0.3676453
Interpretation:
The standard error of the median provides a measure of the variability or uncertainty associated with the sample median as an estimate of the population median. In this context, a standard error of 0.3676 indicates the expected amount of variation in the sample median across different bootstrap samples.
Magnitude of Standard Error: A smaller standard error suggests greater precision in estimating the population median, indicating that the sample median is likely closer to the true population median. A larger standard error would imply more uncertainty in the estimate.
Use of Bootstrap: The bootstrap method is particularly useful when there is no simple formula for computing the standard error of a statistic, such as the median.
By resampling from the dataset, the bootstrap provides an empirical distribution of the statistic, allowing for the estimation of its variability.
Practical Implications: Researchers and analysts can use the standard error of the median to construct confidence intervals or make inferences about the true population median.
Understanding the uncertainty associated with the estimate is crucial for providing a complete picture of the reliability of the median as a summary statistic for ‘medv’.
In summary, the estimate of the standard error of the median obtained through the bootstrap method adds valuable information about the variability in the sample median and contributes to the overall assessment of the reliability of the median as a measure of central tendency for the ‘medv’ variable.
# Calculate the tenth percentile of 'medv'
tenth_percentile <- quantile(Boston$medv, 0.1)
# Display the estimate for the tenth percentile
cat("Estimated Tenth Percentile (μˆ0.1) of 'medv':", tenth_percentile, "\n")
## Estimated Tenth Percentile (μˆ0.1) of 'medv': 12.75
# Define the bootstrap function to calculate the tenth percentile
bootstrap_tenth_percentile <- function(data, indices) {
sample_data <- data[indices]
return(quantile(sample_data, 0.1))
}
# Set the seed for reproducibility
set.seed(123)
# Perform bootstrap resampling
bootstrap_results_tenth_percentile <- boot(data = Boston$medv, statistic = bootstrap_tenth_percentile, R = 1000)
# Calculate the standard error of the tenth percentile
se_tenth_percentile <- sd(bootstrap_results_tenth_percentile$t)
# Display the estimate for the standard error of the tenth percentile
cat("Estimate of Standard Error (SE) of μˆ0.1:", se_tenth_percentile, "\n")
## Estimate of Standard Error (SE) of μˆ0.1: 0.527868
Interpretation:
The standard error of the tenth percentile provides a measure of the variability or uncertainty associated with the sample tenth percentile as an estimate of the population tenth percentile.
In this context, a standard error of 0.5279 indicates the expected amount of variation in the sample tenth percentile across different bootstrap samples.
Magnitude of Standard Error: A smaller standard error suggests greater precision in estimating the population tenth percentile, indicating that the sample tenth percentile is likely closer to the true population tenth percentile. A larger standard error would imply more uncertainty in the estimate.
Use of Bootstrap: The bootstrap method is particularly useful when there is no simple formula for computing the standard error of a specific quantile, such as the tenth percentile. By resampling from the dataset, the bootstrap provides an empirical distribution of the quantile, allowing for the estimation of its variability.
Practical Implications: Researchers and analysts can use the standard error of the tenth percentile to construct confidence intervals or make inferences about the true population tenth percentile. Understanding the uncertainty associated with the estimate is crucial for providing a complete picture of the reliability of the tenth percentile as a summary statistic for ‘medv’.
In summary, the estimate of the standard error of the tenth percentile obtained through the bootstrap method adds valuable information about the variability in the sample tenth percentile and contributes to the overall assessment of the reliability of this specific quantile as a measure of central tendency for the ‘medv’ variable.