Nick’s data - Positive autobiographical memories in cigarette
smokers.
- cigarette smokers recalled positive memories in an interview format,
for each memory they rated:
- how long ago the event occurred (ordinal, higher values are more
recent memories)
- if the memory involved cigarette smoking
- how frequently they think about the memory
- how (negative-positive) they feel while recalling the memory
- how vivid the memory is
library("tidyverse")
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.4.4 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.1
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library("lme4")
## Loading required package: Matrix
##
## Attaching package: 'Matrix'
##
## The following objects are masked from 'package:tidyr':
##
## expand, pack, unpack
mem_init_tib <- read_csv("data/mem_initial_ratings.csv") |> mutate(id = as.character(id))
## Rows: 522 Columns: 11
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): mem_description, mem_keyphrase
## dbl (9): id, memory_number, mem_time, mem_smoking, mem_valence, mem_intensit...
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Fit the full model: vividness explained by time, smoking, and
frequency
- we get a singular fit warning - therefore, the model fit results are
not interpretable.
- in linear mixed models, a singular fit occurs when random effect
variance is estimated very near zero or collinearity between random
effects is very near 1 or -1. This can occur when the data is not
sufficiently informative
- in this case the
mem_frequency
random effect
(by-subject slope) is highly negatively correlated with the by-subject
intercept (possibly due to lack of variance in the mem_frequency
measure)
- we can examine the
mem_frequency
variable more closely
to see this (Q: how did we know that this might be the problem? A:
During data collection we suspected that some participants did not
understand this measure fully)
model1 = lmer(mem_vividness ~ mem_time + mem_smoking + mem_frequency + (mem_time + mem_smoking + mem_frequency| id), data=mem_init_tib)
## boundary (singular) fit: see help('isSingular')
summary(model1)
## Linear mixed model fit by REML ['lmerMod']
## Formula: mem_vividness ~ mem_time + mem_smoking + mem_frequency + (mem_time +
## mem_smoking + mem_frequency | id)
## Data: mem_init_tib
##
## REML criterion at convergence: 1216.8
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -5.1005 -0.3896 0.0838 0.5239 2.5855
##
## Random effects:
## Groups Name Variance Std.Dev. Corr
## id (Intercept) 1.153553 1.07404
## mem_time 0.005238 0.07237 -0.69
## mem_smoking 0.035721 0.18900 -0.57 0.11
## mem_frequency 0.015915 0.12615 -1.00 0.68 0.50
## Residual 0.523723 0.72369
## Number of obs: 522, groups: id, 17
##
## Fixed effects:
## Estimate Std. Error t value
## (Intercept) 3.29191 0.30238 10.886
## mem_time 0.08442 0.02875 2.936
## mem_smoking 0.08194 0.08169 1.003
## mem_frequency 0.22672 0.04189 5.412
##
## Correlation of Fixed Effects:
## (Intr) mem_tm mm_smk
## mem_time -0.580
## mem_smoking -0.599 0.192
## mem_freqncy -0.785 0.241 0.238
## optimizer (nloptwrap) convergence code: 0 (OK)
## boundary (singular) fit: see help('isSingular')
#plot individual frequency ratings by subject
#mem_init_tib |> ggplot(aes(x = id, y = mem_frequency)) +
# geom_jitter(shape = 1, width = .1, height = 0)
so we will delete frequency from the model
model1 = lmer(mem_vividness ~ mem_time + mem_smoking + (mem_time + mem_smoking | id), data=mem_init_tib, control = lmerControl(optimizer = "bobyqa"))
summary(model1)
## Linear mixed model fit by REML ['lmerMod']
## Formula: mem_vividness ~ mem_time + mem_smoking + (mem_time + mem_smoking |
## id)
## Data: mem_init_tib
## Control: lmerControl(optimizer = "bobyqa")
##
## REML criterion at convergence: 1279.1
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -4.7733 -0.3443 0.1148 0.5240 2.7004
##
## Random effects:
## Groups Name Variance Std.Dev. Corr
## id (Intercept) 1.028609 1.01420
## mem_time 0.006202 0.07875 -0.79
## mem_smoking 0.071004 0.26647 -0.80 0.40
## Residual 0.596518 0.77235
## Number of obs: 522, groups: id, 17
##
## Fixed effects:
## Estimate Std. Error t value
## (Intercept) 3.83087 0.28622 13.384
## mem_time 0.10335 0.03070 3.366
## mem_smoking 0.05957 0.09677 0.616
##
## Correlation of Fixed Effects:
## (Intr) mem_tm
## mem_time -0.696
## mem_smoking -0.776 0.308