Skip to content

Commit

Permalink
Removed semPLS dependancy
Browse files Browse the repository at this point in the history
Added a mobi dataset
Added data.R to document dataset
changed all files to call internal dataset
Aadded mobi.md document for dataset
Addresses Issue #21
  • Loading branch information
NicholasDanks committed Aug 5, 2017
1 parent 1ec6e7d commit 3f8ef66
Show file tree
Hide file tree
Showing 29 changed files with 775 additions and 685 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Description: SEMinR offers an easy to write and easy to change syntax for
specifying `plsm` models that are compatible with `semPLS`, `sem`,
and possibly other packages supporting structural equation models.
Imports:
semPLS, parallel
parallel
License: GPL-3
LazyData: TRUE
RoxygenNote: 5.0.1
Expand Down
2 changes: 1 addition & 1 deletion R/bootstrap.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#' @seealso \code{\link{relationships}} \code{\link{constructs}} \code{\link{paths}} \code{\link{interactions}}
#'
#' @examples
#' data("mobi", package = "semPLS")
#' mobi <- mobi
#'
#' # seminr syntax for creating measurement model
#' mobi_mm <- constructs(
Expand Down
2 changes: 1 addition & 1 deletion R/consistent.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#' \code{\link{bootstrap_model}}
#'
#' @examples
#' data("mobi", package = "semPLS")
#' mobi <- mobi
#'
#' #seminr syntax for creating measurement model
#' mobi_mm <- constructs(
Expand Down
2 changes: 1 addition & 1 deletion R/consistent_interaction.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#' \code{\link{bootstrap_model}}
#'
#' @examples
#' data("mobi", package = "semPLS")
#' mobi <- mobi
#'
#' #seminr syntax for creating measurement model
#' mobi_mm <- constructs(
Expand Down
38 changes: 38 additions & 0 deletions R/data.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#' Measurement Instrument for the Mobile Phone Industry
#'
#' The data set is used as measurement instrument for the european customer satisfaction
#' index (ECSI) adapted to the mobile phone market, see Tenenhaus et al. (2005).
#'
#' @format A data frame with 250 rows and 24 variables:
#' \describe{
#' \item{CUEX1}{Expectations for the overall quality of “your mobile phone provider” at the moment you became customer of this provider}
#' \item{CUEX2}{Expectations for “your mobile phone provider” to provide products and services to meet your personal need}
#' \item{CUEX3}{How often did you expect that things could go wrong at “your mobile phone provider}
#' \item{CUSA1}{Overall satisfaction}
#' \item{CUSA2}{Fulfillment of expectations}
#' \item{CUSA3}{How well do you think “your mobile phone provider” compares with your ideal mobile phone provider?}
#' \item{CUSCO}{You complained about “your mobile phone provider” last year. How well, or poorly, was your most recent complaint handled or You did not complain about “your mobile phone provider” last year. Imagine you have to complain to “your mobile phone rovider” because of a bad quality of service or product. To what extent do you think that “your mobile phone provider” will care about your complaint?}
#' \item{CUSL1}{If you would need to choose a new mobile phone provider how likely is it that you would choose “your provider” again?}
#' \item{CUSL2}{Let us now suppose that other mobile phone providers decide to lower their fees and prices, but “your mobile phone provider” stays at the same level as today. At which level of difference (in percentage) would you choose another mobile phone provider?}
#' \item{CUSL3}{If a friend or colleague asks you for advice, how likely is it that you would recommend “your mobile phone provider”?}
#' \item{IMAG1}{It can be trusted what it says and does}
#' \item{IMAG2}{It is stable and firmly established}
#' \item{IMAG3}{It has a social contribution to society}
#' \item{IMAG4}{It is concerned with customers}
#' \item{IMAG5}{It is innovative and forward looking}
#' \item{PERQ1}{Overall perceived quality}
#' \item{PERQ2}{Technical quality of the network}
#' \item{PERQ3}{Customer service and personal advice offered}
#' \item{PERQ4}{Quality of the services you use}
#' \item{PERQ5}{Range of services and products offered}
#' \item{PERQ6}{Reliability and accuracy of the products and services provided}
#' \item{PERQ7}{Clarity and transparency of information provided}
#' \item{PERV1}{Given the quality of the products and services offered by “your mobile phone provider” how would you rate the fees and prices that you pay for them?}
#' \item{PERV2}{Given the fees and prices that you pay for “your mobile phone provider” how would you rate the quality of the products and services offered by “your mobile phone provider”?}
#' }
#'
#' @details The data frame mobi contains the observed data for the model specified by ECSImobi.
#' @references Tenenhaus, M., V. E. Vinzi, Y.-M. Chatelin, and C. Lauro (2005) PLS path modeling. Computational Statistics & Data Analysis 48, 159-205.
#' @examples data("mobi")
#'
"mobi"
286 changes: 143 additions & 143 deletions R/interactions.R
Original file line number Diff line number Diff line change
@@ -1,143 +1,143 @@
#' Interaction Functions
#'
#' \code{interactions} creates interaction measurement items by multipying all combination of factor items.
#'
#' This function automatically generates interaction measurement items for a PLS SEM.
#'
#' @param ... Interaction Combinations as generated by the \code{interaction_scaled} or
#' \code{interaction_ortho} methods.
#'
#' @usage
#' # Create two new interactions (factor1.factor2 and factor1.factor3) using
#'
#' # (1) standardized product indicator approach as per Henseler & Chin (2010):
#' interactions( interaction_scaled("factor1", "factor2"),
#' interaction_scaled("factor1", "factor3"))
#'
#' # (2) orthogonalization approach as per Henseler & CHin (2010):
#' interactions( interaction_ortho("factor1", "factor2"),
#' interaction_ortho("factor1", "factor3"))
#'
#' @examples
#' data("mobi", package = "semPLS")
#'
#' mobi_xm <- interactions(
#' interaction_ortho("Image", "Expectation"),
#' interaction_ortho("Image", "Value")
#' )
#'
#' mobi_pls <- estimate_pls(mobi, mobi_mm, mobi_xm, mobi_sm)
#' print_paths(mobi_pls)
#'
#' @aliases interaction_ortho, interaction_scaled
#'
#' @export
interactions <- function(...) {
function(data, mm, all_intxns=list(...)) {
create_interaction <- function(intxn_function) { intxn_function(data, mm) }
intxns_list <- lapply(all_intxns, create_interaction)
return(intxns_list)
}
}

#' \code{interaction_ortho} creates interaction measurement items by multipying all combination of factor items.
#'
#' This function automatically generates interaction measurement items for a PLS SEM.
#'
#' @param ... Interaction Combinations as generated by the \code{interaction_ortho} method.
#'
#' @usage
#' # Create two new interactions (factor1.factor2 and factor1.factor3) using
#'
#' # orthogonalization approach as per Henseler & CHin (2010):
#' interactions( interaction_ortho("factor1", "factor2"),
#' interaction_ortho("factor1", "factor3"))
#'
#' @examples
#' data("mobi", package = "semPLS")
#'
#' mobi_xm <- interactions(
#' interaction_ortho("Image", "Expectation"),
#' interaction_ortho("Image", "Value")
#' )
#'
#' mobi_pls <- estimate_pls(mobi, mobi_mm, mobi_xm, mobi_sm)
#' print_paths(mobi_pls)
#'
#' @aliases interaction_ortho, interaction_scaled
#'
#' @export
interaction_ortho <- function(factor1, factor2) {
function(data, mm) {
interaction_name <- paste(factor1, factor2, sep=".")
iv1_items <- mm[mm[, "latent"] == factor1, ][, "measurement"]
iv2_items <- mm[mm[, "latent"] == factor2, ][, "measurement"]

iv1_data <- as.data.frame(scale(data[iv1_items]))
iv2_data <- as.data.frame(scale(data[iv2_items]))

mult <- function(col) {
iv2_data*col
}

multiples_list <- lapply(iv1_data, mult)
interaction_data <- do.call("cbind", multiples_list)

# Create formula
frmla <- as.formula(paste("interaction_data[,i]",paste(as.vector(c(iv1_items,iv2_items)), collapse ="+"), sep = " ~ "))

# iterate and orthogonalize
for(i in 1:ncol(interaction_data)) {
interaction_data[,i] <- lm(formula = frmla, data = data)$residuals
}
return(list(name = interaction_name, data = interaction_data))
}
}

#' \code{interaction_scaled} creates interaction measurement items by multipying all combination of factor items.
#'
#' This function automatically generates interaction measurement items for a PLS SEM.
#'
#' @param ... Interaction Combinations as generated by the \code{interaction_scaled} method.
#'
#' @usage
#' # Create two new interactions (factor1.factor2 and factor1.factor3) using
#'
#' # standardized product indicator approach as per Henseler & Chin (2010):
#' interactions( interaction_scaled("factor1", "factor2"),
#' interaction_scaled("factor1", "factor3"))
#'
#' @examples
#' data("mobi", package = "semPLS")
#'
#' mobi_xm <- interactions(
#' interaction_scaled("Image", "Expectation"),
#' interaction_scaled("Image", "Value")
#' )
#'
#' mobi_pls <- estimate_pls(mobi, mobi_mm, mobi_xm, mobi_sm)
#' print_paths(mobi_pls)
#'
#' @aliases interaction_ortho, interaction_scaled
#'
#' @export
interaction_scaled <- function(factor1, factor2) {
function(data, mm) {
interaction_name <- paste(factor1, factor2, sep=".")
iv1_items <- mm[mm[, "latent"] == factor1, ][, "measurement"]
iv2_items <- mm[mm[, "latent"] == factor2, ][, "measurement"]

iv1_data <- as.data.frame(scale(data[iv1_items]))
iv2_data <- as.data.frame(scale(data[iv2_items]))

mult <- function(col) {
iv2_data*col
}

multiples_list <- lapply(iv1_data, mult)
interaction_data <- do.call("cbind", multiples_list)

return(list(name = interaction_name, data = interaction_data))
}
}

#' Interaction Functions
#'
#' \code{interactions} creates interaction measurement items by multipying all combination of factor items.
#'
#' This function automatically generates interaction measurement items for a PLS SEM.
#'
#' @param ... Interaction Combinations as generated by the \code{interaction_scaled} or
#' \code{interaction_ortho} methods.
#'
#' @usage
#' # Create two new interactions (factor1.factor2 and factor1.factor3) using
#'
#' # (1) standardized product indicator approach as per Henseler & Chin (2010):
#' interactions( interaction_scaled("factor1", "factor2"),
#' interaction_scaled("factor1", "factor3"))
#'
#' # (2) orthogonalization approach as per Henseler & CHin (2010):
#' interactions( interaction_ortho("factor1", "factor2"),
#' interaction_ortho("factor1", "factor3"))
#'
#' @examples
#' mobi <- mobi
#'
#' mobi_xm <- interactions(
#' interaction_ortho("Image", "Expectation"),
#' interaction_ortho("Image", "Value")
#' )
#'
#' mobi_pls <- estimate_pls(mobi, mobi_mm, mobi_xm, mobi_sm)
#' print_paths(mobi_pls)
#'
#' @aliases interaction_ortho, interaction_scaled
#'
#' @export
interactions <- function(...) {
function(data, mm, all_intxns=list(...)) {
create_interaction <- function(intxn_function) { intxn_function(data, mm) }
intxns_list <- lapply(all_intxns, create_interaction)
return(intxns_list)
}
}

#' \code{interaction_ortho} creates interaction measurement items by multipying all combination of factor items.
#'
#' This function automatically generates interaction measurement items for a PLS SEM.
#'
#' @param ... Interaction Combinations as generated by the \code{interaction_ortho} method.
#'
#' @usage
#' # Create two new interactions (factor1.factor2 and factor1.factor3) using
#'
#' # orthogonalization approach as per Henseler & CHin (2010):
#' interactions( interaction_ortho("factor1", "factor2"),
#' interaction_ortho("factor1", "factor3"))
#'
#' @examples
#' mobi <- mobi
#'
#' mobi_xm <- interactions(
#' interaction_ortho("Image", "Expectation"),
#' interaction_ortho("Image", "Value")
#' )
#'
#' mobi_pls <- estimate_pls(mobi, mobi_mm, mobi_xm, mobi_sm)
#' print_paths(mobi_pls)
#'
#' @aliases interaction_ortho, interaction_scaled
#'
#' @export
interaction_ortho <- function(factor1, factor2) {
function(data, mm) {
interaction_name <- paste(factor1, factor2, sep=".")
iv1_items <- mm[mm[, "latent"] == factor1, ][, "measurement"]
iv2_items <- mm[mm[, "latent"] == factor2, ][, "measurement"]

iv1_data <- as.data.frame(scale(data[iv1_items]))
iv2_data <- as.data.frame(scale(data[iv2_items]))

mult <- function(col) {
iv2_data*col
}

multiples_list <- lapply(iv1_data, mult)
interaction_data <- do.call("cbind", multiples_list)

# Create formula
frmla <- as.formula(paste("interaction_data[,i]",paste(as.vector(c(iv1_items,iv2_items)), collapse ="+"), sep = " ~ "))

# iterate and orthogonalize
for(i in 1:ncol(interaction_data)) {
interaction_data[,i] <- lm(formula = frmla, data = data)$residuals
}
return(list(name = interaction_name, data = interaction_data))
}
}

#' \code{interaction_scaled} creates interaction measurement items by multipying all combination of factor items.
#'
#' This function automatically generates interaction measurement items for a PLS SEM.
#'
#' @param ... Interaction Combinations as generated by the \code{interaction_scaled} method.
#'
#' @usage
#' # Create two new interactions (factor1.factor2 and factor1.factor3) using
#'
#' # standardized product indicator approach as per Henseler & Chin (2010):
#' interactions( interaction_scaled("factor1", "factor2"),
#' interaction_scaled("factor1", "factor3"))
#'
#' @examples
#' mobi <- mobi
#'
#' mobi_xm <- interactions(
#' interaction_scaled("Image", "Expectation"),
#' interaction_scaled("Image", "Value")
#' )
#'
#' mobi_pls <- estimate_pls(mobi, mobi_mm, mobi_xm, mobi_sm)
#' print_paths(mobi_pls)
#'
#' @aliases interaction_ortho, interaction_scaled
#'
#' @export
interaction_scaled <- function(factor1, factor2) {
function(data, mm) {
interaction_name <- paste(factor1, factor2, sep=".")
iv1_items <- mm[mm[, "latent"] == factor1, ][, "measurement"]
iv2_items <- mm[mm[, "latent"] == factor2, ][, "measurement"]

iv1_data <- as.data.frame(scale(data[iv1_items]))
iv2_data <- as.data.frame(scale(data[iv2_items]))

mult <- function(col) {
iv2_data*col
}

multiples_list <- lapply(iv1_data, mult)
interaction_data <- do.call("cbind", multiples_list)

return(list(name = interaction_name, data = interaction_data))
}
}

2 changes: 1 addition & 1 deletion R/model.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#' \code{\link{bootstrap_model}}
#'
#' @examples
#' data("mobi", package = "semPLS")
#' mobi <- mobi
#'
#' #seminr syntax for creating measurement model
#' mobi_mm <- constructs(
Expand Down
2 changes: 1 addition & 1 deletion R/reliability.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#' \code{\link{bootstrap_model}}
#'
#' @examples
#' data("mobi", package = "semPLS")
#' mobi <- mobi
#'
#' #seminr syntax for creating measurement model
#' mobi_mm <- constructs(
Expand Down
2 changes: 1 addition & 1 deletion R/reporting.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#' plot_scores(fitted_model, factors=NULL)
#'
#' @examples
#' data("mobi", package = "semPLS")
#' mobi <- mobi
#' mobi_pls <- estimate_pls(data = mobi,
#' measurement_model = mobi_mm,
#' structural_model = mobi_sm)
Expand Down
2 changes: 1 addition & 1 deletion R/simplePLS.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#' \code{\link{estimate_pls}} \code{\link{bootstrap_model}}
#'
#' @examples
#' data("mobi", package = "semPLS")
#' mobi <- mobi
#'
#' #seminr syntax for creating measurement model
#' mobi_mm <- constructs(
Expand Down
Binary file added data/mobi.rda
Binary file not shown.
Loading

0 comments on commit 3f8ef66

Please sign in to comment.