[R] R function for censored linear regression

2013-09-24 Thread Andreas Wittmann
Dear R-useRs, I'm looking for an R-function for censored linear regression. I have the following data x1 - rnorm(100) x2 - rnorm(100) y - x1 + 2*x2 + rnorm(100,0,0.5) stat - rep(1,100) stat[50:100] - 0 data - data.frame(y,x1,x2,stat) y is the dependent variable, x1 and x2 are the independent

[R] survival package - calculating probability to survive a given time

2010-12-10 Thread Andreas Wittmann
Dear R users, i try to calculate the probabilty to survive a given time by using the estimated survival curve by kaplan meier. What is the right way to do that? as far as is see i cannot use the predict-methods from the survival package? library(survival) set.seed(1) time -

[R] gamma glm - using of weights gives error

2010-10-24 Thread Andreas Wittmann
Dear R-users, i try to use the following code to do a gamma regression glm(x1 / x2 ~ x3 + x4 + x5 + x6 + x7 + x8, family=Gamma(link=log), weights=x2) but here i get the error Error: NA/NaN/Inf in foreign function call (arg 1) In addition: Warning message: step size truncated due to

[R] Replacing double loop by apply

2010-05-14 Thread Andreas Wittmann
Dear R-users, after trying and searching a long time i have the following question. is it possible to replace to following double loop by some apply calls? ### m1 - data.frame(v1=factor(letters[1:5]),

Re: [R] Replacing double loop by apply

2010-05-14 Thread Andreas Wittmann
) On Fri, May 14, 2010 at 9:23 AM, Andreas Wittmann andreas_wittm...@gmx.de mailto:andreas_wittm...@gmx.de wrote: Dear R-users, after trying and searching a long time i have the following question. is it possible to replace to following double loop by some apply calls

[R] help using ecm.mix

2010-03-07 Thread Andreas Wittmann
Dear R-users, i have the following exmple for which i want to use ecm.mix from the mix-package. with da.mix after using em.mix i get the error improper posterior--empty cells, which is not uncommen because of 17 * 5 * 3 = 255 cells. so the next attempt is to use the ecm.mix for the

[R] Name for factor's levels with contr.sum

2010-02-23 Thread Andreas Wittmann
Hi R-useRs, after having read http://tolstoy.newcastle.edu.au/R/help/05/07/8498.html with the same topic but five years older. the solution for a contr.sum with names for factor levels for R version 2.10.1 will be to comment out the following line #colnames(cont) - NULL in contr.sum i

[R] enty-wise closest element

2010-01-17 Thread Andreas Wittmann
Dear R-users, i have a simple problem maybe, but i don't see the solution. i want to find the entry-wise closest element of an vector compared with another. ind1-c(1,4,10) ind2-c(3,5,11) for (i in length(ind2):1) { print(which.min(abs(ind1-ind2[i]))) } for ind2[3] it should be ind1[3] 10,

Re: [R] enty-wise closest element

2010-01-17 Thread Andreas Wittmann
On Jan 17, 2010, at 11:00 AM, Andreas Wittmann wrote: Dear R-users, i have a simple problem maybe, but i don't see the solution. i want to find the entry-wise closest element of an vector compared with another. ind1-c(1,4,10) ind2-c(3,5,11) for (i in length(ind2):1) { print(which.min

[R] parsing protocol of states

2010-01-12 Thread Andreas Wittmann
Dear R-users, actually i try to parse some state protocols for my work. i an easy stetting the code below works fine, if states are reached only once. in harder settings it could be possible that one state gets visited more times. in this case for me its interesting to see how much waiting

[R] Avoid for-loop in creating data.frames

2009-12-10 Thread Andreas Wittmann
Dear R-users, after several tries with lapply and searching the mailing list, i want to ask, wheter and how it is possibly to avoid the for-loop in the following piece of code? set2-as.data.frame(matrix(rnorm(9),ncol=3)) set2[1,1] - NA set2[3,2] - NA set2[2,1] - NA dimnames(set2)[1] -

Re: [R] Avoid for-loop in creating data.frames

2009-12-10 Thread Andreas Wittmann
, baptiste 2009/12/10 Andreas Wittmann andreas_wittm...@gmx.de: Dear R-users, after several tries with lapply and searching the mailing list, i want to ask, wheter and how it is possibly to avoid the for-loop in the following piece of code? set2-as.data.frame(matrix(rnorm(9),ncol=3)) set2[1,1

[R] Solve linear program without objective function

2009-12-04 Thread Andreas Wittmann
Dear R-users, i try to solve to following linear programm in R 0 * x_1 + 2/3 * x_2 + 1/3 * x_3 + 1/3 * x_4 = 0.3 x_1 + x_2 + x_3 + x_4 = 1 x_1, x_2, x_3, x_4 0, x_1, x_2, x_3, x_4 1 as you can see i have no objective function here besides that i use the following code. library(lpSolve)

[R] Generate missing data patterns

2009-12-02 Thread Andreas Wittmann
Dear R-users, i try to generate missing values in a matrix X according to a given missingnes pattern R with the probabilities p per row. X-matrix(rnorm(3*100),ncol=3) ## indicator matrix for missingnes (1 observed, 0 missing) R-matrix(c(1,1,1, 0,0,1, 1,1,0,

Re: [R] predict: remove columns with new levels automatically

2009-11-25 Thread Andreas Wittmann
)) } predict.drop(x ~ ., training, test) best regards Andreas David Winsemius wrote: On Nov 25, 2009, at 1:48 AM, Andreas Wittmann wrote: Sorry for my bad description, i don't want get a constructed algorithm without own work. i only hoped to get some advice how to do this. i don't want

[R] predict: remove columns with new levels automatically

2009-11-24 Thread Andreas Wittmann
Dear R-users, in the follwing thread http://tolstoy.newcastle.edu.au/R/help/03b/3322.html the problem how to remove rows for predict that contain levels which are not in the model. now i try to do this the other way round and want to remove columns (variables) in the model which will be

Re: [R] predict: remove columns with new levels automatically

2009-11-24 Thread Andreas Wittmann
this problem is quite common and i can use an algorithm somebody has already implemented. best regards Andreas Original-Nachricht Datum: Wed, 25 Nov 2009 00:48:59 -0500 Von: David Winsemius dwinsem...@comcast.net An: Andreas Wittmann andreas_wittm...@gmx.de CC: r-help@r

[R] recode according to old levels

2009-11-18 Thread Andreas Wittmann
Dear R-users, i try to recode a factor according to old levels F - factor(sample(c(rep(A, 4), rep(B,2), rep(C,5 recode(F, levels(F)[c(1,3)]='X'; else='Y') i tried to work with eval or expression around levels(F)[c(1,3)], but nothing seems to work. Many thanks if anyone could tell me

[R] predict missing values with svm

2009-09-28 Thread Andreas Wittmann
Dear R-Users, i want to use the function svm of the e1071 package to predict missing data data(iris) ## create missing completely at random data for (i in 1:5) { mcar - rbinom(dim(iris)[1], size=1, prob=0.1) iris[mcar == 1, i] -

[R] mice and Date-Time Classes

2009-07-16 Thread Andreas Wittmann
Dear R-Users, i want to use the function mice of the mice package with data, that contains dates, but this gives an error x - Sys.time() dat - data.frame(dates=(1:10)*60*60*24+x, size=rnorm(10)) dat$dates[c(3,7)]-NA mice(dat) Fehler in check.imputationMethod(imputationMethod,

[R] Runtime Error with multinom

2009-07-14 Thread Andreas Wittmann
Dear R-users, i try to fit a multinomial model in order to get an imputation for a missing value in factor1. library(nnet) factor1 - factor(c(a,b,c,d)) factor2 - factor(c(e,f,g,h)) size - c(3,8,2,1) factor1[3] - NA Z-ifelse(is.na(factor1), 0, 1) assign(data,

[R] integrate with large parameters

2009-05-01 Thread Andreas Wittmann
Dear R-users, i have to integrate the following function `fun1` - function (a, l1, l2) { exp(log(l1) * (a - 1) - l2 * lgamma(a)) } but if l1 is large, i get the non-finite function value error, so my idea is to rescale with exp(-l1) `fun2` - function (a, l1, l2) { exp(log(l1) * (a - 1) -

[R] integrate lgamma from 0 to Inf

2009-04-22 Thread Andreas Wittmann
Dear R users, i try to integrate lgamma from 0 to Inf. But here i get the message roundoff error is detected in the extrapolation table, if i use 1.0e120 instead of Inf the computation works, but this is against the suggestion of integrates help information to use Inf explicitly. Using

[R] Continue R CMD BATCH on error

2009-04-13 Thread Andreas Wittmann
Dear R useRs, after searching r-help and r-manuals for about one hour i have the following, probably easy question for you. i have the following R-code, in the file test01.R `fun1` - function(x) { x - x + 2

[R] Different values for double integral

2009-01-24 Thread Andreas Wittmann
Dear R useRs, i have the function f1(x, y, z) which i want to integrate for x and y. On the one hand i do this by first integrating for x and then for y, on the other hand i do this the other way round and i wondering why i doesn't get the same result each way? z - c(80, 20, 40, 30) f1 -

Re: [R] Different values for double integral

2009-01-24 Thread Andreas Wittmann
, Andreas Wittmann wrote: Dear R useRs, i have the function f1(x, y, z) which i want to integrate for x and y. On the one hand i do this by first integrating for x and then for y, on the other hand i do this the other way round and i wondering why i doesn't get the same result each way? z - c(80

[R] transform R to C

2009-01-05 Thread Andreas Wittmann
Dear R users, i would like to transform the following function from R-code to C-code and call it from R in order to speed up the computation because in my other functions this function is called many times. `dgcpois` - function(z, lambda1, lambda2) { `f1` - function(alpha, lambda1, lambda2)

[R] Finding the first value without warning in a loop

2008-12-06 Thread Andreas Wittmann
Dear R useRs, with the following piece of code i try to find the first value which can be calculated without warnings `test` - function(a) { repeat { ## hide warnings suppressWarnings(log(a)) if (exists(last.warning, envir = .GlobalEnv)) { a - a + 0.1 ## clear

[R] ESS Toolbar missing after Ubuntu Update

2008-11-02 Thread Andreas Wittmann
Dear R useRs, yesterday i updated my system from ubuntu 8.04 to 8.10. I use emacs- snapshot, this is emacs 23.0.60.1 and ess 5.3.8. Before the update i had when starting emacs with an R file an ess-toolbar with little icons to start R or to evaluate a line or a region of my R file, but no this

[R] folded normal distribution in R

2008-10-20 Thread Andreas Wittmann
Dear R useRs, i wanted to ask if the folded normal destribution (Y = abs(X) with X normal distributed) with density and random number generator is implemented in R or in any R-related package so far? Maybe i can use the non-central chi-square distribution and rchisq(n, df=1, ncp0) here?

Re: [R] R CMD SHLIB: file not recognized: File format not recognized

2008-10-19 Thread Andreas Wittmann
the compilation, if i delete it and try the compilation under ubuntu everything works fine, don't know why? best regards Andreas Dirk Eddelbuettel wrote: On Sun, Oct 19, 2008 at 01:27:06AM +0200, Andreas Wittmann wrote: Dear R useRs, on ubuntu 8.04 i try to create a shared object out

[R] R CMD SHLIB: file not recognized: File format not recognized

2008-10-18 Thread Andreas Wittmann
Dear R useRs, on ubuntu 8.04 i try to create a shared object out of a c-file this is // add.c #include Rinternals.h SEXP addiere(SEXP a, SEXP b) { int i, n; n = length(a); for (i = 0; i n; i++) REAL(a)[i] += REAL(b)[i]; return(a); } in terminal i type R CMD SHLIB add.c and get gcc

[R] compute posterior mean by numerical integration

2008-09-27 Thread Andreas Wittmann
Dear R useRs, i try to compute the posterior mean for the parameters omega and beta for the following posterior density. I have simulated data where i know that the true values of omega=12 and beta=0.01. With the function postMeanOmega and postMeanBeta i wanted to compute the mean values of

Re: [R] Computation of contour values - Speeding up computation

2008-09-20 Thread Andreas Wittmann
Thank you very much, yes maybe its worth working on it. best regards Andreas Uwe Ligges wrote: Andreas Wittmann wrote: Dear R useRs, i have the following code to compute values needed for a contour plot myContour - function

[R] lower and upper limits in integrate as vectors

2008-09-20 Thread Andreas Wittmann
Dear R useRs, i try to integrate the following function for many values integrand - function(z) { return(z * z) } i do this with a for-loop for(i in 2:4) { z - integrate(integrand, i-1, i)$value cat(z, z, \n) } to speed up the computation for many values i tried vectors in integrate to do

Re: [R] lower and upper limits in integrate as vectors

2008-09-20 Thread Andreas Wittmann
(integrate, lower=vec1, upper=vec2, MoreArgs=list(f=integrand) ) baptiste On 20 Sep 2008, at 13:08, Andreas Wittmann wrote: Dear R useRs, i try to integrate the following function for many values integrand - function(z) { return(z * z) } i do this with a for-loop for(i in 2:4) { z - integrate

[R] certain number of equations in function depending on parameter

2007-09-19 Thread Andreas Wittmann
Hello everybody, i have the following problem to write a function which recognizes depending on the parameter-inputs how many equations for the calculation in the function are needed. Here is an example of my problem: myfun - function(a, b, c, d) { k - length(a) #here d = 3 for