sm_slope_all {smplot2} | R Documentation |
Calculating the slope across multiple conditions and subjects
Description
This function returns a data frame containing slope (from linear regression) from a data frame that contains the original raw data.
The user can use lm() from base R to compute the slope as well.
Usage
sm_slope_all(data, subjects, groups, conditions, x, values)
Arguments
data |
Name of the variable that stores the data frame that contains the columns with the specified column names. |
subjects |
The name of the column of the data frame that contains subjects. It must be strings. |
groups |
The name of the column of the data frame that contains each group. It must be strings. |
conditions |
The name of the column of the data frame that contains each condition. It must be strings. |
x |
The name of the column of the data frame that contains the x-axis points/x coordinates from which the slopes can be calculated. It must be strings. The column must not have characters. |
values |
The name of the column of the data frame that contains the actual data, which are the y-axis points from which the slope can be calculated. It must be strings. |
Value
Returns a data frame containing slopes for each subject and each experimental condition and/or group.
Examples
library(smplot2)
set.seed(1) # generate random data
day1 = rnorm(16,0,1)
day2 = rnorm(16,5,1)
Subject <- rep(paste0('S',seq(1:16)), 2)
Value <- data.frame(Value = matrix(c(day1,day2),ncol=1))
Day <- rep(c(1,2), each = length(day1))
Condition <- rep('Control', length(day1)*2)
df <- cbind(Subject, Value, Condition, Day)
sm_slope_all(data = df, subjects = 'Subject',values = 'Value',
conditions = 'Condition',x = 'Day')