bdotsThis vignette is created to illustrate the use of the
bcorr function, which finds the correlation between a fixed
value in our dataset and the collection of fitted curves at each time
points for each of the groups fit in bfit.
First, let’s take an existing dataset and add a fixed value for each of the subjects
library(bdots)
library(data.table)
## Let's work with cohort_unrelated dataset, as it has multiple groups
dat <- as.data.table(cohort_unrelated)
## And add a fixed value for which we want to find a correlation
dat[, val := rnorm(1), by = Subject]
head(dat)## Subject Time DB_cond Fixations LookType Group val
## <num> <int> <char> <num> <char> <int> <num>
## 1: 1 0 50 0.01136364 Cohort 50 1.569088
## 2: 1 4 50 0.01136364 Cohort 50 1.569088
## 3: 1 8 50 0.01136364 Cohort 50 1.569088
## 4: 1 12 50 0.01136364 Cohort 50 1.569088
## 5: 1 16 50 0.02272727 Cohort 50 1.569088
## 6: 1 20 50 0.02272727 Cohort 50 1.569088
Now, we go about creating our fitted object as usual
## Create regular fit in bdots
fit <- bfit(data = dat,
subject = "Subject",
time = "Time",
group = c("LookType", "Group"),
y = "Fixations", curveFun = doubleGauss2(),
cores = 2)Using this fit object, we now introduce the bcor
function, taking four arguments:
bdObj, any object returned from a bfit
callval, a length one character vector of the value with
which we want to correlate. val should be a column in our
original dataset, and it should be numericciBands, a boolean indicating whether or not we want to
return 95% confidence intervals. Default is FALSEmethod, paralleling the method argument in
cor and cor.test. The default is
pearson.## Returns a data.table of class bdotsCorrObj
corr_ci <- bcorr(fit, val = "val", ciBands = TRUE)
head(corr_ci)## time Correlation lower upper Group Group1 Group2
## <int> <num> <num> <num> <char> <char> <char>
## 1: 0 0.1163679 -0.5936311 0.7244986 Cohort 50 Cohort 50
## 2: 4 0.1216071 -0.5901785 0.7270138 Cohort 50 Cohort 50
## 3: 8 0.1259779 -0.5872782 0.7290997 Cohort 50 Cohort 50
## 4: 12 0.1293981 -0.5849959 0.7307242 Cohort 50 Cohort 50
## 5: 16 0.1318420 -0.5833581 0.7318808 Cohort 50 Cohort 50
## 6: 20 0.1333391 -0.5823518 0.7325877 Cohort 50 Cohort 50
## time Correlation Group Group1 Group2
## <int> <num> <char> <char> <char>
## 1: 0 0.1163679 Cohort 50 Cohort 50
## 2: 4 0.1216071 Cohort 50 Cohort 50
## 3: 8 0.1259779 Cohort 50 Cohort 50
## 4: 12 0.1293981 Cohort 50 Cohort 50
## 5: 16 0.1318420 Cohort 50 Cohort 50
## 6: 20 0.1333391 Cohort 50 Cohort 50
From here, we are able to use the data.tables themselves
for whatever we may be interested in. We also have a plotting method
associated with this object
Because this object is a data.table, we have full use of
subsetting capabilities for our plots