I am trying to conduct a bootstrapped regression model using code from Andy Field's textbook Discovering Statistics Using R.
I am struggling to interpret an error message that I receive when running the boot()
function. From reading other forum posts I understand that it is telling me that there is an imbalance in the number of items between two objects, but I don't understand what this means in my context and how I can resolve it.
You can download my data here (a publicly available Dataset on Airbnb listings) and find my code and the full error message below. I am using a mixture of factored dummy variables and continuous variables as predictors. Thanks in advance for any help!
Code:
bootReg <- function (formula, data, i)
{
d <- data [i,]
fit <- lm(formula, data = d)
return(coef(fit))
}
bootResults <- boot(statistic = bootReg, formula = review_scores_rating ~ instant_bookable + cancellation_policy +
host_since_cat + host_location_cat + host_response_time +
host_is_superhost + host_listings_cat + property_type + room_type +
accommodates + bedrooms + beds + price + security_deposit +
cleaning_fee + extra_people + minimum_nights + amenityBreakfast +
amenityAC + amenityElevator + amenityKitchen + amenityHostGreeting +
amenitySmoking + amenityPets + amenityWifi + amenityTV,
data = listingsRating, R = 2000)
Error:
Error in t.star[r, ] <- res[[r]] :
number of items to replace is not a multiple of replacement length
In addition: Warning message:
In doTryCatch(return(expr), name, parentenv, handler) :
restarting interrupted promise evaluation