R/getcodes.R

Defines functions getcodes

Documented in getcodes

#' Get Analysis Hub Codes
#'
#' Copy the code after ## Not Run in the Examples below and paste it into a new R Script and save the file as AnalysisHub.R
#' You can then use this R script to run all of your analyses for this course.
#' 
#' @export
#' 
#' @examples
#' \dontrun{
#' getcodes()
#' }
getcodes = function(){
  
clear_console()

cat("######################################################\n")
cat("#                   Analysis Hub                     #\n")
cat("######################################################\n")
cat("# R Codes for Marketing Analytics                    #\n")
cat("# Author: Michael Diore, PhD                        #\n")
cat("# Copyright 2023, Michael Diore All rights reserved.#\n")
cat("# The listentodata R package and this accompanying   #\n")
cat("# R Script are provided to the students at the       #\n")
cat("# University of New Hampshire on an 'AS IS' BASIS,   #\n")
cat("# WITH ABSOLUTELY NO WARRANTIES either expressed or  #\n")
cat("# implied. The package and this script may not be    #\n")
cat("# redistributed in whole or part without the express #\n")
cat("# written permission of the author.                  #\n")
cat("#                    ------------                    #\n")
cat("# This script can run the analyses without error     #\n")
cat("# ONLY IF the required data has been prepared as     #\n")
cat("# instructed in your marketing analytics course.     #\n")
cat("######################################################\n")
cat("\n")
cat("\n")
cat("\n")
cat("\n")
cat("#****************************************************\n")
cat("#--      1. Segmentation and Targeting            --\n")
cat("#**************************************************** \n")
cat("\n")
cat("# You need to have one CSV data file for your segmentation\n")
cat("# data and a second CSV file for your targeting data.\n")
cat("# Make sure you select the right file by paying attention\n")
cat("# to the variable name the load_csv_data() is being \n")
cat("# assigned to.\n")
cat("# The next few lines prepare and run the analysis. \n")
cat("library(listentodata)\n")
cat("# Run the next line to get function details in the Help panel\n")
cat("?Run_SegmentTarget\n")
cat("clear_console()\n")
cat("segmentation_data = load_csv_data()\n")
cat("targeting_data = load_csv_data()\n")
cat("segments = 3\n")
cat("resizepaper = 1\n")
cat("Run_SegmentTarget(segmentation_data,targeting_data,segments, resizepaper)\n")
cat("\n")
cat("print('Cursor Catcher; No need to run this line!')\n")
cat("\n")
cat("\n")
cat("\n")
cat("\n")
cat("\n")
cat("\n")
cat("\n")
cat("#****************************************************\n")
cat("#--                2. RFM Analysis                --\n")
cat("#**************************************************** \n")
cat("\n")
cat("# You need to have a CSV data file that includes \n")
cat("# three columns called Recency, Frequency, and Monetary\n")
cat("# respectively containing numeric values for R, F, and M.\n")
cat("# The next few lines prepare and run the analysis. \n")
cat("library(listentodata)\n")
cat("# Run the next line to get function details in the Help panel\n")
cat("?Run_RFM_Analysis\n")
cat("clear_console()\n")
cat("df = load_csv_data()\n")
cat("Run_RFM_Analysis(df)\n")
cat("\n")
cat("print('Cursor Catcher; No need to run this line!')\n")
cat("\n")
cat("\n")
cat("\n")
cat("\n")
cat("\n")
cat("\n")
cat("\n")
cat("#****************************************************\n")
cat("#--            3. Positioning Analysis            --\n")
cat("#**************************************************** \n")
cat("\n")
cat("# You need to have one CSV data file for your perceptions\n")
cat("# data and a second CSV file for your preferences data.\n")
cat("# Make sure you select the right file by paying attention\n")
cat("# to the variable name the load_csv_data() is being\n")
cat("# assigned to.\n")
cat("# The next few lines prepare and run the analysis. \n")
cat("library(listentodata)\n")
cat("# Run the next line to get function details in the Help panel\n")
cat("?Run_Positioning_Analysis\n")
cat("clear_console()\n")
cat("perceptions_data = load_csv_data()\n")
cat("preferences_data = load_csv_data()\n")
cat("resizepaper = 1.2\n")
cat("Run_Positioning_Analysis(perceptions_data,preferences_data, resizepaper)\n")
cat("\n")
cat("print('Cursor Catcher; No need to run this line!')\n")
cat("\n")
cat("\n")
cat("\n")
cat("\n")
cat("\n")
cat("\n")
cat("\n")
cat("#****************************************************\n")
cat("#--              4. CLV Analysis                  --\n")
cat("#**************************************************** \n")
cat("\n")
cat("# You need to have one CSV data file for your profit\n")
cat("# groups data and a second CSV file for your transition\n")
cat("# matrix data.\n")
cat("# Make sure you select the right file by paying attention\n")
cat("# to the variable name the load_csv_data() is being \n")
cat("# assigned to.\n")
cat("# The next few lines prepare and run the analysis. \n")
cat("library(listentodata)\n")
cat("# Run the next line to get function details in the Help panel\n")
cat("?Run_CLV_Analysis\n")
cat("clear_console()\n")
cat("profitgroups_data = load_csv_data()\n")
cat("transitionmatrix_data = load_csv_data()\n")
cat("discount_rate = 0.15\n")
cat("new_customers = 0\n")
cat("more_customers = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0)\n")
cat("resizepaper = 1.2\n")
cat("Run_CLV_Analysis(profitgroups_data,\n")
cat("                 transitionmatrix_data,\n")
cat("                 discount_rate,\n")
cat("                 new_customers,\n")
cat("                 more_customers,\n")
cat("                 resizepaper)\n")
cat("\n")
cat("print('Cursor Catcher; No need to run this line!')\n")
cat("\n")
cat("\n")
cat("\n")
cat("\n")
cat("\n")
cat("\n")
cat("\n")
cat("#****************************************************\n")
cat("#--            5. Optimal Pricing                 --\n")
cat("#**************************************************** \n")
cat("\n")
cat("# You need to have one CSV data file for your pricing\n")
cat("# survey data. You also need to specify the tested prices\n")
cat("# in the prices vector. Unless you need to, do not \n")
cat("# change the values of the three remaining parameters.\n")
cat("# The next few lines prepare and run the analysis. \n")
cat("library(listentodata)\n")
cat("# Run the next line to get function details in the Help panel\n")
cat("?Run_Optimal_Pricing\n")
cat("survey_data = load_csv_data()\n")
cat("prices = c(1.99,3.99,7.99,10.99,15.99,21.99,26.99)\n")
cat("probabilities = c(0, 0, 0, 0.2, 0.5)\n")
cat("marketsize = 10000\n")
cat("resizepaper = 1.2\n")
cat("Run_Optimal_Pricing(survey_data,\n")
cat("                    prices,\n")
cat("                    probabilities,\n")
cat("                    marketsize,\n")
cat("                    resizepaper)\n")
cat("\n")
cat("\n")
cat("print('Cursor Catcher; No need to run this line!')\n")
cat("\n")
cat("\n")
cat("\n")
cat("\n")
cat("\n")
cat("\n")
cat("\n")
cat("#****************************************************\n")
cat("#--         6. Regression Analysis                --\n")
cat("#**************************************************** \n")
cat("\n")
cat("# You need to have one CSV data file for your regression\n")
cat("# data. You also need to specify the formula in myformula.\n")
cat("# The next few lines prepare and run the analysis. \n")
cat("library(listentodata)\n")
cat("# Run the next line to get function details in the Help panel\n")
cat("?Run_Regression\n")
cat("clear_console()\n")
cat("mydata = load_csv_data()\n")
cat("head(mydata) #shows top rows in the Console\n")
cat("str(mydata) #shows structure of the data\n")
cat("myformula = 'Sales ~ .'\n")
cat("resizepaper = 1\n")
cat("Run_Regression(mydata, myformula, resizepaper)\n")
cat("# If you have data for prediction:\n")
cat("prediction_data = load_csv_data()\n")
cat("Run_Regression(mydata, myformula, prediction_data, resizepaper)\n")
cat("\n")
cat("print('Cursor Catcher; No need to run this line!')\n")
cat("\n")
cat("\n")
cat("\n")
cat("\n")
cat("\n")
cat("\n")
cat("\n")
cat("#****************************************************\n")
cat("#--       7. Logistic Regression Analysis         --\n")
cat("#**************************************************** \n")
cat("\n")
cat("# You need to have one CSV data file for your logistic\n")
cat("# regression data.\n")
cat("# You also need to specify the formula in myformula.\n")
cat("# The next few lines prepare and run the analysis. \n")
cat("library(listentodata)\n")
cat("# Run the next line to get function details in the Help panel\n")
cat("?Run_Logistic\n")
cat("clear_console()\n")
cat("mydata = load_csv_data()\n")
cat("head(mydata)\n")
cat("str(mydata)\n")
cat("myformula = 'visited ~ .'\n")
cat("resizepaper = 1\n")
cat("Run_Logistic(mydata, myformula, resizepaper)\n")
cat("# If you have data for prediction:\n")
cat("prediction_data = load_csv_data()\n")
cat("Run_Logistic(mydata, myformula, prediction_data, resizepaper)\n")
cat("\n")
cat("print('Cursor Catcher; No need to run this line!')\n")
cat("\n")
cat("\n")
cat("\n")
cat("\n")
cat("\n")
cat("\n")
cat("\n")
cat("#****************************************************\n")
cat("#--         8. Sentiment Analysis                   --\n")
cat("#**************************************************** \n")
cat("\n")
cat("# You need to have one csv file containing one columne of text.\n")
cat("# Each cell in this column will be a tweet, review, or document... (No column names/headers)\n")
cat("# The next few lines prepare and run the analysis. \n")
cat("library(listentodata)\n")
cat("# Run the next line to get function details in the Help panel\n")
cat("?Run_Sentiment_Analysis\n")
cat("clear_console()\n")
cat("mydata = load_csv_data()\n")
cat("words2remove = c(\"toremvoe1\", \"toremove2\")\n")
cat("stemthis = FALSE\n")
cat("wcmf = 5 #Word Cloud Minimum Frequency: default = 5\n")
cat("mostfrequent = 25\n")
cat("Run_Sentiment_Analysis(mydata, words2remove, stemthis, wcmf, mostfrequent)\n")
cat("\n")
cat("print('Cursor Catcher; No need to run this line!')\n")
cat("\n")
cat("\n")
cat("\n")
cat("\n")
cat("\n")
cat("\n")
cat("\n")
cat("#****************************************************\n")
cat("#--         9. Conjoint Study Design              --\n")
cat("#**************************************************** \n")
cat("\n")
cat("# You only need to specify the design parameters and \n")
cat("# their attributes here. The profiles design will be\n")
cat("# displayed in the Console and also saved in a csv \n")
cat("# file in the folder you will select.\n")
cat("# The next few lines prepare and run the analysis. \n")
cat("library(listentodata)\n")
cat("# Run the next line to get function details in the Help panel\n")
cat("?Run_Conjoint_Study_Design\n")
cat("clear_console()\n")
cat("designparameters = list(\n")
cat("    NameOfAttribute1 = c('$100','$200','$300','500'),\n")
cat("    NameOfAttribute2 = c('A','B','C','D','E'),\n")
cat("    NameOfAttribute3 = c('Low','Medium','High'),\n")
cat("    NameOfAttribute4 = c('Yes','No'),\n")
cat("    NameOfAttribute5 = c('option1', 'option2', 'option3', 'option4'),\n")
cat("    NameOfAttribute6 = c('option11', 'option22', 'option33', 'option44')\n")
cat("  \n")
cat(")\n")
cat("select_folder() #to select the folder where results will be saved.\n") 
cat("Run_Conjoint_Study_Design(designparameters)  \n")
cat("\n")
cat("print('Cursor Catcher; No need to run this line!')\n")
cat("\n")
cat("\n")
cat("\n")
cat("\n")
cat("\n")
cat("\n")
cat("\n")
cat("#****************************************************\n")
cat("#--            10.  Conjoint Analysis              --\n")
cat("#**************************************************** \n")
cat("\n")
cat("# This analysis requires multiple data files. \n")
cat("# You also need to specify the formula in myformula.\n")
cat("# The next few lines allow you to analyze the provided\n")
cat("# tablet design data.\n")
cat("\n")
cat("library(listentodata)\n")
cat("# Run the next line to get function details in the Help panel\n")
cat("?Run_Conjoint_Analysis\n")
cat("clear_console()\n")
cat("select_folder()  #Select the folder where your data files are\n")
cat("design = read.csv('Tablet_levels_attributes.csv', na.strings=c('','NA')) #design table\n")
cat("products = read.csv('Tablet_survey_products.csv')    # READ PRODUCT PROFILES DATA\n")
cat("ratings =  read.csv('Tablet_survey_ratings.csv')    # READ RATINGS DATA\n")
cat("alternatives = read.csv('Tablet_New_Product_Alternatives.csv') # Load New product alternative\n")
cat("competitors = read.csv('Tablet_competitors.csv')  # Load competitors products\n")
cat("resizepaper = 1\n")
cat("Run_Conjoint_Analysis(design,\n")
cat("                      products,\n")
cat("                      ratings,\n")
cat("                      alternatives,\n")
cat("                      competitors,\n")
cat("                      resizepaper)\n")
cat("\n")
cat("\n")
cat("print('Cursor Catcher; No need to run this line!')\n")
cat("\n")
cat("\n")
cat("# To analyze data sets from other projects, you can\n")
cat("# run the next lines that allow you to load your data sets.\n")
cat("\n")
cat("library(listentodata)\n")
cat("clear_console()\n")
cat("design = load_csv_data()\n")
cat("products = load_csv_data()\n")
cat("ratings =  load_csv_data()\n")
cat("alternatives = load_csv_data()\n")
cat("competitors = load_csv_data()\n")
cat("resizepaper = 1\n")
cat("Run_Conjoint_Analysis(design,\n")
cat("                      products,\n")
cat("                      ratings,\n")
cat("                      alternatives,\n")
cat("                      competitors,\n")
cat("                      resizepaper)\n")
cat("\n")
cat("\n")
cat("print('Cursor Catcher; No need to run this line!')\n")
cat("\n")
cat("\n")
cat("# =================================\n")
cat("#     Copy and save this code!   \n")
cat("# =================================\n")

  
}
1moein/listentodata documentation built on Nov. 14, 2024, 5:35 p.m.