How to pass a list of vectors with various length and list of matrices with various dimensions in Stan model?Supplying seed to Stan doesn't guarantee the same chainsHow to speed up STAN when fitting a random effect model on a large, sparse dataframe?How to define a set of vectors with various length in Stan modelMixture Models in Stan - vectorizationstan number of effective sample sizestan - difficulty vectorizingInteger matrix in stan getting flattenedHow to have a variable in the data block of Stan be an array of length J >= 1?How to update a brmsfit object with a modified brms-generated stan model marginalizing over a distribution of weightsHow to pass multiple columns of weights to brms

Why would anyone ever invest in a cash-only etf?

Can you place a support header in the ceiling?

Why force the nose of 737 Max down in the first place?

Does Wolfram Mathworld make a mistake describing a discrete probability distribution with a probability density function?

Is it okay for me to decline a project on ethical grounds?

How could Nomadic scholars effectively memorize libraries worth of information

Is there an antonym(a complementary antonym) for "spicy" or "hot" regarding food (I do NOT mean "seasoned" but "hot")?

Exploiting the delay when a festival ticket is scanned

How long until two planets become one?

Why did Windows 95 crash the whole system but newer Windows only crashed programs?

Must a song using the A minor scale begin or end with an Am chord? If not, how can I tell what the scale is?

Why is の所 used after ドア in this sentence?

How can religions be structured in ways that allow inter-faith councils to work?

What language is Raven using for her attack in the new 52?

Incrementing add under condition in pandas

Is there a wealth gap in Boston where the median net worth of white households is $247,500 while the median net worth for black families was $8?

Do 3/8 (37.5%) of Quadratics Have No x-Intercepts?

Why did some Apollo missions carry a grenade launcher?

How likely is fragmentation on a table with 40000 products likely to affect performance

Did the Americans trade destroyers in the "destroyer deal" that they would later need themselves?

Should I accept an invitation to give a talk from someone who might review my proposal?

Telling manager project isn't worth the effort?

Does dual boot harm a laptop battery or reduce its life?

Irreducible factors of primitive permutation group representation



How to pass a list of vectors with various length and list of matrices with various dimensions in Stan model?


Supplying seed to Stan doesn't guarantee the same chainsHow to speed up STAN when fitting a random effect model on a large, sparse dataframe?How to define a set of vectors with various length in Stan modelMixture Models in Stan - vectorizationstan number of effective sample sizestan - difficulty vectorizingInteger matrix in stan getting flattenedHow to have a variable in the data block of Stan be an array of length J >= 1?How to update a brmsfit object with a modified brms-generated stan model marginalizing over a distribution of weightsHow to pass multiple columns of weights to brms






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I need to pass the data as a list of vectors with various length and a list of matrices with the same number of rows but with a different number of columns. Is there a way to pass the data in Rstan?










share|improve this question



















  • 1





    There's a chapter in the Stan user's guide that explains how to pack and unpack ragged arrays. There's no native support yet, so you either have to pad as Ben suggests in his answer or encode the way described in the user's guide.

    – Bob Carpenter
    Mar 27 at 14:17











  • Thanks so much,

    – Scarlet Rice
    Mar 27 at 21:49

















0















I need to pass the data as a list of vectors with various length and a list of matrices with the same number of rows but with a different number of columns. Is there a way to pass the data in Rstan?










share|improve this question



















  • 1





    There's a chapter in the Stan user's guide that explains how to pack and unpack ragged arrays. There's no native support yet, so you either have to pad as Ben suggests in his answer or encode the way described in the user's guide.

    – Bob Carpenter
    Mar 27 at 14:17











  • Thanks so much,

    – Scarlet Rice
    Mar 27 at 21:49













0












0








0








I need to pass the data as a list of vectors with various length and a list of matrices with the same number of rows but with a different number of columns. Is there a way to pass the data in Rstan?










share|improve this question














I need to pass the data as a list of vectors with various length and a list of matrices with the same number of rows but with a different number of columns. Is there a way to pass the data in Rstan?







stan rstan rstanarm






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 26 at 19:31









Scarlet RiceScarlet Rice

1




1










  • 1





    There's a chapter in the Stan user's guide that explains how to pack and unpack ragged arrays. There's no native support yet, so you either have to pad as Ben suggests in his answer or encode the way described in the user's guide.

    – Bob Carpenter
    Mar 27 at 14:17











  • Thanks so much,

    – Scarlet Rice
    Mar 27 at 21:49












  • 1





    There's a chapter in the Stan user's guide that explains how to pack and unpack ragged arrays. There's no native support yet, so you either have to pad as Ben suggests in his answer or encode the way described in the user's guide.

    – Bob Carpenter
    Mar 27 at 14:17











  • Thanks so much,

    – Scarlet Rice
    Mar 27 at 21:49







1




1





There's a chapter in the Stan user's guide that explains how to pack and unpack ragged arrays. There's no native support yet, so you either have to pad as Ben suggests in his answer or encode the way described in the user's guide.

– Bob Carpenter
Mar 27 at 14:17





There's a chapter in the Stan user's guide that explains how to pack and unpack ragged arrays. There's no native support yet, so you either have to pad as Ben suggests in his answer or encode the way described in the user's guide.

– Bob Carpenter
Mar 27 at 14:17













Thanks so much,

– Scarlet Rice
Mar 27 at 21:49





Thanks so much,

– Scarlet Rice
Mar 27 at 21:49












1 Answer
1






active

oldest

votes


















3














The answer is essentially no, the Stan language does not allow ragged data structures such as vectors with different lengths, matrices with different numbers of columns, etc.



Depending on your application, it may be easiest to use padding or flattening. By padding I mean adding extra values to your vectors or extra columns to your matrices so that they are all the same size. It is best to use Inf or -Inf as the padded values so that it is easier to spot mistakes if they accidentally get utilized in the target log-kernel. By flattening, I mean making a single long vector by concatenating your vectors of various lengths and the same goes for vectors. Then reform them as vectors and matrices of appropriate sizes in local blocks of your Stan program. In both cases, you would also need to pass the sizes of everything as integer arrays.



Another possibility is to use some script to declare each vector or matrix that you need in the data block, even though they are different sizes. That is simple enough to do but it can be hard to generating the corresponding code to utilize each of them.






share|improve this answer

























  • Thank you. The good thing is that my list of matrices has the same number of rows so it makes the flattening easier to do.

    – Scarlet Rice
    Mar 27 at 21:50










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55364960%2fhow-to-pass-a-list-of-vectors-with-various-length-and-list-of-matrices-with-vari%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









3














The answer is essentially no, the Stan language does not allow ragged data structures such as vectors with different lengths, matrices with different numbers of columns, etc.



Depending on your application, it may be easiest to use padding or flattening. By padding I mean adding extra values to your vectors or extra columns to your matrices so that they are all the same size. It is best to use Inf or -Inf as the padded values so that it is easier to spot mistakes if they accidentally get utilized in the target log-kernel. By flattening, I mean making a single long vector by concatenating your vectors of various lengths and the same goes for vectors. Then reform them as vectors and matrices of appropriate sizes in local blocks of your Stan program. In both cases, you would also need to pass the sizes of everything as integer arrays.



Another possibility is to use some script to declare each vector or matrix that you need in the data block, even though they are different sizes. That is simple enough to do but it can be hard to generating the corresponding code to utilize each of them.






share|improve this answer

























  • Thank you. The good thing is that my list of matrices has the same number of rows so it makes the flattening easier to do.

    – Scarlet Rice
    Mar 27 at 21:50















3














The answer is essentially no, the Stan language does not allow ragged data structures such as vectors with different lengths, matrices with different numbers of columns, etc.



Depending on your application, it may be easiest to use padding or flattening. By padding I mean adding extra values to your vectors or extra columns to your matrices so that they are all the same size. It is best to use Inf or -Inf as the padded values so that it is easier to spot mistakes if they accidentally get utilized in the target log-kernel. By flattening, I mean making a single long vector by concatenating your vectors of various lengths and the same goes for vectors. Then reform them as vectors and matrices of appropriate sizes in local blocks of your Stan program. In both cases, you would also need to pass the sizes of everything as integer arrays.



Another possibility is to use some script to declare each vector or matrix that you need in the data block, even though they are different sizes. That is simple enough to do but it can be hard to generating the corresponding code to utilize each of them.






share|improve this answer

























  • Thank you. The good thing is that my list of matrices has the same number of rows so it makes the flattening easier to do.

    – Scarlet Rice
    Mar 27 at 21:50













3












3








3







The answer is essentially no, the Stan language does not allow ragged data structures such as vectors with different lengths, matrices with different numbers of columns, etc.



Depending on your application, it may be easiest to use padding or flattening. By padding I mean adding extra values to your vectors or extra columns to your matrices so that they are all the same size. It is best to use Inf or -Inf as the padded values so that it is easier to spot mistakes if they accidentally get utilized in the target log-kernel. By flattening, I mean making a single long vector by concatenating your vectors of various lengths and the same goes for vectors. Then reform them as vectors and matrices of appropriate sizes in local blocks of your Stan program. In both cases, you would also need to pass the sizes of everything as integer arrays.



Another possibility is to use some script to declare each vector or matrix that you need in the data block, even though they are different sizes. That is simple enough to do but it can be hard to generating the corresponding code to utilize each of them.






share|improve this answer













The answer is essentially no, the Stan language does not allow ragged data structures such as vectors with different lengths, matrices with different numbers of columns, etc.



Depending on your application, it may be easiest to use padding or flattening. By padding I mean adding extra values to your vectors or extra columns to your matrices so that they are all the same size. It is best to use Inf or -Inf as the padded values so that it is easier to spot mistakes if they accidentally get utilized in the target log-kernel. By flattening, I mean making a single long vector by concatenating your vectors of various lengths and the same goes for vectors. Then reform them as vectors and matrices of appropriate sizes in local blocks of your Stan program. In both cases, you would also need to pass the sizes of everything as integer arrays.



Another possibility is to use some script to declare each vector or matrix that you need in the data block, even though they are different sizes. That is simple enough to do but it can be hard to generating the corresponding code to utilize each of them.







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 27 at 1:49









Ben GoodrichBen Goodrich

3,5371 gold badge8 silver badges14 bronze badges




3,5371 gold badge8 silver badges14 bronze badges















  • Thank you. The good thing is that my list of matrices has the same number of rows so it makes the flattening easier to do.

    – Scarlet Rice
    Mar 27 at 21:50

















  • Thank you. The good thing is that my list of matrices has the same number of rows so it makes the flattening easier to do.

    – Scarlet Rice
    Mar 27 at 21:50
















Thank you. The good thing is that my list of matrices has the same number of rows so it makes the flattening easier to do.

– Scarlet Rice
Mar 27 at 21:50





Thank you. The good thing is that my list of matrices has the same number of rows so it makes the flattening easier to do.

– Scarlet Rice
Mar 27 at 21:50






Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55364960%2fhow-to-pass-a-list-of-vectors-with-various-length-and-list-of-matrices-with-vari%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript