Lib/function/Data

We required at least 20 data points to be included in data set

reduced_Fulladdiction–has all data including demographics

reduced_addiction_withMissing–has variables we are focusing on with misisng addiction_imputed–has variables we are focusing on with no misisng due to copymean imputation

library(readit)
library(INIT)
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✔ ggplot2 3.4.4     ✔ purrr   1.0.2
## ✔ tibble  3.2.1     ✔ dplyr   1.1.4
## ✔ tidyr   1.3.0     ✔ stringr 1.5.1
## ✔ readr   2.1.4     ✔ forcats 1.0.0
## Warning: package 'tibble' was built under R version 4.3.1
## Warning: package 'tidyr' was built under R version 4.2.2
## Warning: package 'readr' was built under R version 4.2.2
## Warning: package 'forcats' was built under R version 4.2.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
library(psych)
## 
## Attaching package: 'psych'
## The following objects are masked from 'package:ggplot2':
## 
##     %+%, alpha
library(longitudinalData)
## Loading required package: clv
## Loading required package: cluster
## Loading required package: class
## Warning: package 'class' was built under R version 4.3.0
## Loading required package: rgl
## This build of rgl does not include OpenGL functions.  Use
##  rglwidget() to display results, e.g. via options(rgl.printRglwidget = TRUE).
## Loading required package: misc3d
## Warning in fun(libname, pkgname): couldn't connect to display ":0"
#library(igraph)
library(qgraph)
library(gimme)
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
library(psych)
library(forecast)
library(broom)
## Warning: package 'broom' was built under R version 4.3.1
library(metafor)
## Loading required package: Matrix
## Warning: package 'Matrix' was built under R version 4.3.1
## 
## Attaching package: 'Matrix'
## The following objects are masked from 'package:tidyr':
## 
##     expand, pack, unpack
## Loading required package: metadat
## Loading required package: numDeriv
## 
## Loading the 'metafor' package (version 4.2-0). For an
## introduction to the package please type: help(metafor)
library(brms)
## Loading required package: Rcpp
## Warning: package 'Rcpp' was built under R version 4.3.1
## Loading 'brms' package (version 2.17.0). Useful instructions
## can be found by typing help('brms'). A more detailed introduction
## to the package is available through vignette('brms_overview').
## 
## Attaching package: 'brms'
## The following object is masked from 'package:forecast':
## 
##     ma
## The following object is masked from 'package:psych':
## 
##     cs
## The following object is masked from 'package:stats':
## 
##     ar
library(lavaan)
## This is lavaan 0.6-16
## lavaan is FREE software! Please report any bugs.
## 
## Attaching package: 'lavaan'
## The following object is masked from 'package:psych':
## 
##     cor2cov
library(lme4)
## 
## Attaching package: 'lme4'
## The following object is masked from 'package:brms':
## 
##     ngrps
library(bayesmeta)
## Loading required package: forestplot
## Loading required package: grid
## Loading required package: checkmate
## Loading required package: abind
## Loading required package: mvtnorm
## 
## Attaching package: 'bayesmeta'
## The following object is masked from 'package:stats':
## 
##     convolve
library(DT)
## Warning: package 'DT' was built under R version 4.3.0
###data files ####

###note non imputed include all data, whereas imputed exclude those who did not do at least 10 time points

# GIMME_Input <- "~/student led research/student led research 2024/data/andrew individual/gimme data"
# GIMME_Output<-"~/student led research/student led research 2024/output/gimme"
# 



calculate_missing_percentages <- function(data, grouping_var) {
  # Ensure the grouping variable is treated as a symbol for dynamic referencing
  grouping_var_sym <- rlang::ensym(grouping_var)
  
  # First dataframe: Calculate the percentage of missing values
  missing_data_df <- data %>%
    dplyr::group_by(!!grouping_var_sym) %>%
    dplyr::mutate(TotalObservations = n()) %>%
    dplyr::summarise(TotalObservations = first(TotalObservations), # Keep the total observations count
                     across(everything(), ~sum(is.na(.)) / length(.) * 100, .names = "perc_missing_{.col}")) %>%
    ungroup()

  # Second dataframe: Summarize the first dataframe
  summary_df <- missing_data_df %>%
    dplyr::select(-!!grouping_var_sym) %>% # Exclude the grouping variable from the summary
    dplyr::summarise(across(.cols = everything(),
                     .fns = list(mean = ~mean(.x, na.rm = TRUE), 
                                 median = ~median(.x, na.rm = TRUE)),
                     .names = "{.col}_{.fn}"))
  
  # Return a list containing both dataframes
  return(list(MissingData = missing_data_df, Summary = summary_df))
}

###restructure meta analtic data, stacking it long

transform_to_long_format <- function(data_frame) {
  long_data <- data_frame %>%
    pivot_longer(-ID, names_to = "variable", values_to = "value") %>%
    mutate(
      IV = sub("_arimaCont.*", "", variable),
      DV = sub(".*\\.(.*)", "\\1", variable), # Dynamically extract DV
      Metric = ifelse(grepl("coef", variable), "Score", "SE"),
      variable = NULL # Remove the original variable column
    ) %>%
    pivot_wider(names_from = Metric, values_from = value) %>%
    select(ID, IV, DV, Score, SE)
  
  return(long_data)
}


addiction_withMissing <- readit("~/student led research/student led research 2024/data/cristobaladdiction/addiction_wtime.csv");
## File guessed to be CSV ("~/student led research/student led research 2024/data/cristobaladdiction/addiction_wtime.csv")
## Rows: 5027 Columns: 14
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## dbl (14): JustAFewMoreMinutes, FailedToDecreaseInternetTime, LostSleepOverIn...
## 
## ℹ 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.
addiction_imputed <- readit("~/student led research/student led research 2024/data/cristobaladdiction/Addiction_imputed.csv")
## File guessed to be CSV ("~/student led research/student led research 2024/data/cristobaladdiction/Addiction_imputed.csv")
## Rows: 4105 Columns: 14── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## dbl (14): ID, Time, JustAFewMoreMinutes, FailedToDecreaseInternetTime, LostS...
## ℹ 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.
Fulladdiction <- readit("~/student led research/student led research 2024/data/cristobaladdiction/data.xlsx");
## File guessed to be xls/xlsx (Excel) ("~/student led research/student led research 2024/data/cristobaladdiction/data.xlsx")
# getting time variable
Fulladdiction <-Fulladdiction   %>%
  arrange(Name, Date, MeasurementPoint) %>% # Ensure the data is ordered
  group_by(Name) %>%
  mutate(time = row_number()) %>% # Create 'time' as a sequential number
  ungroup()

Fulladdiction <- Fulladdiction %>%  
  dplyr::rename(
    JustAFewMoreMinutes = IAT_1,
    FailedToDecreaseInternetTime = IAT_2,
    LostSleepOverInternet = IAT_3,
    FeltBadOffline = IAT_4,
    PreferredInternetOverPeople = IAT_5,
    Anxious =GAD_1,
    ID = Name,
    Time=time,
    Tired =Tired_Awake,
    Unhappy =Unhappy_Happy,
    Agitated=Agitated_Calm,
    NoEnergy=WoEnergy_FullEnergy,
    Bad=Bad_Good,
    Tense=Tense_Relaxed
  )



length(unique(Fulladdiction$ID)) ## 122
## [1] 122
length(unique(addiction_withMissing$ID)) #`122
## [1] 122
length(unique(addiction_imputed$ID)) #84
## [1] 84
# Filter to include only IDs that are found in addiction_imputed and therefore have at least 20 values

reduced_addiction_withMissing <- addiction_withMissing %>%
  filter(ID %in% addiction_imputed$ID)

reduced_Fulladdiction <- Fulladdiction %>%
  filter(ID %in% addiction_imputed$ID)


length(unique(reduced_Fulladdiction$ID)) ## 84
## [1] 84
length(unique(reduced_addiction_withMissing$ID)) #84
## [1] 84
length(unique(addiction_imputed$ID)) #84
## [1] 84

Missing

Descriptives

## Mean age: 23.54762
## SD age: 2.957908
## 
##  Femenino Masculino      Otro 
##        44        36         4

Correlations

This shows you the simple correlations and significant levels

Within are correlations within person Between are correlations between people

I arimax results

This will produce arimax estimates for every internet addiction iv and every well being dv

If score is 2 times the standard error, then that result is significant for that person

## Rows: 2016 Columns: 5
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): IV, DV
## dbl (3): ID, Score, SE
## 
## ℹ 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.

Bayes analysis

Now we ask for the pooled effect of the internet addiction items linking to the well-being times

Score= strength of relationship betrween addiction and well-being

intercept is the pooled effect-ie. average link between internet addiction and well-being (should be negative)

                          Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS

Intercept -0.06 0.02 -0.11 -0.02 1.00 2374 4981

so on average, there is a negative link between addiction and well being…(estimate more than 2 x standard error)

sd(Intercept):

Estimate: 0.18 Est.Error: 0.02

This represents the estimated standard deviation of the intercept across the different levels of ID The estimate of 0.18 with a standard error of 0.02 suggests that there’s variability in the baseline scores across ID

so intercept +_2*SD is the range of links between well-being and addiction. -.06-.36=-.42…strongest link -.06 + .36= .30 …addition associated with higher well being for some

sd(IVFeltBadOffline):

Estimate: 0.15

This is the estimated standard deviation for the effect of the IV variable FeltBadOffline on Score, accounting for random effects across ID. It indicates how much the influence of feeling bad when offline varies across different individuals (ID).

cor(Intercept,IVFeltBadOffline):

Estimate: -0.35

This shows the estimated correlation between the intercept and the effect of FeltBadOffline. A negative value (-0.35) means that, across ID, higher baseline scores tend to be associated with a smaller effect of FeltBadOffline on the outcome (or vice versa).

cor(IVFeltBadOffline,IVPreferredInternetOverPeople):

Estimate: 0.50

This represents the estimated correlation between the effects of FeltBadOffline and PreferredInternetOverPeople on Score, again across ID. A positive correlation (0.50) suggests that individuals for whom FeltBadOffline has a stronger effect on Score also tend to have a stronger effect of PreferredInternetOverPeople.

##  Family: gaussian 
##   Links: mu = identity; sigma = identity 
## Formula: Score | se(SE) ~ 1 + IV + DV + (1 + IV + DV | ID) 
##    Data: combined_results (Number of observations: 2016) 
##   Draws: 4 chains, each with iter = 10000; warmup = 5000; thin = 1;
##          total post-warmup draws = 20000
## 
## Group-Level Effects: 
## ~ID (Number of levels: 84) 
##                                                          Estimate Est.Error
## sd(Intercept)                                                0.18      0.02
## sd(IVFeltBadOffline)                                         0.15      0.01
## sd(IVJustAFewMoreMinutes)                                    0.08      0.01
## sd(IVPreferredInternetOverPeople)                            0.19      0.02
## sd(DVBad)                                                    0.11      0.01
## sd(DVNoEnergy)                                               0.12      0.01
## sd(DVTense)                                                  0.08      0.01
## sd(DVTired)                                                  0.13      0.01
## sd(DVUnhappy)                                                0.11      0.01
## cor(Intercept,IVFeltBadOffline)                             -0.35      0.10
## cor(Intercept,IVJustAFewMoreMinutes)                        -0.08      0.14
## cor(IVFeltBadOffline,IVJustAFewMoreMinutes)                  0.20      0.14
## cor(Intercept,IVPreferredInternetOverPeople)                -0.46      0.09
## cor(IVFeltBadOffline,IVPreferredInternetOverPeople)          0.50      0.09
## cor(IVJustAFewMoreMinutes,IVPreferredInternetOverPeople)     0.07      0.14
## cor(Intercept,DVBad)                                        -0.12      0.13
## cor(IVFeltBadOffline,DVBad)                                 -0.30      0.12
## cor(IVJustAFewMoreMinutes,DVBad)                             0.18      0.16
## cor(IVPreferredInternetOverPeople,DVBad)                    -0.10      0.13
## cor(Intercept,DVNoEnergy)                                   -0.15      0.12
## cor(IVFeltBadOffline,DVNoEnergy)                             0.07      0.13
## cor(IVJustAFewMoreMinutes,DVNoEnergy)                        0.19      0.15
## cor(IVPreferredInternetOverPeople,DVNoEnergy)                0.03      0.13
## cor(DVBad,DVNoEnergy)                                        0.63      0.10
## cor(Intercept,DVTense)                                      -0.34      0.13
## cor(IVFeltBadOffline,DVTense)                               -0.11      0.15
## cor(IVJustAFewMoreMinutes,DVTense)                           0.22      0.18
## cor(IVPreferredInternetOverPeople,DVTense)                  -0.01      0.15
## cor(DVBad,DVTense)                                           0.41      0.15
## cor(DVNoEnergy,DVTense)                                      0.49      0.14
## cor(Intercept,DVTired)                                      -0.19      0.12
## cor(IVFeltBadOffline,DVTired)                               -0.08      0.13
## cor(IVJustAFewMoreMinutes,DVTired)                          -0.09      0.15
## cor(IVPreferredInternetOverPeople,DVTired)                  -0.19      0.13
## cor(DVBad,DVTired)                                           0.36      0.13
## cor(DVNoEnergy,DVTired)                                      0.74      0.08
## cor(DVTense,DVTired)                                         0.29      0.16
## cor(Intercept,DVUnhappy)                                    -0.16      0.13
## cor(IVFeltBadOffline,DVUnhappy)                             -0.22      0.13
## cor(IVJustAFewMoreMinutes,DVUnhappy)                         0.17      0.16
## cor(IVPreferredInternetOverPeople,DVUnhappy)                -0.09      0.13
## cor(DVBad,DVUnhappy)                                         0.72      0.09
## cor(DVNoEnergy,DVUnhappy)                                    0.39      0.13
## cor(DVTense,DVUnhappy)                                       0.32      0.16
## cor(DVTired,DVUnhappy)                                       0.28      0.14
##                                                          l-95% CI u-95% CI Rhat
## sd(Intercept)                                                0.15     0.22 1.00
## sd(IVFeltBadOffline)                                         0.13     0.19 1.00
## sd(IVJustAFewMoreMinutes)                                    0.06     0.11 1.00
## sd(IVPreferredInternetOverPeople)                            0.16     0.22 1.00
## sd(DVBad)                                                    0.09     0.14 1.00
## sd(DVNoEnergy)                                               0.10     0.15 1.00
## sd(DVTense)                                                  0.06     0.11 1.00
## sd(DVTired)                                                  0.10     0.16 1.00
## sd(DVUnhappy)                                                0.09     0.14 1.00
## cor(Intercept,IVFeltBadOffline)                             -0.54    -0.14 1.00
## cor(Intercept,IVJustAFewMoreMinutes)                        -0.35     0.20 1.00
## cor(IVFeltBadOffline,IVJustAFewMoreMinutes)                 -0.09     0.45 1.00
## cor(Intercept,IVPreferredInternetOverPeople)                -0.63    -0.26 1.00
## cor(IVFeltBadOffline,IVPreferredInternetOverPeople)          0.30     0.67 1.00
## cor(IVJustAFewMoreMinutes,IVPreferredInternetOverPeople)    -0.21     0.34 1.00
## cor(Intercept,DVBad)                                        -0.37     0.13 1.00
## cor(IVFeltBadOffline,DVBad)                                 -0.53    -0.05 1.00
## cor(IVJustAFewMoreMinutes,DVBad)                            -0.14     0.47 1.00
## cor(IVPreferredInternetOverPeople,DVBad)                    -0.35     0.14 1.00
## cor(Intercept,DVNoEnergy)                                   -0.39     0.09 1.00
## cor(IVFeltBadOffline,DVNoEnergy)                            -0.18     0.32 1.00
## cor(IVJustAFewMoreMinutes,DVNoEnergy)                       -0.12     0.47 1.00
## cor(IVPreferredInternetOverPeople,DVNoEnergy)               -0.21     0.28 1.00
## cor(DVBad,DVNoEnergy)                                        0.41     0.80 1.00
## cor(Intercept,DVTense)                                      -0.58    -0.05 1.00
## cor(IVFeltBadOffline,DVTense)                               -0.40     0.20 1.00
## cor(IVJustAFewMoreMinutes,DVTense)                          -0.14     0.56 1.00
## cor(IVPreferredInternetOverPeople,DVTense)                  -0.31     0.28 1.00
## cor(DVBad,DVTense)                                           0.08     0.67 1.00
## cor(DVNoEnergy,DVTense)                                      0.20     0.72 1.00
## cor(Intercept,DVTired)                                      -0.42     0.06 1.00
## cor(IVFeltBadOffline,DVTired)                               -0.33     0.17 1.00
## cor(IVJustAFewMoreMinutes,DVTired)                          -0.39     0.21 1.00
## cor(IVPreferredInternetOverPeople,DVTired)                  -0.43     0.06 1.00
## cor(DVBad,DVTired)                                           0.08     0.59 1.00
## cor(DVNoEnergy,DVTired)                                      0.56     0.87 1.00
## cor(DVTense,DVTired)                                        -0.04     0.57 1.00
## cor(Intercept,DVUnhappy)                                    -0.40     0.10 1.00
## cor(IVFeltBadOffline,DVUnhappy)                             -0.47     0.04 1.00
## cor(IVJustAFewMoreMinutes,DVUnhappy)                        -0.14     0.48 1.00
## cor(IVPreferredInternetOverPeople,DVUnhappy)                -0.34     0.17 1.00
## cor(DVBad,DVUnhappy)                                         0.51     0.87 1.00
## cor(DVNoEnergy,DVUnhappy)                                    0.12     0.62 1.00
## cor(DVTense,DVUnhappy)                                      -0.03     0.60 1.00
## cor(DVTired,DVUnhappy)                                      -0.01     0.53 1.00
##                                                          Bulk_ESS Tail_ESS
## sd(Intercept)                                                4584     8200
## sd(IVFeltBadOffline)                                         3661     8178
## sd(IVJustAFewMoreMinutes)                                    5800     9532
## sd(IVPreferredInternetOverPeople)                            3950     8073
## sd(DVBad)                                                    5598    10221
## sd(DVNoEnergy)                                               4955     8651
## sd(DVTense)                                                  4241     7089
## sd(DVTired)                                                  5615     9778
## sd(DVUnhappy)                                                5865    10302
## cor(Intercept,IVFeltBadOffline)                              3424     7372
## cor(Intercept,IVJustAFewMoreMinutes)                         7584    11918
## cor(IVFeltBadOffline,IVJustAFewMoreMinutes)                  6544    10918
## cor(Intercept,IVPreferredInternetOverPeople)                 4068     7744
## cor(IVFeltBadOffline,IVPreferredInternetOverPeople)          3048     6314
## cor(IVJustAFewMoreMinutes,IVPreferredInternetOverPeople)     2727     6516
## cor(Intercept,DVBad)                                         5643    10154
## cor(IVFeltBadOffline,DVBad)                                  5601     9726
## cor(IVJustAFewMoreMinutes,DVBad)                             4409     8277
## cor(IVPreferredInternetOverPeople,DVBad)                     6115     9619
## cor(Intercept,DVNoEnergy)                                    5402     9287
## cor(IVFeltBadOffline,DVNoEnergy)                             5316     9163
## cor(IVJustAFewMoreMinutes,DVNoEnergy)                        3836     6990
## cor(IVPreferredInternetOverPeople,DVNoEnergy)                5897    11157
## cor(DVBad,DVNoEnergy)                                        4876     8908
## cor(Intercept,DVTense)                                       8601    11997
## cor(IVFeltBadOffline,DVTense)                                7609    12102
## cor(IVJustAFewMoreMinutes,DVTense)                           5243     8308
## cor(IVPreferredInternetOverPeople,DVTense)                   8460    13694
## cor(DVBad,DVTense)                                           5897    10899
## cor(DVNoEnergy,DVTense)                                      5864    11044
## cor(Intercept,DVTired)                                       6361    10658
## cor(IVFeltBadOffline,DVTired)                                5637    10366
## cor(IVJustAFewMoreMinutes,DVTired)                           4352     8245
## cor(IVPreferredInternetOverPeople,DVTired)                   6945    10978
## cor(DVBad,DVTired)                                           4067     8372
## cor(DVNoEnergy,DVTired)                                      7498    11813
## cor(DVTense,DVTired)                                         5897    11262
## cor(Intercept,DVUnhappy)                                     6761    12223
## cor(IVFeltBadOffline,DVUnhappy)                              6750    10833
## cor(IVJustAFewMoreMinutes,DVUnhappy)                         5022     9141
## cor(IVPreferredInternetOverPeople,DVUnhappy)                 7953    11933
## cor(DVBad,DVUnhappy)                                         5046     9568
## cor(DVNoEnergy,DVUnhappy)                                    5983    12182
## cor(DVTense,DVUnhappy)                                       5813    10271
## cor(DVTired,DVUnhappy)                                       5980    10225
## 
## Population-Level Effects: 
##                               Estimate Est.Error l-95% CI u-95% CI Rhat
## Intercept                        -0.06      0.02    -0.11    -0.02 1.00
## IVFeltBadOffline                  0.01      0.02    -0.03     0.05 1.00
## IVJustAFewMoreMinutes             0.03      0.01     0.00     0.05 1.00
## IVPreferredInternetOverPeople     0.04      0.02    -0.00     0.08 1.00
## DVBad                             0.00      0.02    -0.03     0.03 1.00
## DVNoEnergy                       -0.00      0.02    -0.04     0.03 1.00
## DVTense                           0.00      0.01    -0.02     0.03 1.00
## DVTired                          -0.02      0.02    -0.05     0.02 1.00
## DVUnhappy                         0.00      0.02    -0.03     0.03 1.00
##                               Bulk_ESS Tail_ESS
## Intercept                         2374     4981
## IVFeltBadOffline                  3212     6326
## IVJustAFewMoreMinutes             8416    12320
## IVPreferredInternetOverPeople     3429     6076
## DVBad                             5119     8847
## DVNoEnergy                        5198     9542
## DVTense                           6763    10555
## DVTired                           5988    10341
## DVUnhappy                         6546    10504
## 
## Family Specific Parameters: 
##       Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
## sigma     0.00      0.00     0.00     0.00   NA       NA       NA
## 
## Draws were sampled using sampling(NUTS). For each parameter, Bulk_ESS
## and Tail_ESS are effective sample size measures, and Rhat is the potential
## scale reduction factor on split chains (at convergence, Rhat = 1).

i2 analysis

level of heterogeneity of every combination of variable

Rough guidelines for interpreting I2 in the meta-analytic literature are that values less than 25% reflect low inconsistency, 25% to 50% reflect moderate inconsistency, 50 to 75% reflect high inconsistency, and over 75% show very high inconsistency (Higgins et al., 2003). While there are no absolute cutoffs, in the Cochrane library of meta-analyses, for example, the median I2 is 21% (Ioannidis et al., 2007). If I2 exceeds even 50%, it is common to search for subgroups or to avoid reporting pooled effects (Lo et al., 2019).