Title: | Performs Segmented Linear Regression on Two Independent Variables |
---|---|
Description: | Implements a specific form of segmented linear regression with two independent variables. The visualization of that function looks like a quarter segment of a cowbell giving the package its name. The package has been specifically constructed for the case where minimum and maximum value of the dependent and two independent variables are known a prior, which is usually the case when those values are derived from Likert scales. |
Authors: | Christoph Luerig [aut, cre] |
Maintainer: | Christoph Luerig <[email protected]> |
License: | GPL-3 |
Version: | 0.1.0 |
Built: | 2024-11-28 06:35:03 UTC |
Source: | CRAN |
Data set of two games containing measurements of Fluency, Absorption, Fit (= Perceived difficulty) and Fun. Fluency and Absorption are measured on a scale from 1..7, Fun and Fit are measured 1..9.
The application case for which this package has been constructed for is the response analysis
of one dependend variable that depends on two independend variable. Additionally a prior information is
given on the minimal and maximal values of those three variables. This is the case if those variables originate
from questions using Likert scales.
This information is indicated upfront with the function generateCowbellConcept
.
The response surface resembles a quarter segment of a cowbell. It starts with a certain value at the
dependend variable if any of the independent variables are at their minimal value. If both independent variables
have reached their breakpoint value a new value with a plateau will be returned. Going to the plateau a rising linear
ridge is used. Where to both sides of the ridge there is only a linear dependency on one of the independent variables.
In general this model may be worth trying if one assumes that
there is a point of saturation for both independent variables and that up this point essentially the smaller one of both values
is determining the result on the dependend variable.
This is computed in a second step with the help of the
function generateCowbell
.
fitted
generic.Implementation of the fitted
generic.
## S3 method for class 'cowbell' fitted(object, ...)
## S3 method for class 'cowbell' fitted(object, ...)
object |
The data obtained by function |
... |
Just for compatibility purposes. |
List with predicted values
# Run a simplified anaylsis with 10 iterations only (to save time.) concept<-generateCowbellConcept(Fun ~ Fluency * Absorption, 1, 9, 1, 7, 1, 7) data(allFun) test<-generateCowbell(concept, allFun, 10) fitted(test)
# Run a simplified anaylsis with 10 iterations only (to save time.) concept<-generateCowbellConcept(Fun ~ Fluency * Absorption, 1, 9, 1, 7, 1, 7) data(allFun) test<-generateCowbell(concept, allFun, 10) fitted(test)
This function takes the cowbell definition that was created with generateCowbellConcept
and performs
a regression analysis. Additionally it also moves the breaking point to the maximal values of the independent
variables to later on test for the significance of the breaking point. This function needs relatively long to
compute as it uses a gradient based optimizer for optimizing a non - linear model.
generateCowbell(concept, table, iterations = 1000, learningRate = 0.01)
generateCowbell(concept, table, iterations = 1000, learningRate = 0.01)
concept |
The previously in function |
table |
The table that at least contains the data for the dependent and the two independent variables specified in concept. |
iterations |
The number of iteration that should be done with the gradient optimizer. |
learningRate |
The step size that should be applied in the gradient optimizer. |
A list with the data, the model with and without breakpoint and the F-Statistics.
# Run a simplified anaylsis with 10 iterations only (to save time.) concept<-generateCowbellConcept(Fun ~ Fluency * Absorption, 1, 9, 1, 7, 1, 7) data(allFun) test<-generateCowbell(concept, allFun, 10)
# Run a simplified anaylsis with 10 iterations only (to save time.) concept<-generateCowbellConcept(Fun ~ Fluency * Absorption, 1, 9, 1, 7, 1, 7) data(allFun) test<-generateCowbell(concept, allFun, 10)
Generates a concept which is basically the formula used for the regression analysis and minimal and maximal values of the dependent and two independent variables. As this package creates a very specific regression model the formula is always of the form Dest ~ SrcA * SrcB. If one of the minimal and maximal values are omitted, the minimum or maximum value of the data set will be used later on.
generateCowbellConcept(formula, minDest = NA, maxDest = NA, minSrcA = NA, maxSrcA = NA, minSrcB = NA, maxSrcB = NA)
generateCowbellConcept(formula, minDest = NA, maxDest = NA, minSrcA = NA, maxSrcA = NA, minSrcB = NA, maxSrcB = NA)
formula |
The formula essentially specifying the names of the dependend variable (here Dest) and the two independent variables (here SrcA, SrcB). Example: Dest ~ SrcA * SrcB. |
minDest |
The a prior known minimal value the dependend variable (Dest) can have. |
maxDest |
The a prior known maximal value the dependend variable (Dest) can have. |
minSrcA |
The a prior known minimal value the first dependend variable (SrcA) can have. |
maxSrcA |
The a prior known maximal value the first dependend variable (SrcA) can have. |
minSrcB |
The a prior known minimal value the second dependend variable (SrcB) can have. |
maxSrcB |
The a prior known maximal value the second dependend variable (SrcB) can have. |
List of the aggregate information. This is used in the regression analysis.
concept<-generateCowbellConcept(Fun ~ Fluency * Absorption, 1, 9, 1, 7, 1, 7)
concept<-generateCowbellConcept(Fun ~ Fluency * Absorption, 1, 9, 1, 7, 1, 7)
Generates a three dimension plot of cowbell function. Additionally the data points of the original data set are added
in the visualization. The function with and without breaking point can be visualized.
Implementation of the plot
generic.
## S3 method for class 'cowbell' plot(x, breakPointUsed = TRUE, ...)
## S3 method for class 'cowbell' plot(x, breakPointUsed = TRUE, ...)
x |
The data obtained by function |
breakPointUsed |
Defaults to TRUE and indicates if we want to use the version with breakpoint (or not). |
... |
Just for compatibility purposes. |
# Run a simplified anaylsis with 10 iterations only (to save time.) concept<-generateCowbellConcept(Fun ~ Fluency * Absorption, 1, 9, 1, 7, 1, 7) data(allFun) test<-generateCowbell(concept, allFun, 10) plot(test)
# Run a simplified anaylsis with 10 iterations only (to save time.) concept<-generateCowbellConcept(Fun ~ Fluency * Absorption, 1, 9, 1, 7, 1, 7) data(allFun) test<-generateCowbell(concept, allFun, 10) plot(test)
Implementation of the predict
generic. The provided data has to have the exact column names
that were used when the cowbell analysis was done. If no data is provided the original data is used.
## S3 method for class 'cowbell' predict(object, newdata, ...)
## S3 method for class 'cowbell' predict(object, newdata, ...)
object |
The data obtained by function |
newdata |
The data set to perform the prediction on. If omitted the original data is used. |
... |
Just for compatibility purposes. |
The vector with the predicted data.
# Run a simplified anaylsis with 10 iterations only (to save time.) concept<-generateCowbellConcept(Fun ~ Fluency * Absorption, 1, 9, 1, 7, 1, 7) data(allFun) test<-generateCowbell(concept, allFun, 10) predict(test)
# Run a simplified anaylsis with 10 iterations only (to save time.) concept<-generateCowbellConcept(Fun ~ Fluency * Absorption, 1, 9, 1, 7, 1, 7) data(allFun) test<-generateCowbell(concept, allFun, 10) predict(test)
Prints the used formula, the R squared and the F statistics in comparison with a constant function (average of values).
## S3 method for class 'cowbell' print(x, ...)
## S3 method for class 'cowbell' print(x, ...)
x |
Object generated with function |
... |
Only for compatibility purposes. |
Implementation of the print
generic.
# Run a simplified anaylsis with 10 iterations only (to save time.) concept<-generateCowbellConcept(Fun ~ Fluency * Absorption, 1, 9, 1, 7, 1, 7) data(allFun) test<-generateCowbell(concept, allFun, 10) test
# Run a simplified anaylsis with 10 iterations only (to save time.) concept<-generateCowbellConcept(Fun ~ Fluency * Absorption, 1, 9, 1, 7, 1, 7) data(allFun) test<-generateCowbell(concept, allFun, 10) test
Implementation of the print
generic.
## S3 method for class 'cowbellConcept' print(x, ...)
## S3 method for class 'cowbellConcept' print(x, ...)
x |
Object generated with function |
... |
Unused for compatibility only. |
# Generate a concept and display it. concept<-generateCowbellConcept(Fun ~ Fluency * Absorption, 1, 9, 1, 7, 1, 7) concept
# Generate a concept and display it. concept<-generateCowbellConcept(Fun ~ Fluency * Absorption, 1, 9, 1, 7, 1, 7) concept
summary.cowbell
.The output states the concept consisting of the formula and the value range, that was given as a prior information. Then follows the characteristics of the cowbell function. This is the minimal and maximal value of the dependent variable. The maximum is reached at the plateau part and the minimal at the outer ring of the cowbell. It gets reached if any of the two independent variables have reached their minimum. The R function with which the cowbell gets computed is then appended. It follows the R squared and F-statistics in comparison with a constant function.
## S3 method for class 'summary.cowbell' print(x, ...)
## S3 method for class 'summary.cowbell' print(x, ...)
x |
The object to print generated by |
... |
Just for compatibility purposes. |
The following analysis is done to check the significance of the breakpoint. The breakpoint gets eliminated by removing the plateau. The linear rising ridge of the cowbell is rised up to the specified maximum of the independent variables. Therefore only the minimal and maximal value of the dependent variable is left of the definition. What follows is the string that characterizes the R function and the R Squared of the used model. The following F-Statistics compares the full model with the breakpoint against this reduced model without to estimate the significance of the breakpoint.
Implementation of the print
generic.
# Run a simplified anaylsis with 10 iterations only (to save time.) concept<-generateCowbellConcept(Fun ~ Fluency * Absorption, 1, 9, 1, 7, 1, 7) data(allFun) test<-generateCowbell(concept, allFun, 10) summary(test)
# Run a simplified anaylsis with 10 iterations only (to save time.) concept<-generateCowbellConcept(Fun ~ Fluency * Absorption, 1, 9, 1, 7, 1, 7) data(allFun) test<-generateCowbell(concept, allFun, 10) summary(test)
residuals
generic.Implementation of the residuals
generic.
## S3 method for class 'cowbell' residuals(object, ...)
## S3 method for class 'cowbell' residuals(object, ...)
object |
The data obtained by function |
... |
Just for compatibility purposes. |
Vector with the residuals to the data.
# Run a simplified anaylsis with 10 iterations only (to save time.) concept<-generateCowbellConcept(Fun ~ Fluency * Absorption, 1, 9, 1, 7, 1, 7) data(allFun) test<-generateCowbell(concept, allFun, 10) residuals(test)
# Run a simplified anaylsis with 10 iterations only (to save time.) concept<-generateCowbellConcept(Fun ~ Fluency * Absorption, 1, 9, 1, 7, 1, 7) data(allFun) test<-generateCowbell(concept, allFun, 10) residuals(test)
Generates a list that contains relevant information of the cowbell analysis. concept
contains the formula and the minimal
and maximal values. baseDefinition
contains the information for the cowbell. This is the minimal and the maximal value the
cowbell can reach and the position of the breaking point. baseDefinitionReduced
only contains the minimal and the maximal value,
the breakpoint is not included in that model. functionString
is a string version of the R function that generates the cowbell.
functionStringReduced
is the string version without the breaking point. fstatistic
contains the fstatistic information of the
cowbell model in contrast to the constant function. fstatisticBreakpoint
describes the F-statistics of the full cowbell model against the version
without break point.
## S3 method for class 'cowbell' summary(object, ...)
## S3 method for class 'cowbell' summary(object, ...)
object |
The resulting object of |
... |
Just for compatibility purposes. |
Implementation of the summary
generic.
List with the mentioned values.
# Run a simplified anaylsis with 10 iterations only (to save time.) concept<-generateCowbellConcept(Fun ~ Fluency * Absorption, 1, 9, 1, 7, 1, 7) data(allFun) test<-generateCowbell(concept, allFun, 10) summary(test)$functionString
# Run a simplified anaylsis with 10 iterations only (to save time.) concept<-generateCowbellConcept(Fun ~ Fluency * Absorption, 1, 9, 1, 7, 1, 7) data(allFun) test<-generateCowbell(concept, allFun, 10) summary(test)$functionString
This is an artificial data with a perfect cowbell structure that is used for testing.