0
$\begingroup$

I would like to extract coefficients of indexed variables from a large sum. The following is an example motivated by linear regression to illustrate the problem.

Consider the (unnormalised) log likelihood of a linear regression problem with design matrix X, observations y, and regression parameters w given by

logLikelihood = -gamma / 2 * Sum[(y[i] - Sum[X[i, j] w[j], {j, 1, p}]) ^ 2, {i, 1, n}]

I would like to use Mathematica to extract coefficients of indexed variables from the log-likelihood. For example, I would like to apply

SomeFunction[logLikelihood, w[k]^2]

and get the following result

- gamma / 2 * Sum[X[i,k] ^ 2, {i, 1, n}]

I have tried Coefficient and differentiating with respect to the variable of interest but both are not quite working as I would like.

$\endgroup$
3
  • $\begingroup$ Are n and p left as a variables, or do you plug in numbers for them? $\endgroup$
    – march
    Commented Dec 10, 2015 at 22:18
  • $\begingroup$ I would like to leave n and p as variables. $\endgroup$ Commented Dec 10, 2015 at 22:19
  • $\begingroup$ You might want to look at mathematica.stackexchange.com/questions/65471/…. $\endgroup$
    – JimB
    Commented Dec 10, 2015 at 22:36

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.