DPCGadget: Shiny gadget for editinging compensatory pnodes

View source: R/shinyNode.R

DPCGadgetR Documentation

Shiny gadget for editinging compensatory pnodes

Description

These functions open a shiny application (in a browser window or other location) for editing a Pnode object. This is the most complex version taking advantage of all of the complex choices available using the partial credit link (i.e., PnodeLink(pnode) is partialCredit). In particular, it allows specification of different combination rules for each state transition. The rules can be either the multiple-a type (e.g., Compensatory) or muliptle-b type (e.g., OffsetConjunctive or OffsetDisjunctive). It even allows for a subset of parents to be used in each transition by specifying an inner Q-matrix (though PnodeQ). To manage this complexity, each transition is displayed on a separate tab of the interface.

Usage

MakeDPCGadget(pnode, color = "steelblue")
DPCGadget(pnode, color="steelblue",viewer=shiny::paneViewer())

Arguments

pnode

A Pnode object to be modified.

color

A base color to use for barcharts (see barchart.CPF). Execute colors() for a list of choices.

viewer

This is passed to the viewer argument of shiny::runGadget.

Details

The DPCGadget assumes that:

  • The link function is partialCredit.

  • There is a list of rules, one for each state transition (i.e., one for all states except the last and lowest value. Alternatively, if a single value is given it is used for all transitions.

  • The value of PnodeQ(pnode) is a logical matrix with rows corresponding to state transitions and columns corresponding to parent variables. If any cell value is false, that parent variable is not used to calculate the effective theta for that cell transition. As a special case, if PnodeQ(pnode) equals TRUE, then it is considered to be a matrix with all elements true.

Both PnodeAlphas(node) and PnodeBetas(node) should be a list of vectors. The length of each vector should be either one or the number of relevant (after filtering with the inner Q-matrix) parent variables. Which it needs to be depends on whether the rule for that transition is a multiple-a type (alphas should match number of parents) or multiple-b type (betas should match number of parents). In either case, if a single value is given and a longer list is expected, it will be replicated across the parents. The length of the lists should match the state transitions (with the first one corresponding to the transition from the 2nd highest state to the highest, the second the transition to the 2nd highest state and so forth). No entry is needed for the lowest state. Once again, if a single vector is given in place of the list, it will be replicated as needed.

To recap, the outer (list) structure corresponds to state transitions and the inner (vector) structure corresponds to the parent variables. It is recommended to use labeled vectors and lists to annotate the structure.

Value

The function MakeDPCGadget returns a list of two functions, ui and server. These are meant to be passed to shiny::runApp to generate the actual app.

The function DPCGadget will return the pnode object or throw a ‘Cancel-Error’.

Author(s)

Russell Almond

References

Almond, R. G. (2015) An IRT-based Parameterization for Conditional Probability Tables. Paper presented at the 2015 Bayesian Application Workshop at the Uncertainty in Artificial Intelligence Conference.

See Also

Pnode, calcDPCFrame, barchart.CPF

OffsetGadget, RegressionGadget, CompensatoryGadget

Examples

## Not run: 
library(PNetica) ## Requires implementation
sess <- NeticaSession()
startSession(sess)

tNet <- CreateNetwork("TestNet",sess)

theta1 <- NewDiscreteNode(tNet,"theta1",
                         c("VH","High","Mid","Low","VL"))
PnodeStateValues(theta1) <- effectiveThetas(PnodeNumStates(theta1))
PnodeProbs(theta1) <- rep(1/PnodeNumStates(theta1),PnodeNumStates(theta1))
theta2 <- NewDiscreteNode(tNet,"theta2",
                         c("VH","High","Mid","Low","VL"))
PnodeStateValues(theta2) <- effectiveThetas(PnodeNumStates(theta2))
PnodeProbs(theta2) <- rep(1/PnodeNumStates(theta1),PnodeNumStates(theta2))

## DPCGadget

partial3 <- NewDiscreteNode(tNet,"partial3",
                            c("FullCredit","PartialCredit","NoCredit"))
PnodeParents(partial3) <- list(theta1,theta2)

## Usual way to set rules is in constructor
partial3 <- Pnode(partial3,rules="Compensatory", link="partialCredit")
PnodePriorWeight(partial3) <- 10
BuildTable(partial3)

partial3 <- DPCGadget(partial3)

## This expression can be used inside an Rmarkdown document
gadget <- MakeDPCGadget(partial3)
shinyApp(gadget$ui,gadget$server,options(height=2000))

## More complex example showing off some of the options:
## Set up so that first skill only needed for first transition, second
## skill for second transition; Adjust alphas to match
PnodeQ(partial3) <- matrix(c(TRUE,TRUE,
                             TRUE,FALSE), 2,2, byrow=TRUE)
PnodeLnAlphas(partial3) <- list(FullCredit=c(theta1=-.25,theta2=.25),
                                PartialCredit=0)

partial3 <- DPCGadget(partial3)


DeleteNetwork(tNet)
stopSession(sess)

## End(Not run)


ralmond/Peanut documentation built on Sept. 19, 2023, 8:27 a.m.