Git Product home page Git Product logo

gorica's Introduction

lifecycle CRAN status downloads R-CMD-check

GORICA: Evaluation of Inequality Constrained Hypotheses Using Generalized AIC

Implements the generalized order-restricted information criterion approximation (GORICA). The GORICA can be utilized to evaluate (in)equality constrained hypotheses. The GORICA is applicable not only to normal linear models, but also to generalized linear models (GLMs), generalized linear mixed models (GLMMs), and structural equation models (SEMs). In addition, the GORICA can be utilized in the context of contingency tables for which (in)equality constrained hypotheses do not necessarily contain linear restrictions on cell probabilities, but instead often contain non-linear restrictions on cell probabilities.

Installation

You can install gorica from GitHub with:

# install.packages("devtools")
devtools::install_github("cjvanlissa/gorica")

Workflow

Add gorica to your existing R workflow, and evaluate informative hypotheses for your familiar R analyses! Here is an example for testing an informative hypothesis about mean differences in an ANOVA:

res <- lm(Sepal.Length ~ -1 + Species, data = iris)
gorica(res, "Speciessetosa < Speciesversicolor = Speciesvirginica; Speciessetosa < Speciesversicolor < Speciesvirginica")
#> Informative hypothesis test for an object of class lm:
#> 
#>    loglik  penalty gorica gorica_weights
#> H1 -14.948 1.500   32.897 0.000         
#> H2 5.103   1.834   -6.539 0.762         
#> Hu 5.103   3.000   -4.206 0.238         
#> 
#> Hypotheses:
#>   H1: Speciessetosa<Speciesversicolor=Speciesvirginica
#>   H2: Speciessetosa<Speciesversicolor<Speciesvirginica 
#>   Hu: Unconstrained hypothesis
#> 

gorica's People

Contributors

cjvanlissa avatar rebeccakuiper avatar

Watchers

 avatar  avatar

gorica's Issues

k-way anova door recoding factors??

Gaat opmerking in Bain tutorial ook voor ons op??
Ik hoop het niet...

opmerking in Bain tutorial:
Two-way or higher order ANOVA's can only be handled by recoding all factors into one factor. If, or example, there is a factor sex with levels man and woman, and a factor age with levels young and old, these have to be recoded in a new factor sexage with levels manyoung, manold, womanyoung, womanold

create_matrix functie via package bain

Ik heb dit als issue, zodat ik kan zien dat je dit gedaan hebt.
Dan weet ik wanneer ik met de tutorials bezig kan (omdat ik dan die van Herbert kan nabootsen).

acknowledgement restriktor + aanpassen foutmelding

De gorica package maakt in de comp() functie grotendeels gebruik van de complement code uit restriktor zonder hier een acknowledgement te plaatsen. Het is wel netjes om dit aan het pakket toe te voegen, bijvoorbeeld als comment. Daarnaast, staat in de code nog verwijzingen naar restriktor:

stop("Restriktor ERROR: no complement exists for the unrestricted hypothesis.")
en
stop("Restriktor ERROR: you might have found a bug, please contact me!")

Zou je dit willen aanpassen.

Feature: Include goric values, from goric package

Uitbreidingen die ik graag nog zie:

  • Include goric values (voor nu iig wanneer Multivariaat normal linear models – tzt wellicht voor meer type modellen, bijv ook SEM).
  1. Kan jij dat doen obv de goric R package?

Illegal lavaan syntax

In at least one of the testthat examples (test-sem_example.R), the following lavaan syntax is used:

model <- '
Cry = ~ y1 + y2 + y3 + y4
Fld = ~ y2 + y3 + y5 + y6 + y7 + y8
Cry ~ edc + age
Fld ~ edc + age
'

Note that in the first two syntax lines, there is space beteen the '=' and '~' symbols. However, lavaan's new parser will no longer allow for this. Is it possible to remove the space in this (and perhaps other) example(s)? Otherwise, it will break the testthat tests and this will prevent the new version of lavaan (0.6-17) to get through the CRAN checks.

Results: misfit en complexity anders weergeven (zie comment)

De gorica functie geeft misfit en complexity weer. Op zich is het idee prima, maar ik zou toch graag het volgende zien: fit = loglik en complexity = penalty.
Heel evt kan er in een note ergens dat gorica = -2 * fit + 2 * complexity of gorica = -2 * loglik + 2 * penalty.

Feature: Gorica for contingency tables

  • Straks contingency table code (levert Yasin aan) – dus code specifiek voor bepaalde type modellen (contingency tables en evt multinomial regression).
    Btw, then link functions (e.g., from prob’s to odds ratios), but can be easily handed in text.

Test against complement of hypotheses

Also incorporate the functionality of evaluating a hypothesis against its complement (and if more than one substantive hypothesis: also the complement of the set).

description/help file: lavaan & standardize=TRUE

Ik kon zo snel niet zien dat er een beschrijving staat bij de gorica mbt het lavaan object. Zo weet de gebruiker ook niet dat er een 'standardize=TRUE' optie/command is...
Zie evt code hieronder.

Load the gorica and lavaan libraries.

if (!require("gorica")) install.packages("gorica") # install this package first (once)
if (!require("lavaan")) install.packages("lavaan") # install this package first (once)
library(gorica)
library(lavaan)

Specify the latent regression model

model2 <- '
A =~ Ab + Al + Af + An + Ar + Ac
B =~ Bb + Bl + Bf + Bn + Br + Bc
A ~ B + age + peabody
'

Fit the latent regression model using the lavaan sem function

fit2 <- sem(model2, data = sesamesim, std.lv = TRUE)

Formulate hypotheses

hypotheses2 <- "
AB > Apeabody = Aage = 0;
A
B > Apeabody > Aage = 0;
AB > Apeabody > A~age > 0
"

Call gorica

Note: because more than 1 hypothesis, we cannot use: comparison = "complement"

set.seed(100)
out2_c <- gorica(fit2, hypotheses2, standardize=TRUE)
out2_c

Complement alleen als 1 hypothese

Op dit moment is er alleen code om de resultaten van 1 hypothese vs zijn complement te bepalen en niet voor een set van hypotheses. Toen ik het deed voor meer dan een hypothese, dan geeft het wel output. Op zich geeft het de output met de unconstrained, alleen is er geen melding dat dit gebeurd en daarnaast staat er in de output ook dat het de complement is...
Kan je een foutmelding inbouwen. Als je daarnaast ook de resultaten wilt geven met de unconstrained dan moet de hypothese daar aangepast worden (niet Hc en ook niet de omschrijving - zie hieronder).

Hieronder vind je code en output.

Load the gorica and lavaan libraries.

if (!require("gorica")) install.packages("gorica") # install this package first (once)
if (!require("lavaan")) install.packages("lavaan") # install this package first (once)
library(gorica)
library(lavaan)

Specify the latent regression model

model2 <- '
A =~ Ab + Al + Af + An + Ar + Ac
B =~ Bb + Bl + Bf + Bn + Br + Bc
A ~ B + age + peabody
'

Fit the latent regression model using the lavaan sem function

fit2 <- sem(model2, data = sesamesim, std.lv = TRUE)

Formulate hypotheses

hypotheses2 <- "
AB > Apeabody = Aage = 0;
A
B > Apeabody > Aage = 0;
AB > Apeabody > A~age > 0
"

Call gorica

Note: because more than 1 hypothesis, we cannot use: comparison = "complement"

set.seed(100)
out2_c <- gorica(fit2, hypotheses2, comparison = "complement", standardize=TRUE)
out2_c

OUTPUT:

Informative hypothesis test for an object of class lavaan:

loglik penalty gorica gorica_weights
H1 6.836 0.504 -12.663 0.370
H2 6.836 0.691 -12.290 0.307
H3 6.836 0.823 -12.026 0.269
Hc 6.894 2.496 -8.798 0.054

Hypotheses:
H1: AB>Apeabody=Aage=0
H2: A
B>Apeabody>Aage=0
H3: AB>Apeabody>A~age>0
Hc: Complement of the hypothesis

Standardizing predictors

How to handle this? lm includes data, which can be standardized and the model re-run. Other model objects do not include data.

Feature: Range restricted hypotheses

Rebecca: Include ‘c’ as option, then range restristrictions (like 0 < mu1 < 5) possible (but dependent on c). Kan ik tzt meer uitleg over geven. Code hiervoor ligt er nog niet, dit is voor in de verdere toekomst 😊.

Methods for Mplus and Lavaan

  • You also make this available for Mplus input (via Mplus automation) and make sure the estimates have names assigned etc.
    Could you also then standardize the data and re-run the model?
  • You also make this available for Lavaan objects (like you will do for Bain).

Feature: Link functions in hypothesis string

  1. De hypotheses kunnen nu in termen van namen worden gegeven, maar kan je daarbij ook ‘(link) functies’ maken. Hieronder een voorbeeld wat je bijv in restriktor kan:
    myConstraints <- ’
    m1 := .Intercept.
    m2 := .Intercept. + facialBurns
    m3 := .Intercept. + gender
    m4 := .Intercept. + facialBurns + gender + gender.facialBurns
    m1 < m4
    m2 < m4
    m3 < m4 ’
    Kan iets soortgelijks ook in de gorica? Of kan het alleen maar obv de namen van de variabelen?

Opgeven aantal iteraties in bepalen penalty

Is het mogelijk om het aantal iteraties in het bepalen van de penalty op te geven?
Zo ja, hoe en kan dat in de description/help file worden toegevoegd.
Zo nee, kan je dat realiseren (en dan toevoegen aan help file)?

Matrix interface for gorica

Rebecca: Ik doe ook iets met ‘combining evidence’. Waarschijnlijk zal ik nog steeds moeten wennen, maar hier lijkt mij het opgeven van restricties in matrices handiger dan in woorden (of anders gezegd: hier lijkt me het opgeven van de parameters voor elk van de studies in de evidence synthesis voorzien van namen in een shiny app erg onhandig). Ik kan dat natuurlijk achter de schermen doen, maar dat is een beetje suf: van restrictiematrix naar hypothese in woorden en dan in jouw deel (dus de gorica R package) weer andersom. Heel misschien moeten we kijken wat we al kunnen inbouwen in de gorica voor wat betreft combining evidence…. Maar dat is weer wat meer (maar komt wel weer een artikel uit met simulaties…).

Fout in bepalen PT van compl

Bijgevoegd een file waar je kan zien dat het fout gaat: Ik zal het e-mailen, want ik krijg melding dat deze type file niet gesupport wordt...

Ik krijg zelfs een negatieve penalty voor het complement (en het zou iets dicht bij 12 moeten zijn, iig tussen 0 en 12)...
Ik heb ik restriktor geprobeerd met soortgelijke hypo en dan in een regressie model en daar gaat penalty bepalen voor het complement wel goed; dus ik denk dat het ergens in jouw code zit.... Wellicht moet je code van restriktor aanroepen??

Output: relative weigth (zie comment)

Ook een matrix maken (van relative weights) zoals bain met BFmatrix.
Dat evt alleen opvraagbaar, maar mag ook standaard output zijn.

Evt mbt "Ik wil bijv, als lik = max lik is, aangeven wat max relative weight is of zeggen dat er nu een max is tov hypo’s met zelfde lik.":
Dan in rel weight matrix aangeven welke hun max hebben (nl als gelijke LL, dus ook als twee gelijk hebben maar ll niet max is).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.