0% found this document useful (0 votes)
106 views2 pages

Pls Script

The document repeats code to load cola preference data, run a partial least squares regression (PLS) model with cross validation, identify the best number of dimensions, re-run the model, and create a bar plot of the coefficients of the top 5 predictors. This is done multiple times without any explanation of the repetition.

Uploaded by

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

Pls Script

The document repeats code to load cola preference data, run a partial least squares regression (PLS) model with cross validation, identify the best number of dimensions, re-run the model, and create a bar plot of the coefficients of the top 5 predictors. This is done multiple times without any explanation of the repetition.

Uploaded by

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

cola.url = "http://wiki.q-researchsoftware.com/images/d/db/Stacked_colas.

csv"
colas = read.csv(cola.url)
str(colas)

colas = subset(colas, select = -c(URLID, brand))

library(pls)
pls.model = plsr(pref ~ ., data = colas, validation = "CV")
summary(pls.model)

# Find the number of dimensions with lowest cross validation error


cv = RMSEP(pls.model)
best.dims = which.min(cv$val[estimate = "adjCV", , ]) - 1

# Rerun the model


pls.model = plsr(pref ~ ., data = colas, ncomp = best.dims)
summary(pls.model)

coefficients = coef(pls.model)
sum.coef = sum(sapply(coefficients, abs))
coefficients = coefficients * 100 / sum.coef
coefficients = sort(coefficients[, 1 , 1])
barplot(tail(coefficients, 5))

cola.url = "http://wiki.q-researchsoftware.com/images/d/db/Stacked_colas.csv"
colas = read.csv(cola.url)
str(colas)

colas = subset(colas, select = -c(URLID, brand))

library(pls)
pls.model = plsr(pref ~ ., data = colas, validation = "CV")
summary(pls.model)

# Find the number of dimensions with lowest cross validation error


cv = RMSEP(pls.model)
best.dims = which.min(cv$val[estimate = "adjCV", , ]) - 1

# Rerun the model


pls.model = plsr(pref ~ ., data = colas, ncomp = best.dims)
summary(pls.model)

coefficients = coef(pls.model)
sum.coef = sum(sapply(coefficients, abs))
coefficients = coefficients * 100 / sum.coef
coefficients = sort(coefficients[, 1 , 1])
barplot(tail(coefficients, 5))

cola.url = "http://wiki.q-researchsoftware.com/images/d/db/Stacked_colas.csv"
colas = read.csv(cola.url)
str(colas)

colas = subset(colas, select = -c(URLID, brand))

library(pls)
pls.model = plsr(pref ~ ., data = colas, validation = "CV")
summary(pls.model)
# Find the number of dimensions with lowest cross validation error
cv = RMSEP(pls.model)
best.dims = which.min(cv$val[estimate = "adjCV", , ]) - 1

# Rerun the model


pls.model = plsr(pref ~ ., data = colas, ncomp = best.dims)
summary(pls.model)

coefficients = coef(pls.model)
sum.coef = sum(sapply(coefficients, abs))
coefficients = coefficients * 100 / sum.coef
coefficients = sort(coefficients[, 1 , 1])
barplot(tail(coefficients, 5))

cola.url = "http://wiki.q-researchsoftware.com/images/d/db/Stacked_colas.csv"
colas = read.csv(cola.url)
str(colas)

colas = subset(colas, select = -c(URLID, brand))

library(pls)
pls.model = plsr(pref ~ ., data = colas, validation = "CV")
summary(pls.model)

# Find the number of dimensions with lowest cross validation error


cv = RMSEP(pls.model)
best.dims = which.min(cv$val[estimate = "adjCV", , ]) - 1

# Rerun the model


pls.model = plsr(pref ~ ., data = colas, ncomp = best.dims)
summary(pls.model)

coefficients = coef(pls.model)
sum.coef = sum(sapply(coefficients, abs))
coefficients = coefficients * 100 / sum.coef
coefficients = sort(coefficients[, 1 , 1])
barplot(tail(coefficients, 5))

You might also like