Re: [R] Deparse substitute assign with list elements

2015-05-15 Thread soeren . vogel
Thanks, Bill, I should have googled more carefully: http://stackoverflow.com/questions/9561053/assign-values-to-a-list-element-in-r So, remove assign(nm, tmp, parent.frame()) and add txt - paste( nm, '-', tmp, sep='' ) eval( parse(text=txt), parent.frame() ) in

[R] Deparse substitute assign with list elements

2015-05-14 Thread soeren . vogel
Hello, When I use function `foo` with list elements (example 2), it defines a new object named `b[[1]]`, which is not what I want. How can I change the function code to show the desired behaviour for all data structures passed to the function? Or is there a more appropriate way to sort of

[R] Get previous R digest volumes/issues

2011-09-10 Thread soeren . vogel
Hello, (how) can I download/re-retrieve/order previous R-** digest volumes/issues to my mailbox for local browsing? Thank you, Sören __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide

Re: [R] Instances of a C++ class in R

2011-05-13 Thread soeren . vogel
On 28.04.2011, at 12:18, soeren.vo...@uzh.ch wrote: On 27.04.2011, at 11:59, soeren.vo...@uzh.ch wrote: We are working on a class in C++. The files compile fine (R CMD SHLIB ...) and run in R. A bzipped tar archive with source code can be downloaded from here:

Re: [R] Instances of a C++ class in R

2011-04-28 Thread soeren . vogel
On 27.04.2011, at 11:59, soeren.vo...@uzh.ch wrote: We are working on a class in C++. The files compile fine (R CMD SHLIB ...) and run in R. A bzipped tar archive with source code can be downloaded from here: http://sovo.md-hh.com/files/GUTS3.tar.bz In R, dyn.load(GUTS.so) generates an

[R] Instances of a C++ class in R

2011-04-27 Thread soeren . vogel
Hello We are working on a class in C++. The files compile fine (R CMD SHLIB ...) and run in R. A bzipped tar archive with source code can be downloaded from here: http://sovo.md-hh.com/files/GUTS3.tar.bz In R, dyn.load(GUTS.so) generates an instance of the GUTS class. (How) Is it possible to

Re: [R] Nagelkerke R square for Prediction data

2010-12-27 Thread Soeren . Vogel
Hello I found some small postings dated to 22 Oct 2008 on the message subject. Recently, I have been working with binary logistic regressions. I didn't use the design package. Yet, I needed the fit indices. Therefore, I wrote a small function to output the Nagelkerke's R, and the Cox--Snell R

[R] Multinomial Analysis

2010-12-15 Thread soeren . vogel
I want to analyse data with an unordered, multi-level outcome variable, y. I am asking for the appropriate method (or R procedure) to use for this analysis. N - 500 set.seed(1234) data0 - data.frame(y = as.factor(sample(LETTERS[1:3], N, repl = T, + prob = c(10, 12, 14))), x1 =

[R] Linear separation

2010-12-03 Thread soeren . vogel
In https://stat.ethz.ch/pipermail/r-help/2008-March/156868.html I found what linear separability means. But what can I do if I find such a situation in my data? Field (2005) suggest to reduce the number of predictors or increase the number of cases. But I am not sure whether I can, as an

[R] slicing list with matrices

2010-11-17 Thread soeren . vogel
A list contains several matrices. Over all matrices (list elements) I'd like to access one matrix cell: m - matrix(1:9, nrow=3, dimnames=list(LETTERS[1:3], letters[1:3])) l - list(m1=m, m2=m*2, m3=m*3) l[[3]] # works l[[3]][1:2, ] # works l[[1:3]][1, 1] # does not work How can I slice all C-c

[R] S: appropriate significance tests

2010-10-20 Thread soeren . vogel
Hello (1) How can I compare two Pearson correlation coefficients for significant differences without the use of the raw data? (2) How can I compare two linear regression coefficients for significant differences without the use of the raw data? (3) How can I compare two multiple correlation

Re: [R] S: appropriate significance tests

2010-10-20 Thread soeren . vogel
Thanks Greg for the additional remarks. Basically I have two questions, let me try to specify them as follows: (1) Height and intelligence may correlate at, say, X, but speed and finger length may correlate at Y. Despite any sense of such a statement, is X significantly larger than Y? How can

[R] Sweave line breaks

2010-07-30 Thread soeren . vogel
Hello, when I print x in Sweave, the lines do not wrap. However, I want them to wrap (perhaps at a specified width). How? Thanks, *S* keep.source=TRUE= x - Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad

[R] ROpenOffice (which requires Rcompression)

2010-07-23 Thread soeren . vogel
Hello, for my data preparation and administration (data, labels, etc.) I use OpenOffice.org ODS spreadsheet files with several sheets in one file. However, I find it inconvenient to export every single sheet to a csv file whenever I apply changes to the labelling or so, and I haven't found a

[R] Default For list.len Argument (list output truncated)

2010-07-21 Thread Soeren . Vogel
Hello How can I set a default for the 'list.len' argument in 'str'? x - as.data.frame(matrix(1:1000, ncol=1000)) str(x) formals(str) - alist(object=, ...=, list.len=1000) args(str); formals(str) str(x) Does not display errors, but does not work either. Thanks for help Sören

[R] S: Book for time series analysis with R

2010-07-09 Thread soeren . vogel
Hello Could you recommend a printed/electronic book that teaches time series analysis (using R) for students? I am searching for something similar to the MASS book, with a level lower but close, for TSA. Easy examples would be fine to understand deeper statistical procedures. Functions,

[R] Adding NAs to data.frame

2010-05-08 Thread soeren . vogel
Hello, after the creation of a data.frame I like to add NAs as follows: n - 743; x - runif(n, 1, 7); Y - runif(n, 1, 7); Ag6 - runif(n, 1, 7); df - data.frame(x, Y, Ag6); # a list with positions: v - apply(df, 2, function(x) sample(n, sample(1:ceiling(5*n/100), 1), repl=F)); # a loop too much?

[R] apply fun to df returning a matrix

2010-04-30 Thread Soeren . Vogel
Hello, a data.frame, df, holds the numerics, x, y, and z. A function, fun, should return some arbitrary statistics about the arguments, e.g. the sum or anything else. What I want to do is to apply this function to every pair of variables in df, and the return should be a matrix as found

Re: [R] apply fun to df returning a matrix

2010-04-30 Thread Soeren . Vogel
Hi Mohamed, thanks for your answer. Anyway, the how to is exactly my problem, since ... fun2 - function(x){ please_use_aggregate_and_apply_in_some_way_and_return_the_output_of_my_example_as_requested (fun(x)); } fun2(df); ... unfortunately returns an error ;-). Could you please give a

Re: [R] apply fun to df returning a matrix

2010-04-30 Thread Soeren . Vogel
Thanks for the code, that was exactly what I was looking for. Regards, Sören On 30.04.2010, at 14:04, David Winsemius wrote: On Apr 30, 2010, at 6:59 AM, Mohamed Lajnef wrote: Hi Soeren Apply or aggregate functions Probably needs combn as well. Could do it all with numeric indices,

[R] Return a variable name

2010-04-16 Thread soeren . vogel
Hello, how can I return the name of a variable, say a$b, from a function? fun - function(x){ return(substitute(x)); } a - data.frame(b=1:10); fun(a$b) ... returns a$b, but this is a type language, thus I can't use it as a character string, can I? How? Thanks for help, Sören

[R] cbind, row names

2010-01-29 Thread soeren . vogel
Hello, I read the help as well as the examples, but I can not figure out why the following code does not produce the *given* row names, x and y: x - 1:20 y - 21:40 rbind( x=cbind(N=length(x), M=mean(x), SD=sd(x)), y=cbind(N=length(y), M=mean(y), SD=sd(y)) ) Could you please help? Thank

[R] Exact test for count data

2009-11-28 Thread soeren . vogel
Hello! Bortz, Lienert, Boehnke (2008, pp. 140--142) suggest an exact polynomial test for low frequency tables. I used it recently, and thus, created the code attached. Maybe someone would use (and likely modify) it or incorporate it into their package. Sören References: Bortz, J.,

[R] searching code for combination of vector

2009-11-25 Thread soeren . vogel
For a given numeric vector v of length n and sum s, is there a ready- to-run code that returns every combination of v in n summing up to s? Example for n=3 and s=2: v - c(2, 0, 0) # find some coding here that returns [1] 2 0 0 [2] 1 1 0 [3] 1 0 1 [4] 0 2 0 [5] 0 1 1 [6] 0 0 2 Thanks Sören

[R] Define return values of a function

2009-11-22 Thread Soeren . Vogel
I have created a function to do something: i - factor(sample(c(A, B, C, NA), 793, rep=T, prob=c(8, 7, 5, 1))) k - factor(sample(c(X, Y, Z, NA), 793, rep=T, prob=c(12, 7, 9, 1))) mytable - function(x){ xtb - x btx - x # do more with x, not relevant here cat(The table has been

Re: [R] shrink list by mathed entries

2009-11-14 Thread Soeren . Vogel
On 14.11.2009, at 03:58, David Winsemius wrote: On Nov 13, 2009, at 11:19 AM, soeren.vo...@eawag.ch wrote: a - c(Mama, Papa, Papa; Mama, , Sammy; Mama; Papa) a - strsplit(a, ; ) mama - rep(F, length(a)) mama[sapply(a, function(x) { sum(x==Mama) }, simplify=T) 0] - T [...] ... produces the

[R] Craddock-Flood Test in R?

2009-11-13 Thread soeren . vogel
Hello The Craddock-Flood Test is recommended for large tables with small degrees of freedom and low-frequency cells. Is there an R procedure and/or package which does the test? Thank you for your help! Sören Vogel -- Sören Vogel, Dipl.-Psych. (Univ.), PhD-Student, Eawag, Dept. SIAM

[R] shrink list by mathed entries

2009-11-13 Thread Soeren . Vogel
Hello a - c(Mama, Papa, Papa; Mama, , Sammy; Mama; Papa) a - strsplit(a, ; ) mama - rep(F, length(a)) mama[sapply(a, function(x) { sum(x==Mama) }, simplify=T) 0] - T papa - rep(F, length(a)) papa[sapply(a, function(x) { sum(x==Papa) }, simplify=T) 0] - T # ... more variables ... produces the

[R] when use which()

2009-11-13 Thread soeren . vogel
Hello: # some code to assign with and without which q - 1:20; q[c(9, 12, 14)] - NA r - 1:20; r[c(8:9, 12:15)] - NA s - 1:20; s[c(8:9, 12:15)] - NA r[q 16] - 0 s[which(q 16)] - 0 r;s # both: 0 0 0 0 0 0 0 0 NA 0 0 NA 0 NA 0 16 17 18 19 20 r - 1:20; r[c(8:9, 12:15)] - NA s - 1:20;

[R] Formatted contingency tables with (%)

2009-11-10 Thread soeren . vogel
Quite often, I need those tables: x - sample(c(a, b, c), 40, rep=T) y - sample(c(X, Y), 40, rep=T) (tbl - table(x, y)) (z - as.factor(paste(as.vector(tbl), (, round(prop.table(as.vector(tbl)) * 100, 1), %), sep=))) matrix(as.factor(z), nrow=3, dimnames=dimnames(tbl)) But the result looks

[R] pca vs. pfa: dimension reduction

2009-03-25 Thread soeren . vogel
Can't make sense of calculated results and hope I'll find help here. I've collected answers from about 600 persons concerning three variables. I hypothesise those three variables to be components (or indicators) of one latent factor. In order to reduce data (vars), I had the following

[R] sunflowerplot error

2009-03-19 Thread soeren . vogel
A sunflowerplot crossing two categorial variables with NAs fails: ### sample: start ### set.seed(20) a - c(letters[1:4]) z - c(letters[23:26]) fa - factor(sample(rep.int(a, 1000), 100, replace=T), levels=a, ordered=T) fz - factor(sample(rep.int(z, 1000), 100, replace=T), levels=z, ordered=T)

[R] chisq.test: decreasing p-value

2009-03-11 Thread soeren . vogel
A Likert scale may have produced counts of answers per category. According to theory I may expect equality over the categories. A statistical test shall reveal the actual equality in my sample. When applying a chi square test with increasing number of repetitions (simulate.p.value) over a

Re: [R] chisq.test: decreasing p-value

2009-03-11 Thread soeren . vogel
Thanks to Peter, David, and Michael! After having corrected the coding error, the p values converge to particular value, not necessarily zero. The whole story is, 634 respondents in 6 different areas marked their answer on a 7-step Likert scale (very bad, bad, ..., very good -- later

[R] Summary of data.frame according to colnames and grouping factor

2009-03-08 Thread soeren . vogel
A dataframe holds 3 vars, each checked true or false (1, 0). Another var holds the grouping, r and s: ### start:example set.seed(20) d - data.frame(sample(c(0, 1), 20, replace=T), sample(c(0, 1), 20, replace=T), sample(c(0, 1), 20, replace=T)) names(d) - c(A, B, C) e - rep(c(r, s), 10) ###

[R] Recode factor into binary factor-level vars

2009-03-07 Thread soeren . vogel
How to I recode a factor into a binary data frame according to the factor levels: ### example:start set.seed(20) l - sample(rep.int(c(locA, locB, locC, locD), 100), 10, replace=T) # [1] locD locD locD locD locB locA locA locA locD locA ### example:end What I want in the end is the

[R] Summary grouped by factor

2009-03-06 Thread soeren . vogel
### example:start v - sample(rnorm(200), 100, replace=T) k - rep.int(c(locA, locB, locC, locD), 25) tapply(v, k, summary) ### example:end ... (hopefully) produces 4 summaries of v according to k group membership. How can I transform the output into a nice table with the croups as columns and

Re: [R] Summary grouped by factor

2009-03-06 Thread soeren . vogel
On 06.03.2009, at 16:48, soeren.vo...@eawag.ch wrote: ### example:start v - sample(rnorm(200), 100, replace=T) k - rep.int(c(locA, locB, locC, locD), 25) tapply(v, k, summary) ### example:end ... (hopefully) produces 4 summaries of v according to k group membership. How can I transform the

[R] Grouped Boxplot

2009-03-04 Thread soeren . vogel
Pls forgive me heavy-handed data generation -- newby ;-) ### start ### # example data g - rep.int(c(A, B, C, D), 125) t - rnorm(5000) a - sample(t, 500, replace=TRUE) b - sample(t, 500, replace=TRUE) # what I actually want to have: boxplot(a | b ~ g) # but that does obviously not produce what

[R] add absolute value to bars in barplot

2009-02-27 Thread soeren . vogel
Hello, r-h...@r-project.orgbarplot(twcons.area, beside=T, col=c(green4, blue, red3, gray), xlab=estate, ylab=number of persons, ylim=c(0, 110), legend.text=c(treated, mix, untreated, NA)) produces a barplot very fine. In addition, I'd like to get the bars' absolute values on the top

[R] cross tabulation: convert frequencies to percentages

2009-02-27 Thread soeren . vogel
Hello, might be rather easy for R pros, but I've been searching to the dead end to ... twsource.area - table(twsource, area, useNA=ifany) gives me a nice cross tabulation of frequencies of two factors, but now I want to convert to pecentages of those absolute values. In addition I'd

[R] Plot grouped histograms

2008-10-09 Thread soeren . vogel
r11 -- r16 are variables showing a reason for usage of a product in 6 different situations. Each variable is a factor with 4 levels imported from a SPSS sav file with labels ranging from not important to very important, and NA's for a sample of N = 276. (1) I need a chi square test of

[R] read.spss: variable.labels

2008-10-07 Thread soeren . vogel
Hi, how can I attach variable labels originally read by read.spss() to the resulting variables? pre X - read.spss('data.sav', use.value.labels = TRUE, to.data.frame = TRUE, trim.factor.names = TRUE, trim_values = TRUE, reencode = UTF-8) names(X) - tolower(names(X)) attach(X) /pre Thank

[R] Regression with nominal data

2008-09-07 Thread soeren . vogel
Hi, y is nominal (3 categories), x1 to 3 is scale. What I want is a regression, showing the probability to fall in one of the three categories of y according to the x. How can I perform such a regression in R? Thanks for your help Sören __