0

I'm just trying to learn how to use the nlsem package in R to fit nonlinear SEMM, but I keep running into to the error "Posterior probability could not be calculated properly. Choose different starting parameters" when I try to create the res object. I'm trying to estimate a nonlinear model where latent variable tas predicts latent variable cts, moderated by latent variable ams. I'm still pretty new to R and very new to nonlinear analyses, so any help at all would be appreciated!

My code so far:

    ##nonlinear SEM
    #Select data
    FPerpSEMM<-subset(FPerp,
                select=(c("tas1", "tas3", "tas6", "tas7", "tas9", "tas13","tas14", "AMSEscalate",
                          "AMSNegAttribution", "AMSSelfAware", "AMSCalming", "cts_5", "cts_25", 
                          "cts_29", "cts_35", "cts_49", "cts_65", "cts_67", "cts_69")))
    FPerpSEMM$x1<-FPerpSEMM$tas1
    FPerpSEMM$x2<-FPerpSEMM$tas3
    FPerpSEMM$x3<-FPerpSEMM$tas6
    FPerpSEMM$x4<-FPerpSEMM$tas7
    FPerpSEMM$x5<-FPerpSEMM$tas9
    FPerpSEMM$x6<-FPerpSEMM$tas13
    FPerpSEMM$x7<-FPerpSEMM$tas14
    FPerpSEMM$x8<-FPerpSEMM$AMSEscalate
    FPerpSEMM$x9<-FPerpSEMM$AMSNegAttribution
    FPerpSEMM$x10<-FPerpSEMM$AMSSelfAware
    FPerpSEMM$x11<-FPerpSEMM$AMSCalming
    FPerpSEMM$y1<-FPerpSEMM$cts_5
    FPerpSEMM$y2<-FPerpSEMM$cts_25
    FPerpSEMM$y3<-FPerpSEMM$cts_29
    FPerpSEMM$y4<-FPerpSEMM$cts_35
    FPerpSEMM$y5<-FPerpSEMM$cts_49
    FPerpSEMM$y6<-FPerpSEMM$cts_65
    FPerpSEMM$y7<-FPerpSEMM$cts_67
    FPerpSEMM$y8<-FPerpSEMM$cts_69
    FPerpSEMMr1<-subset(FPerpSEMM,
                      select=(c("x1","x2","x3","x4","x5","x6","x7","x8","x9","x10","x11",
                                "y1","y2","y3","y4","y5","y6","y7","y8")))
    #Create dataframe containing only complete cases
    FPerpSEMMcc<-na.omit(FPerpSEMMr1) 
    # load data
    dat <- as.matrix(FPerpSEMMcc[, c(12:19, 1:7, 8:11)])
    # specify model of class SEMM
    model<- specify_sem(num.x = 11, num.y = 8, num.xi = 2, num.eta = 1,
                         xi = "x1-x7,x8-x11", eta = "y1-y8",
                     num.classes = 3, interaction = "xi1:xi2", rel.lat = "eta1~xi1+xi2",
                constraints = "direct1")
    class(model)
    #fit model
    dat <- as.matrix(FPerpSEMMcc[, c(12:19, 1:7, 8:11)])
    set.seed(911)
    pars.start <- runif(count_free_parameters(model))
    res <- em(model, dat, pars.start, convergence = 0.1, max.iter = 200)
    summary(res)
    plot(res)
bcd
  • 1
  • Hi bcd, it would be easier to help if you provide `FPerp` such as with `dput()`. See more at [How to make a reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – Ian Campbell Mar 26 '20 at 22:16
  • Thank you for the quick response! When I try to include the output from dput(FPerp) in my post, I run out of room to include it by several thousand characters. Is there any way I can cut it down and it still be useful? – bcd Mar 31 '20 at 16:14
  • Maybe try `dput(FPerp[1:50,])`? – Ian Campbell Mar 31 '20 at 16:48
  • Thank you, but it's still way to long. I'm not sure I'm going to be able to cut this down enough to post and it still be anything useful. Do you know anywhere else I might be able to post this question that might have a higher character limit? – bcd Apr 01 '20 at 16:21
  • If there is no personally identifiable / human subjects research data nor anything you are worried about anyone stealing, you could just upload the whole data file to GitHub. – Ian Campbell Apr 01 '20 at 16:34

0 Answers0