### Install GAMLj from GitHub Source: https://gamlj.github.io/rpackage/index.html Use this command to install the latest version of GAMLj directly from the GitHub repository. ```R devtools::install_github("gamlj/gamlj") ``` ```R devtools::install_github(“gamlj/gamlj”) ``` -------------------------------- ### Load GAMLj library Source: https://gamlj.github.io/rpackage/articles/vignettes_plot.html Initial setup to access GAMLj functions. ```R library(GAMLj3) ``` -------------------------------- ### Initialize GAMLj Environment Source: https://gamlj.github.io/rpackage/articles/vignettes_defining_model.html Load the GAMLj3 library and prepare the example dataset. ```R library(GAMLj3) data("clustermanymodels") data<-clustermanymodels ``` -------------------------------- ### Install Legacy GAMLj Version Source: https://gamlj.github.io/rpackage/index.html Use this command to install version 2.6.6 if compatibility with older analyses is required. ```R devtools::install_github("gamlj/gamlj",ref="Version.2.6.6") ``` -------------------------------- ### Install Legacy GAMLj Version Source: https://gamlj.github.io/rpackage/index.html Install version 2.6.6 of the GAMLj module for compatibility with older analyses. ```R devtools::install_github("gamlj/gamlj",ref="Version.2.6.6") ``` ```R devtools::install_github(“gamlj/gamlj”,ref=“Version.2.6.6”) ``` -------------------------------- ### Install GAMLj from Source Source: https://gamlj.github.io/rpackage/index.html Compile the module from a local repository clone using the jmvtools package. ```R library(jmvtools) jmvtools::install() ``` -------------------------------- ### Install GAMLj in R Source: https://gamlj.github.io/index.html Use the devtools package to install the GAMLj library directly from the GitHub repository. ```R devtools::install_github("gamlj/gamlj") ``` -------------------------------- ### Install GAMLj from source Source: https://gamlj.github.io/rpackage/index.html Compile the module from a local clone of the repository using the jmvtools package. ```R library(jmvtools) jmvtools::install() ``` -------------------------------- ### Interactive Terminal Startup Notice Source: https://gamlj.github.io/rpackage/LICENSE.html Short license notice to display when a program starts in interactive mode. ```text Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type 'show w'. This is free software, and you are welcome to redistribute it under certain conditions; type 'show c' for details. ``` -------------------------------- ### Generating plots with GAMLj Source: https://gamlj.github.io/rpackage/reference/jnplot.html Examples showing how to generate plots from a GAMLj linear model object. ```R data(qsport) gmod <- GAMLj3::gamlj_lm( formula = performance ~ hours, data = qsport ) plot(gmod, plot_x = "hours") plot(gmod, formula = ~hours) #> [[1]] #> ``` -------------------------------- ### Example usage of GAMLj linear model Source: https://gamlj.github.io/rpackage/reference/s3methods.html Demonstrates fitting a linear model using GAMLj3 and displaying the summary output. ```r data(fivegroups) fivegroups$Group <- factor(fivegroups$Group) gmod <- GAMLj3::gamlj_lm( formula = Score ~ Group, data = fivegroups ) summary(gmod) ``` -------------------------------- ### Display contrast matrix output Source: https://gamlj.github.io/rosetta_contrasts.html Example output generated by the difference.emmc function. ```text ## 2 vs previous 3 vs previous 4 vs previous ## 1 -1 -0.5 -0.333 ## 2 1 -0.5 -0.333 ## 3 0 1.0 -0.333 ## 4 0 0.0 1.000 ``` -------------------------------- ### GAMLj model estimation example Source: https://gamlj.github.io/rpackage/reference/test_contrasts.html Example of fitting a linear model with GAMLj and calculating estimated marginal means. ```R data(fivegroups) fivegroups$Group <- factor(fivegroups$Group) gmod <- GAMLj3::gamlj_lm( formula = Score ~ Group, data = fivegroups ) em_means(gmod, formula = ~Group) ``` -------------------------------- ### Extracting ANOVA results Source: https://gamlj.github.io/rpackage/reference/anova.html Example showing how to fit a GAMLj linear model and extract the ANOVA table. ```R data(fivegroups) fivegroups$Group <- factor(fivegroups$Group) gmod <- GAMLj3::gamlj_lm( formula = Score ~ Group, data = fivegroups ) #> #> Attaching package: ‘jmvcore’ #> The following objects are masked from ‘package:base’: #> #> endsWith, format, startsWith anova(gmod) #> [[1]] #> #> Model Fit #> ───────────────────────────────────────────────────────────────────── #> R² Adj. R² df df (res) F p #> ───────────────────────────────────────────────────────────────────── #> 0.1472811 0.1318705 3 166 9.557137 0.0000074 #> ───────────────────────────────────────────────────────────────────── #> #> #> [[2]] #> #> ANOVA Omnibus tests #> ───────────────────────────────────────────────────────────────────────── #> SS df F p η²p #> ───────────────────────────────────────────────────────────────────────── #> Model 7.4831734 3 9.5571370 0.0000074 0.1472811 #> Group 7.4831734 3 9.5571370 0.0000074 0.1472811 #> Residuals 43.3256242 166 #> Total 50.8087976 169 #> ───────────────────────────────────────────────────────────────────────── #> #> ``` -------------------------------- ### Perform post-hoc tests on a GAMLj model Source: https://gamlj.github.io/rpackage/reference/posthoc.html Example of running a linear model with GAMLj and performing post-hoc tests on the 'Group' factor. ```R data(fivegroups) fivegroups$Group <- factor(fivegroups$Group) gmod <- GAMLj3::gamlj_lm( formula = Score ~ Group, data = fivegroups ) posthoc(gmod, formula = ~Group) ``` -------------------------------- ### Extracting estimated marginal means from a GAMLj model Source: https://gamlj.github.io/rpackage/reference/em_means.html Example showing how to fit a linear model using GAMLj and extract the estimated marginal means for a specific factor. ```R data(fivegroups) fivegroups$Group <- factor(fivegroups$Group) gmod <- GAMLj3::gamlj_lm( formula = Score ~ Group, data = fivegroups ) em_means(gmod, formula = ~Group) #> #> ESTIMATED MARGINAL MEANS #> #> Estimate Marginal Means - Group #> ────────────────────────────────────────────────────────────────────── #> Group Mean SE df Lower Upper #> ────────────────────────────────────────────────────────────────────── #> 1 0.0095455 0.0770180 166 -0.1425156 0.1616065 #> 2 -0.0905556 0.0851466 166 -0.2586653 0.0775542 #> 3 0.2531111 0.0761574 166 0.1027492 0.4034731 #> 4 0.4526667 0.0761574 166 0.3023047 0.6030286 #> ────────────────────────────────────────────────────────────────────── #> ``` -------------------------------- ### Fit a logistic regression model Source: https://gamlj.github.io/rpackage/reference/gamlj_glm.html Example of fitting a logistic regression model using the GAMLj3 package with the neuralgia dataset. ```R data <- emmeans::neuralgia GAMLj3::gamlj_glm( formula = Pain ~ Duration, data = data, model_type = "logistic" ) ``` -------------------------------- ### Get Residuals Source: https://gamlj.github.io/rpackage/articles/vignettes_gamlj_methods.html Extract residuals from the model. ```R res<-residuals(mod1) head(res) ``` -------------------------------- ### Get Predicted Values Source: https://gamlj.github.io/rpackage/articles/vignettes_gamlj_methods.html Calculate predicted values for the model. ```R preds<-predict(mod1) head(preds) ``` -------------------------------- ### R Deviation Contrast Implementation Source: https://gamlj.github.io/rosetta_contrasts.html Demonstrates setting up deviation contrasts in R by reversing the default contr.sum behavior and fitting a linear model. ```R file<-"../data/rosetta.contrasts.csv" dat<-read.csv2(file,stringsAsFactors = F) dat$Group<-factor(dat$Group) dat$Score<-as.numeric(dat$Score) ### reverse contrast sum ### contrasts(dat$Group)<-matrix(rev(contr.sum(4)),ncol=3) contrasts(dat$Group) ``` ```R ## [,1] [,2] [,3] ## 1 -1 -1 -1 ## 2 1 0 0 ## 3 0 1 0 ## 4 0 0 1 ``` ```R model<-lm(Score~Group,data=dat) summary(model) ``` ```R ## ## Call: ## lm(formula = Score ~ Group, data = dat) ## ## Residuals: ## Min 1Q Median 3Q Max ## -2.06311 -0.27955 -0.00111 0.28531 1.65733 ## ## Coefficients: ## Estimate Std. Error t value Pr(>|t|) ## (Intercept) 0.15619 0.03936 3.969 0.000107 *** ## Group1 -0.24675 0.07193 -3.430 0.000760 *** ## Group2 0.09692 0.06670 1.453 0.148092 ## Group3 0.29647 0.06670 4.445 0.000016 *** ## --- ## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 ## ## Residual standard error: 0.5109 on 166 degrees of freedom ## Multiple R-squared: 0.1473, Adjusted R-squared: 0.1319 ## F-statistic: 9.557 on 3 and 166 DF, p-value: 0.000007399 ``` ```R ## means (mm<-tapply(dat$Score, dat$Group, mean)) ``` ```R ## 1 2 3 4 ## 0.009545455 -0.090555556 0.253111111 0.452666667 ``` -------------------------------- ### Source File License Header Source: https://gamlj.github.io/rpackage/LICENSE.html Standard copyright and license notice to be placed at the beginning of each source file. ```text Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . ``` -------------------------------- ### Load qsport dataset Source: https://gamlj.github.io/rpackage/reference/qsport.html Loads the simulated qsport dataset into the R environment. ```R data(qsport) ``` -------------------------------- ### Predicting values from a linear model Source: https://gamlj.github.io/rpackage/reference/predict.html Example usage of the predict function on a GAMLj linear model object. ```R data("qsport") gmod <- GAMLj3::gamlj_lm( formula = performance ~ hours, data = qsport ) preds <- predict(gmod) ``` -------------------------------- ### Implement Post-hoc Tests with emmeans Source: https://gamlj.github.io/posthoc_specs.html This snippet demonstrates the internal logic for generating post-hoc comparisons using the emmeans package with different adjustment methods. ```R formula <- as.formula(paste('~', term)) referenceGrid <- emmeans::emmeans(private$.model, formula) bonferroni <- summary(pairs(referenceGrid, adjust='bonferroni')) holm <- summary(pairs(referenceGrid, adjust='holm')) tukey<-summary(pairs(referenceGrid, adjust='tukey')) scheffe<-summary(pairs(referenceGrid, adjust='scheffe')) sidak<-summary(pairs(referenceGrid, adjust='sidak')) ``` -------------------------------- ### Perform Post-Hoc Comparisons with emmeans Source: https://gamlj.github.io/gmixed_specs.html This snippet demonstrates how to generate a reference grid and compute pairwise comparisons with various adjustment methods for GZLM models. ```R referenceGrid <- emmeans::emmeans(model, formula) none <- summary(pairs(referenceGrid, adjust='none')) tukey <- summary(pairs(referenceGrid, adjust='tukey')) scheffe <- summary(pairs(referenceGrid, adjust='scheffe')) bonferroni <- summary(pairs(referenceGrid, adjust='bonferroni')) holm <- summary(pairs(referenceGrid, adjust='holm')) ``` -------------------------------- ### Load HSB Demo Dataset Source: https://gamlj.github.io/rpackage/reference/hsbdemo.html Loads the hsbdemo dataset into the R environment. ```R data(hsbdemo) ``` -------------------------------- ### R Omnibus test output Source: https://gamlj.github.io/rosetta_gzlmmixed1.html Example output from the car::Anova command showing Wald chi-square tests. ```text Analysis of Deviance Table (Type III Wald chisquare tests) Response: remission Chisq Df Pr(>Chisq) (Intercept) 14.918 1 0.0001123 *** IL6 24.293 1 8.273e-07 *** CRP 4.420 1 0.0355197 * CancerStage 256.523 3 < 2.2e-16 *** LengthofStay 12.982 1 0.0003145 *** Experience 19.135 1 1.218e-05 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 ``` -------------------------------- ### Inverting and Transposing a Model Matrix Source: https://gamlj.github.io/rosetta_contrasts.html Demonstrates how to derive a contrast matrix by taking the inverse of the transpose of a model matrix. ```R ### take the inverse #### ilmat<-ginv(lmat) ### transpose it ### round(t(ilmat),digits = 3) ``` -------------------------------- ### Implement Simple Contrast in R Source: https://gamlj.github.io/rosetta_contrasts.html Configures simple contrasts for a factor in R using contr.treatment. ```R #### contrast=simple ####### dat$Group<-factor(dat$Group) k<-4 # number of levels contrasts(dat$Group)<-contr.treatment(k)-(1/k) contrasts(dat$Group) ``` -------------------------------- ### Get coefficients covariances for a GAMLj model Source: https://gamlj.github.io/rpackage/reference/vcov.gamlj.html Use this method to extract the variance-covariance matrix from a fitted GAMLj model object. ```R # S3 method for class 'gamlj' vcov(object, ...) ``` -------------------------------- ### Fit a linear mixed model Source: https://gamlj.github.io/rpackage/reference/gamlj_mixed.html Example of fitting a linear mixed model using the gamlj_mixed function with a specified formula and dataset. ```R data(clustermanymodels) GAMLj3::gamlj_mixed( formula = ycont ~ 1 + x + (1 | cluster), data = clustermanymodels ) ``` -------------------------------- ### Load the beers_bars dataset Source: https://gamlj.github.io/rpackage/reference/beers_bars.html Load the simulated dataset into the R environment. ```R data(beers_bars) ``` -------------------------------- ### Define and test custom contrasts Source: https://gamlj.github.io/rpackage/reference/test_contrasts.html Basic syntax for the test_contrasts function. ```R test_contrasts(object, contrasts, ...) ``` -------------------------------- ### print(x, ...) Source: https://gamlj.github.io/rpackage/reference/s3methods.html Prints GAMLj3 objects of class 'jmvrtable', 'jmvrobj', or 'gamlj_list'. ```APIDOC ## print(x, ...) ### Description Prints the content of GAMLj3 tables or objects in R style. ### Parameters - **x** (jmvrtable/jmvrobj/gamlj_list) - Required - The object to print. - **...** (dots) - Optional - Additional arguments passed to methods. ``` -------------------------------- ### Calculate Simple Effects for a GAMLj Model Source: https://gamlj.github.io/rpackage/reference/simple_effects.html Demonstrates how to fit a mixed model using GAMLj and subsequently calculate simple effects for the interaction between time and group. ```R data(wicksell) wicksell$time <- factor(wicksell$time) wicksell$group <- factor(wicksell$group) wicksell$subj <- factor(wicksell$subj) gmod<-GAMLj3::gamlj_mixed( formula = dv ~ 1 +group+ time:group+ time+( 1 | subj ), data = wicksell) simple_effects(gmod,formula =~time:group) ``` -------------------------------- ### Create Basic Scatterplot Source: https://gamlj.github.io/rosetta_moderation.html Generate a simple scatterplot to visualize the interaction. ```SPSS GRAPH /SCATTERPLOT(BIVAR)=x WITH y BY z. ``` -------------------------------- ### Calculate Simple Contrast with emmeans Source: https://gamlj.github.io/rosetta_contrasts.html Uses the dunnett method in emmeans to perform simple contrasts. ```R model<-lm(Score~Group,data=dat) emm<-emmeans(model,~Group) contrast(emm,"dunnett",adjust = "none") ``` -------------------------------- ### Run a General Linear Model Source: https://gamlj.github.io/rpackage/reference/gamlj_lm.html Executes a linear model analysis using the ToothGrowth dataset. ```R data("ToothGrowth") GAMLj3::gamlj_lm(formula = len ~ supp, data = ToothGrowth) ``` -------------------------------- ### Summarize Model Results Source: https://gamlj.github.io/rpackage/articles/vignettes_gamlj_lm.html Render the entire results object into simple tables using the summary command. ```R summary(mod1) ``` -------------------------------- ### S3 methods for GAMLj3 classes Source: https://gamlj.github.io/rpackage/reference/s3methods.html Methods for interacting with GAMLj3 result objects, including summary, print, coefficient extraction, and model fit. ```R # S3 method for class 'ResultsElement' summary(object, ...) # S3 method for class 'gamlj_list' summary(object, ...) # S3 method for class 'jmvrtable' print(x, ...) # S3 method for class 'jmvrobj' print(x, ...) # S3 method for class 'gamlj_list' print(x, ...) # S3 method for class 'gamlj' coef(object, ...) fit(x, ...) # S3 method for class 'gamlj' fit(x, ...) ``` -------------------------------- ### Configure simple effects table labels Source: https://gamlj.github.io/rpackage/articles/vignettes_gamlj_lm.html Computes simple effects with percentile conditioning and custom labels for the moderator values. ```R se<-simple_effects(mod3,simple_x = "xage",simple_mods = "zexer",covs_conditioning="percent",covs_scale_labels="values_labels") ``` ```R se ``` -------------------------------- ### Apply and Scale Helmert Contrasts in R Source: https://gamlj.github.io/rosetta_contrasts.html Demonstrates how to reverse and rescale R's default contr.helmert to match jamovi/SPSS results. ```R dat$Group<-factor(dat$Group) contrasts(dat$Group)<-matrix(rev(contr.helmert(4)),ncol=3) con_weights<-contrasts(dat$Group) #### not scaled contrast weights ###### con_weights ``` ```R model<-lm(Score~Group,data=dat) summary(model) ``` ```R cv<-apply(con_weights,2,max)+1 cv ``` ```R coef(model)[c(2:4)]*cv ``` ```R ### make a diagonal matrix with cv in the diagonal ########## diag_cv<-matrix(rep(cv,each=4),ncol=3) ######## divide the contrast weights ########## helm<-con_weights/diag_cv ### scaled contrast weights ############ helm ``` ```R contrasts(dat$Group)<-helm model<-lm(Score~Group,data=dat) summary(model) ``` -------------------------------- ### Estimate model and generate initial plot Source: https://gamlj.github.io/rpackage/articles/vignettes_plot.html Estimate a linear model using gamlj_lm and extract a plot for the main effect of Sepal.Width. ```R mod<-gamlj_lm(formula=Sepal.Length~Sepal.Width*Petal.Length*Petal.Width, data=iris, plot_x = "Sepal.Width" ) ``` ```R plot(mod) ``` -------------------------------- ### Defining Custom Contrasts in emmeans Source: https://gamlj.github.io/rosetta_contrasts.html Shows how to define custom contrast coding by calculating the inverse of the transpose of a model matrix. ```R (rcodes<-(-1)*contr.sdif(4)) ``` ```R cont<-contrast(emm,"consec",referse=T,adjust = "none") (weigths<-coef(cont)[,2:4]) ``` ```R #### model matrix ###### rcodes ``` ```R #### transpose the R model matrix ###### tcodes<-t(rcodes) #### invert it ##### round(ginv(tcodes),digits = 3) ``` -------------------------------- ### Load and summarize exercise data Source: https://gamlj.github.io/rpackage/articles/vignettes_gamlj_lm.html Reads the exercise dataset from a remote URL and displays summary statistics for the relevant variables. ```R data<-read.csv("https://raw.githubusercontent.com/mcfanda/gamlj_docs/master/data/exercise.csv") summary(data[,c("xage","zexer","yendu")]) ``` -------------------------------- ### Initialize a Linear Model Source: https://gamlj.github.io/rpackage/articles/vignettes_gamlj_lm.html Specify the model formula and data frame to create a linear model object. ```R mod1<-gamlj_lm(formula = yendu~xage+zexer, data=data) ``` -------------------------------- ### Replicate ANOVA with R Linear Model Source: https://gamlj.github.io/rosetta_simpleint.html Sets up a linear model using lm() and performs Type II ANOVA tests via the car package. ```R data<-read.csv("../data/keppel_3way_pg466.csv",stringsAsFactors=T) data$Feedback <- car::recode(data$Feedback, "'none'='None'; 'pos'='Positive'; 'neg'='Negative'") data$Feedback<-factor(data$Feedback,levels=c("None","Positive","Negative")) data$WordType <- factor(data$WordType, levels=c("LF_LE","HF_LE","HF_HE")) contrasts(data$Grade)<-c(0,1) model<-lm(numrecall~Feedback*WordType*Grade,data=data) car::Anova(model) ``` -------------------------------- ### Load fivegroups dataset Source: https://gamlj.github.io/rpackage/reference/fivegroups.html Loads the fivegroups dataset into the R environment. ```R data(fivegroups) ``` -------------------------------- ### Load Wicksell dataset Source: https://gamlj.github.io/rpackage/reference/wicksell.html Loads the wicksell dataset into the R environment. ```R data(wicksell) ``` -------------------------------- ### Load subjects_on_stimuli dataset Source: https://gamlj.github.io/rpackage/reference/subjects_on_stimuli.html Loads the simulated dataset into the R environment. ```R data(subjects_on_stimuli) ``` -------------------------------- ### Extract residuals from a linear model Source: https://gamlj.github.io/rpackage/reference/residuals.html Demonstrates how to fit a linear model using GAMLj and extract the residuals. ```R data("qsport") gmod <- GAMLj3::gamlj_lm( formula = performance ~ hours, data = qsport ) preds <- residuals(gmod) ``` -------------------------------- ### Post-hoc Analysis Source: https://gamlj.github.io/rpackage/articles/vignettes_gamlj_methods.html Attempt to retrieve post-hoc tests or perform them by passing options to the command. ```R ph<-posthoc(mod1) ``` ```R ph ``` ```R posthoc(mod1,posthoc= ~cat3) ``` -------------------------------- ### Define Models via Terms Source: https://gamlj.github.io/rpackage/articles/vignettes_defining_model.html Specify models using the dep argument and model_terms as either a formula or a list. ```R gamlj_lm(dep=ycont,model_terms=~x*z , data=data) ``` ```R gamlj_lm(dep=ycont,model_terms=list("x","z",c("x","z")) , data=data) ``` -------------------------------- ### Load manymodels dataset Source: https://gamlj.github.io/rpackage/reference/manymodels.html Load the manymodels dataset into the R environment. ```R data(manymodels) ``` -------------------------------- ### Load Poisson Acts Dataset Source: https://gamlj.github.io/rpackage/reference/poissonacts.html Loads the poissonacts dataset into the R environment. ```R data(poissonacts) ``` -------------------------------- ### posthoc() Source: https://gamlj.github.io/rpackage/reference Performs post-hoc tests on GAMLj results. ```APIDOC ## posthoc() ### Description Calculates post-hoc tests for GAMLj model results. ```