Publications by Daniel
Read and write excel file
Data read and write library(readxl) library(readr) library(haven) library(writexl) Importing data Read in from excel excel <- read_excel("C:/Users/hed2/Downloads/mybook2/mybook2/excel.xlsx") excel ## # A tibble: 4 × 4 ## ID sex ht_in wgt_lbs ## <chr> <chr> <dbl> <dbl> ## 1 001 Male 71 190 ## 2 002 Male 69 ...
163 sym R (3615 sym/16 pcs)
Least-squares means with interaction
Reference Least-squares means with interaction Without interaction at a special value # Compute least-squares means for specified factors or factor combinations in a linear model require(lsmeans) ## Loading required package: lsmeans ## Loading required package: emmeans ## The 'lsmeans' package is now basically a front end for 'emmeans'. ## User...
212 sym R (6764 sym/35 pcs)
How to calculate the prediction interval for LMM
How to calculate the prediction interval for LMM Using ggpredict function library(nlme) library(ggeffects) library(tidyverse) ## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ── ## ✔ dplyr 1.1.1 ✔ readr 2.1.4 ## ✔ forcats 1.0.0 ✔ st...
145 sym R (6993 sym/46 pcs) 3 img
Spline regression
Reference Spline regression Dataset library(splines) library(ggplot2) df <- data.frame(x=1:15, y=c(2, 10, 20, 25, 20, 10, 19, 15, 19, 10, 6, 20, 31, 31, 40)) #create scatter plot with line of best fit ggplot(df, aes(x=x, y=y)) + geom_point() + geom_smooth(method=loess, se=FALSE) ## `geom_smooth()` using formula = 'y ...
305 sym R (5166 sym/17 pcs) 9 img
Simulating data for linear mix model
Introduction [Reference] (https://stats.stackexchange.com/questions/11233/how-to-simulate-data-based-on-a-linear-mixed-model-fit-object-in-r) Manual simulating data for linear mix model with the random intercepts library(nlme) fm2 <- lme(distance ~ age + Sex, data = Orthodont, random = ~ 1) simfun <- function(n) { # n is the number of subje...
378 sym R (4000 sym/11 pcs)
Combine estimates by pooling rules
Introduction Rubin´s Rules (RR) are designed to pool parameter estimates, such as mean differences, regression coefficients, standard errors and to derive confidence intervals and p-values. The standard errors of the multiple imputation solution are slightly smaller than in the complete-case analysis. # Examples # impute missing data, analyse...
323 sym R (1608 sym/11 pcs)
Causal inference intro
Introduction In detail please see the reference by Ashley I Naimi. Install packages from remote github # https://www.youtube.com/watch?v=c14aqVC-Szo # usethis::create_github_token() # get a token # usethis::edit_r_environ() # .Renviron # GITHUB_TOKEN = ghp_6... l # save and restart r studio # options(download.file.method = "wininet") # ...
1167 sym R (5840 sym/32 pcs)
Expectation maximum
Introduction If the new solution costs less than the old solution then it is guaranteed to be accepted and a poorer solution is unlikely to be accepted. it is to calculate the integral, proportion, and sampling. Data simulation # Plot the exponential distribution: x <- seq(from = 0, to = 10, length=20) y <- exp(-x) #y is only density function ...
528 sym Python (2185 sym/21 pcs) 7 img
MCMC sampling
Introduction If the new solution costs less than the old solution then it is guaranteed to be accepted and a poorer solution is unlikely to be accepted. it is to calculate the integral, proportion, and area. Data simulation # Plot the exponential distribution: x <- seq(from = 0, to = 10, length=20) y <- exp(-x) #y is only density function plo...
513 sym Python (1504 sym/13 pcs) 3 img
SuperLearner_sl3
SuperLearner_sl3 In detail please see the reference by Ashley I Naimi. Scale variables library(sl3) library(tidyverse) ## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ── ## ✔ dplyr 1.1.1 ✔ readr 2.1.4 ## ✔ forcats 1.0.0 ✔ stringr ...
349 sym R (6910 sym/20 pcs)