[R] Using eval in multinom argument

Crouch, Daniel daniel.crouch at kcl.ac.uk
Mon Feb 16 17:21:08 CET 2009


Hi,

I am having difficulty entering a 'programmable' argument into the multinom function from the nnet package. Interactively, I can get the function to work fine by calling it this way:

z1=multinom(formula = class.ind(grp[-outgroup])~ (PC1 + PC2 + PC3), data=data.frame(scores))

However I need to be able to change the number of variables I am looking for in 'scores' and so am trying to call it this way...

z1=multinom(formula = class.ind(grp[-outgroup])~ eval(parse(text=PCnames)), data=data.frame(scores))

...where, for example, PCnames = c("PC1", "+",   "PC2", "+",   "PC3")   

This gives no error messages, but only the last variable (in this case PC3) gets considered in the model. z1 looks like this:

  (Intercept) eval(parse(text = PCnames))
2    3.530352                  -116.87140
3   -1.308613                    13.59134
4    3.662172                   -57.52198
5   -1.216041                  -242.38827
6   -9.377894                  -367.71614
7   -3.145738                  -286.19766

Rather than this:

  (Intercept)       PC1        PC2       PC3
2   288.97131   889.281  3776.5837 -2105.751
3  -712.53519  2775.663  8490.5724  8602.834
4   229.17772  4234.950   329.6995 -2182.238
5    85.54585 -3036.657  3968.2517 -3450.070
6  -676.55377 -9545.785  2422.5340 -7183.686
7  -631.91921 10997.432 -3310.2905 -5348.513

Any help would be much appreciated.

Thanks,
Daniel Crouch


Daniel Crouch
Research Student
Department of Medical & Molecular Genetics
King's College London
8th Floor, Tower Wing
Guy's Hospital
London SE1 9RT
United Kingdom



More information about the R-help mailing list