0

I'm a beginner R programmer struggling with a multivariate array problem.

I'm attempting to input an array of 4 parameter values, say a=1:10, b=1:10, p=1:10, q=1:10, into a function y=f(x|a, b, p, q) that calculates values of y based on my dataset, x, and every possible combination of the given 4 parameters [(a=1,b=1,p=1,q=1),(a=2,b=1,p=1,q=1),...,(a=10,b=1,p=1,q=1),...,(a=10,b=10,p=10,q=10)] = 10^4 = 10,000 possible combinations and therefore 10,000 y values.

Ideally I'd like the output to be in an array format which I can then graph in R, allowing each parameter to be plotted as a separate axis.

If anyone could point me in the right direction it would be much appreciated!

Thanks,

Robert

3
  • 3
    Robert, no disrespect intended, but you're not really asking a question. There are a number of steps needed to do what you're asking and it's impossible to tell from your question where you are hung. The best beginner R skill you can grab right now is decomposing your problem into steps. Then try to do each step. If you can't do a step, break that into a single question and show a simple example of what you want and what you've tried. Commented Apr 6, 2011 at 21:23
  • agreed with JD. In trying to compose an answer, I realized that I'm pretty much going to end up coding every step. Commented Apr 6, 2011 at 22:32
  • Yes, sorry about that, should have been more clear. I'm trying to map out the negative log-likelihood of a four parameter probability distribution (the Generalized Beta of the 2nd Kind) to help me find the best fit (= minimum negative log-likelihood) to my insurance claims data. There are various iterative algorithms available in SAS and R, but I've been having problems with them producing stable results as I vary the values of the initial parameters. So I'm going with the "eyeball" approach to locate the best initial parameters. Commented Apr 12, 2011 at 13:18

1 Answer 1

2

I agree with JD Long that the request is too vague to allow a final answer, but there is an answer to the first part:

all.comb.dfrm  <- expand.grid(a=1:10, b=1:10, p=1:10, q=1:10)
all.comb.dfrm$Y <- with(all.comb.dfrm, f(a,b,p,q) )
Sign up to request clarification or add additional context in comments.

1 Comment

I literally typed an identical answer with different object names. Beat me to the punch! +1

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.