[Rsiena-help] Loop in "sienaDataCreate"
Tom Snijders
Tom.Snijders at nuffield.ox.ac.uk
Fri Jun 22 12:22:11 CEST 2012
Dear Ruth,
That is a wonderful way to do it. I had been trying to work with vectors or lists of strings that were not accepted in sienaDataCreate, and therefore responded with the simpler shortcutting way. I'll try to remember this way of using variable names (if that is the proper way to abbreviate what's going on here).
Best,
Tom
================================================================
Tom A.B. Snijders
Professor of Statistics in the Social Sciences
Department of Politics and Department of Statistics
Nuffield College
University of Oxford
tel. +44-01865-278599
-----Original Message-----
From: rsiena-help-bounces at lists.r-forge.r-project.org [mailto:rsiena-help-bounces at lists.r-forge.r-project.org] On Behalf Of Ruth Ripley
Sent: 22 June 2012 11:16
To: rsiena-help at lists.r-forge.r-project.org
Subject: Re: [Rsiena-help] Loop in "sienaDataCreate"
Dear Philippe,
Two apologies: first, I did not reply to the list and second, I omitted sep="" from the code. I repeat my reply (with the corrected code) below for others' benefit.
sienaDataCreate uses the name of the object unless you supply another name. The supplied name cannot be varied by using a character variable.
You could use something like
mydata.basic.model <- list();
for (i in c(1:5))
{
mycall <- paste("sienaDataCreate(peers", i, "=peers[[i]])", sep="")
mydata.basic.model[[i]] <- eval(parse(text=mycall))}
which should give peers1 ... as the names of the networks. ([[ does not work in this context but I doubt it is an important part of the name.)
The idea here is to create a character string that represents the function call you would like to execute, parse it to make it an expression rather than a character string and then eval it.
Regards,
Ruth
On 21/06/2012 17:50, Philippe Sulger wrote:
> Dear all
>
> I try to program a loop over 5 different networks. Therein I use
> "sienaDataCreate". E.g.:
>
> mydata.basic.model <- list();
>
> for (i in c(1:5))
> {mydata.basic.model[[i]] <- sienaDataCreate(peers[[i]])}
>
> Where "peers" is defined/specified previously as a list over networks s.t.
>
> peers <- list()
>
> for (i in c(1:5))
> {peers[[i]] <- sienaNet(
> array( c(peers.data.w1[[i]], peers.data.w2[[i]]),
> dim = c( dim(peers.data.w1[[i]])[1],
> dim(peers.data.w2[[i]])[1], 2)))}
>
> The latter loop works. The former loop does not work. That is,
> mydata.basic.model[[1]], for instance, gets "peers[[i]]" as dependent
> variable (instead of "peers[[1]]". The same for the other networks.
>
> But if I define the model-data separately for each network, i.e.,
>
> mydata.basic.model[[1]] <- sienaDataCreate(peers[[1]])
> mydata.basic.model[[2]] <- sienaDataCreate(peers[[2]])
>
> it works.
>
> What goes wrong?
>
> Thank you for your efforts.
>
> Best
> Philippe
>
>
> This body part will be downloaded on demand.
>
_______________________________________________
Rsiena-help mailing list
Rsiena-help at lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rsiena-help
Nuffield College is a Registered Charity No. 1137506. Registered Office: Nuffield College, New Road, Oxford, OX1 1NF
More information about the Rsiena-help
mailing list