need to clarify why vector=TRUE not used in the unweighted model

To generate a weighted likelihood, you need row likelihoods, and to weight and sum each of these to form a single number (likelihood) that can be the ultimate objective of.

You say that firstModel.objective "is calculated differently (not with vector=TRUE) because it was not working for me."

You have to get a row-vector out of that first model. It is those individual likelihoods for each row that will be weighted. So you need to get that working.
Post here for help (post the full model script, and the data if you can).

Good day,
Firstly, Thank you for providing a response.

I attached a portion of the data set (samp.txt), the data set is much longer but even with this smaller version, I was not able to extract the likelihood vector.

At the moment, the biggest issue is getting the likelihood vector when vector=TRUE. In my previous analysis, I did not incorporate the weights in myData so I am going to do that in the renewed analysis. The labels of the parameters are not fully specified in the code but I don't think that is the reason of the issue.

The code is:

library(foreign)
samp <- read.table("samp.txt",header=TRUE)
nsamp <- names(samp)
example1 <- mxModel("examp1",
# factor loadings
mxMatrix("Full", nrow=6, ncol=1,
values=c(1,rep(0.8,5)),
free=c(FALSE,rep(TRUE,5)), lbound = c(NA,rep(0.01,5)),
name="A"),
# specify the factor intercorrelation matrix
mxMatrix("Symm", nrow=1, ncol=1, values=2, free=TRUE, lbound = 0.01, name="L"),
# specify the matrix of unique item variances
mxMatrix("Diag", nrow=6, ncol=6, values=rep(0.8,6), free=TRUE, lbound = rep(0.01,6), name="U"),
# specify the algebra that results in the model expectations
mxAlgebra(A %% L %% t(A) + U,
name="Covar1"
),
# specify a model for the means
mxMatrix("Full", nrow=1, ncol=6,
values=c(rep(3.5,6)), free=TRUE, lbound = rep(0.01,6),
name="Mean1"
),
# choose the full information maximum likelihood objective function
mxFIMLObjective(covariance="Covar1", means="Mean1",dimnames=nsamp,vector=TRUE),
# attach the data to the model
mxData(samp, type="raw")
)

model1 <- mxRun(example1)
stat <- summary(model)

It then gives a warning message:
In model 'examp1' NPSOL returned a non-zero status code 1. The final iterate satisfies the optimality conditions to the accuracy requested, but the sequence of iterates has not yet converged. NPSOL was terminated because no further improvement could be made in the merit function (Mx status GREEN).

I saw in a number of threads that there are a number of factors as to why the warning measage emerges, e.g. modifying starting values and providing lower bounds. I tried to use differing starting values and lower bounds but the warning message is still present.

As to getting the likelihood vector from another source, I used the code from this OpenMX link about FIML specification (I did not put the code because it could be too long): http://openmx.psyc.virginia.edu/docs/openmx/latest/fiml_rowobjective.html. It is underneath the page, starting with model specification and ending with model fitting. I extracted the likelihood vector from one of its output.

I hope I provided sufficient information to tackle this problem. Thank you.

samp <-read.table("samp.txt",header=TRUE)
nsamp <-names(samp)
samp$weight <-runif(nrow(samp))# Your sample weights!!!
example1 <- mxModel("examp1",
# factor loadings
mxMatrix("Full", nrow=6, ncol=1,
values=c(1,rep(0.8,5)),
free=c(FALSE,rep(TRUE,5)), lbound =c(NA,rep(0.01,5)),
name="A"),
# specify the factor intercorrelation matrix
mxMatrix("Symm", nrow=1, ncol=1, values=2, free=TRUE, lbound =0.01, name="L"),
# specify the matrix of unique item variances
mxMatrix("Diag", nrow=6, ncol=6, values=rep(0.8,6), free=TRUE, lbound =rep(0.01,6), name="U"),
# specify the algebra that results in the model expectations
mxAlgebra(A %*% L %*%t(A)+ U,
name="Covar1"),
# specify a model for the means
mxMatrix("Full", nrow=1, ncol=6,
values=c(rep(3.5,6)), free=TRUE, lbound =rep(0.01,6),
name="Mean1"),
# choose the full information maximum likelihood objective function
mxFIMLObjective(covariance="Covar1", means="Mean1",dimnames=nsamp,vector=TRUE))
example1a <- mxModel(model="Container", example1,
# attach the data to the model
mxData(samp, type="raw"),
# Algebra for weights
mxAlgebra(-2*sum(data.weight%x%log(examp1.objective)), name ="obj"),
mxAlgebraObjective("obj"))
model1a <- mxRun(example1a)
stat <-summary(model1a)
stat

Instead of sampling weights, is it possible to use kernel weights to perform kernel regression? I am trying to provide smooth trends of factor model parameters through kernel smoothing and I was wondering if this also applies for kernel weights.

To generate a weighted likelihood, you need row likelihoods, and to weight and sum each of these to form a single number (likelihood) that can be the ultimate objective of.

You say that firstModel.objective "is calculated differently (not with vector=TRUE) because it was not working for me."

You have to get a row-vector out of that first model. It is those individual likelihoods for each row that will be weighted. So you need to get that working.

Post here for help (post the full model script, and the data if you can).

You also need to ensure that "myData" contains the column "weight"

> The unweighted model works, but there were issues with extracting the likelihood vector when vector=TRUE

that's the problem to be clear about: what do you mean "issues"? firstModel.objective didn't contain the row likelihoods?

> I then decided to use another code from the website

> (using the formula of row-likelihood)

> and I was able to extract the likelihoods with it.

Which was that?

Good day,

Firstly, Thank you for providing a response.

I attached a portion of the data set (samp.txt), the data set is much longer but even with this smaller version, I was not able to extract the likelihood vector.

At the moment, the biggest issue is getting the likelihood vector when vector=TRUE. In my previous analysis, I did not incorporate the weights in myData so I am going to do that in the renewed analysis. The labels of the parameters are not fully specified in the code but I don't think that is the reason of the issue.

The code is:

library(foreign)

samp <- read.table("samp.txt",header=TRUE)

nsamp <- names(samp)

example1 <- mxModel("examp1",

# factor loadings

mxMatrix("Full", nrow=6, ncol=1,

values=c(1,rep(0.8,5)),

free=c(FALSE,rep(TRUE,5)), lbound = c(NA,rep(0.01,5)),

name="A"),

# specify the factor intercorrelation matrix

mxMatrix("Symm", nrow=1, ncol=1, values=2, free=TRUE, lbound = 0.01, name="L"),

# specify the matrix of unique item variances

mxMatrix("Diag", nrow=6, ncol=6, values=rep(0.8,6), free=TRUE, lbound = rep(0.01,6), name="U"),

# specify the algebra that results in the model expectations

mxAlgebra(A %

% L %% t(A) + U,name="Covar1"

),

# specify a model for the means

mxMatrix("Full", nrow=1, ncol=6,

values=c(rep(3.5,6)), free=TRUE, lbound = rep(0.01,6),

name="Mean1"

),

# choose the full information maximum likelihood objective function

mxFIMLObjective(covariance="Covar1", means="Mean1",dimnames=nsamp,vector=TRUE),

# attach the data to the model

mxData(samp, type="raw")

)

model1 <- mxRun(example1)

stat <- summary(model)

It then gives a warning message:

In model 'examp1' NPSOL returned a non-zero status code 1. The final iterate satisfies the optimality conditions to the accuracy requested, but the sequence of iterates has not yet converged. NPSOL was terminated because no further improvement could be made in the merit function (Mx status GREEN).

I saw in a number of threads that there are a number of factors as to why the warning measage emerges, e.g. modifying starting values and providing lower bounds. I tried to use differing starting values and lower bounds but the warning message is still present.

As to getting the likelihood vector from another source, I used the code from this OpenMX link about FIML specification (I did not put the code because it could be too long): http://openmx.psyc.virginia.edu/docs/openmx/latest/fiml_rowobjective.html. It is underneath the page, starting with model specification and ending with model fitting. I extracted the likelihood vector from one of its output.

I hope I provided sufficient information to tackle this problem. Thank you.

metavid

Here is a full working example

It works. Again, thank you for providing a solution to my second question!

Good day,

Instead of sampling weights, is it possible to use kernel weights to perform kernel regression? I am trying to provide smooth trends of factor model parameters through kernel smoothing and I was wondering if this also applies for kernel weights.

Thank you.

metavid