Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transformations, where the transformed parameter is not used in the model, do not work #313

Open
jhorzek opened this issue May 2, 2023 · 1 comment

Comments

@jhorzek
Copy link
Owner

jhorzek commented May 2, 2023

The following does not work:

library(lessSEM)

# Identical to regsem, lessSEM builds on the lavaan
# package for model specification. The first step
# therefore is to implement the model in lavaan.

dataset <- simulateExampleData()

lavaanSyntax <- "
f =~ l1*y1 + l2*y2 + l3*y3 + l4*y4 + l5*y5 + 
     l6*y6 + l7*y7 + l8*y8 + l9*y9 + l10*y10 + 
     l11*y11 + l12*y12 + l13*y13 + l14*y14 + l15*y15
f ~~ 1*f
"

lavaanModel <- lavaan::sem(lavaanSyntax,
                           data = dataset,
                           meanstructure = TRUE,
                           std.lv = TRUE)

# Regularization:

lsem <- lasso(
  # pass the fitted lavaan model
  lavaanModel = lavaanModel,
  # names of the regularized parameters:
  regularized = paste0("l", 6:15),
  # in case of lasso and adaptive lasso, we can specify the number of lambda
  # values to use. lessSEM will automatically find lambda_max and fit
  # models for nLambda values between 0 and lambda_max. For the other
  # penalty functions, lambdas must be specified explicitly
  nLambdas = 50)

# use the plot-function to plot the regularized parameters:
plot(lsem)

transformation <- "
parameters: l3, l4, lprod
lprod= l3 * l4;
"

lsem <- lasso(
  # pass the fitted lavaan model
  lavaanModel = lavaanModel,
  # names of the regularized parameters:
  regularized = paste0("l", 6:15),
  # in case of lasso and adaptive lasso, we can specify the number of lambda
  # values to use. lessSEM will automatically find lambda_max and fit
  # models for nLambda values between 0 and lambda_max. For the other
  # penalty functions, lambdas must be specified explicitly
  lambdas = seq(0,1,.1),
  modifyModel = modifyModel(transformations = transformation))
coef(lsem)
lsem@transformations

Such transformations could be useful for path tracing rules, but we cannot regularize lprod anyway, so I will not implement these transformations for the time being. We could add a warning to let users know.

@jhorzek
Copy link
Owner Author

jhorzek commented Jan 9, 2024

Maybe we could check if something that the user puts in as a parameter (here: lprod) gets retuned with a different value by the transformation function. That is, lessSEM expects that all SEM parameters (e.g., l1, l2) can be a function of other parameters. However, non-SEM parameters (lprod) are not allowed to be functions of other parameters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant