Package 'SurveyDefense'

Title: Survey Defense Tool
Description: This tool is designed to analyze up to 5 Fraud Detection Questions integrated into a survey, focusing on potential fraudulent participants to clean the survey dataset from potential fraud. Fraud Detection Questions and further information available at <https://surveydefense.org>.
Authors: Philipp Brüggemann [aut, cre]
Maintainer: Philipp Brüggemann <[email protected]>
License: GPL-3
Version: 0.2.0
Built: 2024-12-11 07:19:44 UTC
Source: CRAN

Help Index


Fraud Detection Analysis Tool 1

Description

This function analyzes survey data based on up to 5 Fraud Detection Questions and generates results in Word and HTML formats.

Usage

FraudDetec1(
  output_dir,
  data,
  FraudList,
  correct_answers = c(0, 0, 0, 0, 0),
  ...
)

Arguments

output_dir

Path specifying where the Word and HTML files will be saved.

data

The data frame containing all the survey data.

FraudList

A character vector of up to 5 Fraud Detection Questions.

correct_answers

A numeric vector representing correct answers for each question. Default is c(0, 0, 0, 0, 0).

...

Survey questions to be analyzed.

Value

A flextable object with the fraud detection analysis results. The results include summary statistics and metrics comparing responses from reliable and fraudulent participants.

Examples

if (requireNamespace("flextable", quietly = TRUE) && requireNamespace("officer", quietly = TRUE)) {
  library(flextable)
  library(officer)

  # Example data for fraud detection analysis
  Q1 <- c(4, 5, 3, 2, 5, 2)
  Q2 <- c(3, 4, 2, 5, 4, 3)
  Q3 <- c(5, 4, 3, 5, 4, 5)
  Q4 <- c(1, 2, 3, 4, 5, 2)
  Q5 <- c(5, 2, 2, 1, 4, 1)
  Q6 <- c(5, 2, 3, 5, 1, 2)
  Q7 <- c(5, 2, 4, 5, 3, 4)

  Fraud1 <- c(0, 1, 0, 0, 0, 0)
  Fraud2 <- c(0, 0, 0, 0, 0, 0)
  Fraud3 <- c(0, 1, 0, 0, 0, 0)
  Fraud4 <- c(0, 0, 1, 0, 0, 1)
  Fraud5 <- c(0, 0, 0, 1, 1, 1)

  Test_Data_Fraud <- data.frame(Q1, Q2, Q3, Q4, Q5, Q6, Q7, Fraud1, Fraud2, Fraud3, Fraud4, Fraud5)

  temp_dir <- tempdir()

  FraudDetec1(
    output_dir = temp_dir,
    data = Test_Data_Fraud,
    FraudList = c("Fraud1", "Fraud2", "Fraud3", "Fraud4", "Fraud5"),
    correct_answers = c(0, 0, 0, 0, 0),
    Q1, Q2, Q3, Q4, Q5, Q6, Q7
  )
}

Fraud Detection Analysis Tool 2

Description

This function analyzes survey data using up to 5 Fraud Detection Questions and generates a report in Word and HTML formats.

Usage

FraudDetec2(
  output_dir,
  data,
  FraudList,
  correct_answers = c(0, 0, 0, 0, 0),
  ...
)

Arguments

output_dir

Path specifying where the Word and HTML files will be saved.

data

The data frame containing all the survey data.

FraudList

A character vector of up to 5 Fraud Detection Questions.

correct_answers

A numeric vector representing correct answers for each question. Default is c(0, 0, 0, 0, 0).

...

Survey questions to be analyzed.

Value

A flextable object with the fraud detection analysis results, including summary statistics for the overall sample and identified fraudulent responses.

Examples

if (requireNamespace("flextable", quietly = TRUE) && requireNamespace("officer", quietly = TRUE)) {
  library(flextable)
  library(officer)

  # Example data for fraud detection analysis
  Q1 <- c(4, 5, 3, 2, 5, 2)
  Q2 <- c(3, 4, 2, 5, 4, 3)
  Q3 <- c(5, 4, 3, 5, 4, 5)
  Q4 <- c(1, 2, 3, 4, 5, 2)
  Q5 <- c(5, 2, 2, 1, 4, 1)
  Q6 <- c(5, 2, 3, 5, 1, 2)
  Q7 <- c(5, 2, 4, 5, 3, 4)

  Fraud1 <- c(0, 1, 0, 0, 0, 0)
  Fraud2 <- c(0, 0, 0, 0, 0, 0)
  Fraud3 <- c(0, 1, 0, 0, 0, 0)
  Fraud4 <- c(0, 0, 1, 0, 0, 1)
  Fraud5 <- c(0, 0, 0, 1, 1, 1)

  Test_Data_Fraud <- data.frame(Q1, Q2, Q3, Q4, Q5, Q6, Q7, Fraud1, Fraud2, Fraud3, Fraud4, Fraud5)

  temp_dir <- tempdir()

  FraudDetec2(
    output_dir = temp_dir,
    data = Test_Data_Fraud,
    FraudList = c("Fraud1", "Fraud2", "Fraud3", "Fraud4", "Fraud5"),
    correct_answers = c(0, 0, 0, 0, 0),
    Q1, Q2, Q3, Q4, Q5, Q6, Q7
  )
}

Fraud Detection Analysis Tool 3

Description

Fraud Detection Analysis Tool 3

Usage

FraudDetec3(
  output_dir,
  data,
  FraudList,
  correct_answers = c(0, 0, 0, 0, 0),
  ...
)

Arguments

output_dir

Path specifying where the Word and HTML files will be saved.

data

The data frame containing all the survey data.

FraudList

A character vector of up to 5 Fraud Detection Questions.

correct_answers

A numeric vector representing correct answers for each question. Default is c(0, 0, 0, 0, 0).

...

Survey questions to be analyzed.

Value

A flextable object with the results.

Examples

if (requireNamespace("flextable", quietly = TRUE) && requireNamespace("officer", quietly = TRUE)) {
  library(flextable)
  library(officer)

  # Example data for fraud detection analysis
  Q1 <- c(4, 5, 3, 2, 5, 2)
  Q2 <- c(3, 4, 2, 5, 4, 3)
  Q3 <- c(5, 4, 3, 5, 4, 5)
  Q4 <- c(1, 2, 3, 4, 5, 2)
  Q5 <- c(5, 2, 2, 1, 4, 1)
  Q6 <- c(5, 2, 3, 5, 1, 2)
  Q7 <- c(5, 2, 4, 5, 3, 4)

  Fraud1 <- c(0, 1, 0, 0, 0, 0)
  Fraud2 <- c(0, 0, 0, 0, 0, 0)
  Fraud3 <- c(0, 1, 0, 0, 0, 0)
  Fraud4 <- c(0, 0, 1, 0, 0, 1)
  Fraud5 <- c(0, 0, 0, 1, 1, 1)

  Test_Data_Fraud <- data.frame(Q1, Q2, Q3, Q4, Q5, Q6, Q7, Fraud1, Fraud2, Fraud3, Fraud4, Fraud5)

  temp_dir <- tempdir()

  FraudDetec3(
    output_dir = temp_dir,
    data = Test_Data_Fraud,
    FraudList = c("Fraud1", "Fraud2", "Fraud3", "Fraud4", "Fraud5"),
    correct_answers = c(0, 0, 0, 0, 0),
    Q1, Q2, Q3, Q4, Q5, Q6, Q7
  )
}

Fraud Detection Analysis Tool 4

Description

Fraud Detection Analysis Tool 4

Usage

FraudDetec4(
  output_dir,
  data,
  FraudList,
  correct_answers = c(0, 0, 0, 0, 0),
  ...
)

Arguments

output_dir

Path specifying where the Word and HTML files will be saved.

data

The data frame containing all the survey data.

FraudList

A character vector of up to 5 Fraud Detection Questions.

correct_answers

A numeric vector representing correct answers for each question. Default is c(0, 0, 0, 0, 0).

...

Survey questions to be analyzed.

Value

A flextable object with the results.

Examples

if (requireNamespace("flextable", quietly = TRUE) && requireNamespace("officer", quietly = TRUE)) {
  library(flextable)
  library(officer)

  # Example data for fraud detection analysis
  Q1 <- c(4, 5, 3, 2, 5, 2)
  Q2 <- c(3, 4, 2, 5, 4, 3)
  Q3 <- c(5, 4, 3, 5, 4, 5)
  Q4 <- c(1, 2, 3, 4, 5, 2)
  Q5 <- c(5, 2, 2, 1, 4, 1)
  Q6 <- c(5, 2, 3, 5, 1, 2)
  Q7 <- c(5, 2, 4, 5, 3, 4)

  Fraud1 <- c(0, 1, 0, 0, 0, 0)
  Fraud2 <- c(0, 0, 0, 0, 0, 0)
  Fraud3 <- c(0, 1, 0, 0, 0, 0)
  Fraud4 <- c(0, 0, 1, 0, 0, 1)
  Fraud5 <- c(0, 0, 0, 1, 1, 1)

  Test_Data_Fraud <- data.frame(Q1, Q2, Q3, Q4, Q5, Q6, Q7, Fraud1, Fraud2, Fraud3, Fraud4, Fraud5)

  temp_dir <- tempdir()

  FraudDetec4(
    output_dir = temp_dir,
    data = Test_Data_Fraud,
    FraudList = c("Fraud1", "Fraud2", "Fraud3", "Fraud4", "Fraud5"),
    correct_answers = c(0, 0, 0, 0, 0),
    Q1, Q2, Q3, Q4, Q5, Q6, Q7
  )
}

Fraud Detection Analysis Tool 5

Description

Fraud Detection Analysis Tool 5

Usage

FraudDetec5(
  output_dir,
  data,
  FraudList,
  correct_answers = c(0, 0, 0, 0, 0),
  ...
)

Arguments

output_dir

Path specifying where the Word and HTML files will be saved.

data

The data frame containing all the survey data.

FraudList

A character vector of up to 5 Fraud Detection Questions.

correct_answers

A numeric vector representing correct answers for each question. Default is c(0, 0, 0, 0, 0).

...

Survey questions to be analyzed.

Value

A flextable object with the results.

Examples

if (requireNamespace("flextable", quietly = TRUE) && requireNamespace("officer", quietly = TRUE)) {
  library(flextable)
  library(officer)

  # Example data for fraud detection analysis
  Q1 <- c(4, 5, 3, 2, 5, 2)
  Q2 <- c(3, 4, 2, 5, 4, 3)
  Q3 <- c(5, 4, 3, 5, 4, 5)
  Q4 <- c(1, 2, 3, 4, 5, 2)
  Q5 <- c(5, 2, 2, 1, 4, 1)
  Q6 <- c(5, 2, 3, 5, 1, 2)
  Q7 <- c(5, 2, 4, 5, 3, 4)

  Fraud1 <- c(0, 1, 0, 0, 0, 0)
  Fraud2 <- c(0, 0, 0, 0, 0, 0)
  Fraud3 <- c(0, 1, 0, 0, 0, 0)
  Fraud4 <- c(0, 0, 1, 0, 0, 1)
  Fraud5 <- c(0, 0, 0, 1, 1, 1)

  Test_Data_Fraud <- data.frame(Q1, Q2, Q3, Q4, Q5, Q6, Q7, Fraud1, Fraud2, Fraud3, Fraud4, Fraud5)

  temp_dir <- tempdir()

  FraudDetec5(
    output_dir = temp_dir,
    data = Test_Data_Fraud,
    FraudList = c("Fraud1", "Fraud2", "Fraud3", "Fraud4", "Fraud5"),
    correct_answers = c(0, 0, 0, 0, 0),
    Q1, Q2, Q3, Q4, Q5, Q6, Q7
  )
}