[R] r: RODBC QUESTION
hello all i have a quick question. i have been using the RODBC library (trying to read Excel data into R but i am doing this by using Rexcel. this is probably not the correct forum - sorry for this). my code is shown below: Sub A() 'start the connection to R Call RInterface.StartRServer RInterface.RRun library(RODBC) RInterface.RRun A = odbcConnectExcel('c:/TRY.xls') RInterface.RRun q1 = sqlFetch(A, 'Sheet1') RInterface.RRun odbcClose (A) Worksheets(out).Activate Call RInterface.GetArray(q1, Range(A1)) Call RInterface.StopRServer End Sub i have included four examples below. on the left hand side we have the data as it appears in Excel and on the right hand side we have the output from the code (outputted to the 'out' sheet in excel). in the first example the code works while in the other three exampl0es it does not. ('a' is some character) when i use the commands in r directly everything works correctly (ie missing values are treated as NA - characters is treated similarly) can anyone show me how to solve this! ANOTHER QUESTION: am i allowed to have numeric and character values in the same column when importing from Excel to R? (seems like i cant) thanking you in advance! wishing you all a happy new year (in advance) / allan Y X1 X2 1 6 3 1 6 3 2 6 2 2 6 2 3 5 2 3 5 2 Y X1 X2 0 1 6 3 2 6 2 3 a 2 Y X1 X2 0 1 6 3 2 6 2 3 a 2 Y X1 X2 0 1 3 2 6 2 3 5 2__ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] R: scale and location - t distr
hi all HOPE SOMEONE CAN HELP! i 've been searching r and some of the archives in order to find out how one can consistently estimate the degrees of freedom of the following random variable: Y = a*T(v)+b a and b = constants T(v) is a Students t distribution with v degrees of freedom i found one posting in 2001 but no answer! i know that this problem can easily be solved using MLE (numerically) but i am interested in the method of moment estimates. i derived the estimators and then simulated 10 000 times from the distribution in order to evaluate the efficiency of the estimators. the parameters used are: a=0.1 b=0 v=9.5 and the simulation results are: mean(a)=0.10017 mean(b)=6.4202e-06 mean(v)=9.780 sd(a)=0.0016 sd(b)=1.1334e-03 sd(v)=1.1681 the sample size used is also 10 000! from the above results it seems as if a and b is being estimated consistently but v is not (i.e. the mean of the different paameter estimates is not equal to 9.5)! i know that a confidence interval about the estimate does contain 9.5 but the sd of the v estimate seems to big! QUESTION: # is this because the number of simulations is to small and that the asymptotic results for v does not yet hold? i will run the simulations 100 000 times and report the results later. hopefully someone can shed some insight on this problem. / allan__ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] R: pp plot
hi all i would like to know if anyone has a reference on how one would place the bands on the pp plot. i want to test whether or not a certain data set comes from a particular distribution (not normal). i've already plotted F(X(j)) vs j/(n+1) where F(x) is the cum dist function, X(j) is the j'th order statistic and n is the sample size. a goole search gave arb references and thought some one one the list should definitely know how to solve this problem. thanking you in advance allan__ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] R: pp plot
the distribution is not a standard one P Ehlers wrote: Is qq.plot in package 'car' of use to you? I think that it requires your distribution to be one of those available in R. Peter Clark Allan wrote: hi all i would like to know if anyone has a reference on how one would place the bands on the pp plot. i want to test whether or not a certain data set comes from a particular distribution (not normal). i've already plotted F(X(j)) vs j/(n+1) where F(x) is the cum dist function, X(j) is the j'th order statistic and n is the sample size. a goole search gave arb references and thought some one one the list should definitely know how to solve this problem. thanking you in advance allan __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- Peter Ehlers University of Calgary __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html__ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] R: method of moments
hi all does anyone know how one would calculate the covariance matrix of a vector of estimated parameters if we use the method of moments technique? one could use bootstrapping techniques but there should be some asymptotic results that could be used as per MLE estimates. a reference would be much appreciated.__ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] R: source
hi all i have a quick question i would like to use the source command but i keep on getting an error eg source(c:/research file/model.txt) the problem seems to be because of the space in the file name but this is how windows references the folder name. i dont want to change the folder name ??/ allan__ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] R: integration problem
hi all an integration problem. i would like an exact or good approximation for the following, but i do not want to use a computer. any suggestions: integral of exp(b*x)/sqrt(1-x^2) where b is a constant greater than or equal to 0 and the integral runs from 0 to 1 any help would be apreciated / allan__ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] R: deleting rows
hi all hopefully some one can help. assume that i imported the following data into R (say the data frame is called a) x1 x2 x3 1 NA 3 1 2 NA 1 2 3 3 NA 6 4 5 9 7 5 6 7 8 9 NA 7 9 How can i construct a new data frame that only contains those rows that does not contain the NA's? is these a quick way? ie x1 x2 x3 1 2 3 4 5 9 7 5 6 7 8 9 in this example we can simple use a[c(-1,-2,-4,-8),] but happens if we have a larger dataframe? we need to construct some kind of row indicator telling R which rows contains NA'S. is there an easier method? / allan__ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] R: optim
thanx for the reply. i understood that the function found a maximum. i was just a bit worried about the message. i assumed that it was an ERROR message. i see now that it is some sort of stopping rule. does this make sense? / allan Douglas Bates wrote: On 9/6/05, Clark Allan [EMAIL PROTECTED] wrote: hi all i dont understand the error message that is produced by the optim function. can anybody help??? ie: [[1]]$message [1] CONVERGENCE: REL_REDUCTION_OF_F = FACTR*EPSMCH can anyone help? That code indicates that the optimizer has declared convergence because the relative reduction in the objective function in successive iterates is below a tolerance. As documented in ?optim, a convergence code of 0 indicates success ... convergence: An integer code. '0' indicates successful convergence. Error codes are ... This may be counter-intuitive but it does make sense to shell programmers. The idea is that there is only one way you can succeed but there are many different ways of failing so you use the nonzero codes to indicate the types of failure and the zero code, which we usually read as FALSE in a logical context, to indicate success. ### SK.FIT(XDATA=a,XDATAname=a,PHI1=1,v=5,vlo=2,vhi=300,phi2lo=.01) [[1]] [[1]]$par [1] -0.01377906 0.83859445 0.34675230 300. [[1]]$value [1] 90.59185 [[1]]$counts function gradient 53 53 [[1]]$convergence [1] 0 [[1]]$message [1] CONVERGENCE: REL_REDUCTION_OF_F = FACTR*EPSMCH # i ghave included the function used in the optim call: SKEWMLE=function(l,DATA=XDATA,...) { #alpha = l[1] #beta = l[2] #phi2 = l[3] #v= l[4] phi1=PHI1 DATA-as.matrix(DATA) fnew-function(x,y,l,...) { #when we do not estimate phi1 t1=(1+((y-l[1]-l[2]*x)^2)/(l[4]*l[3]^2))^(-0.5*(1+l[4])) t2=(1+(x^2)/l[4])^(-0.5*(1+l[4])) t3=2*((gamma(0.5*(1+l[4]))/(gamma(0.5*l[4])*sqrt(l[4]*pi)))^2)/l[3] t1*t2*t3 } a-double(length(DATA)) y=DATA a=apply(y,1,function(q) log(integrate(fnew,lower=0,upper=Inf,y=q,l=l)$value)) -sum(a) } __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] R: optim
funny optim message: $MLE $MLE$par [1] -0.09554688 1.13100488 0.06651340 $MLE$value [1] 48.93381 $MLE$counts function gradient 100 100 $MLE$convergence [1] 52 $MLE$message [1] ERROR: ABNORMAL_TERMINATION_IN_LNSRCH WHAT DOES THIS ERROR MESSAGE MEAN??? hope some one can help. / allan Clark Allan wrote: thanx for the reply. i understood that the function found a maximum. i was just a bit worried about the message. i assumed that it was an ERROR message. i see now that it is some sort of stopping rule. does this make sense? / allan Douglas Bates wrote: On 9/6/05, Clark Allan [EMAIL PROTECTED] wrote: hi all i dont understand the error message that is produced by the optim function. can anybody help??? ie: [[1]]$message [1] CONVERGENCE: REL_REDUCTION_OF_F = FACTR*EPSMCH can anyone help? That code indicates that the optimizer has declared convergence because the relative reduction in the objective function in successive iterates is below a tolerance. As documented in ?optim, a convergence code of 0 indicates success ... convergence: An integer code. '0' indicates successful convergence. Error codes are ... This may be counter-intuitive but it does make sense to shell programmers. The idea is that there is only one way you can succeed but there are many different ways of failing so you use the nonzero codes to indicate the types of failure and the zero code, which we usually read as FALSE in a logical context, to indicate success. ### SK.FIT(XDATA=a,XDATAname=a,PHI1=1,v=5,vlo=2,vhi=300,phi2lo=.01) [[1]] [[1]]$par [1] -0.01377906 0.83859445 0.34675230 300. [[1]]$value [1] 90.59185 [[1]]$counts function gradient 53 53 [[1]]$convergence [1] 0 [[1]]$message [1] CONVERGENCE: REL_REDUCTION_OF_F = FACTR*EPSMCH # i ghave included the function used in the optim call: SKEWMLE=function(l,DATA=XDATA,...) { #alpha = l[1] #beta = l[2] #phi2 = l[3] #v= l[4] phi1=PHI1 DATA-as.matrix(DATA) fnew-function(x,y,l,...) { #when we do not estimate phi1 t1=(1+((y-l[1]-l[2]*x)^2)/(l[4]*l[3]^2))^(-0.5*(1+l[4])) t2=(1+(x^2)/l[4])^(-0.5*(1+l[4])) t3=2*((gamma(0.5*(1+l[4]))/(gamma(0.5*l[4])*sqrt(l[4]*pi)))^2)/l[3] t1*t2*t3 } a-double(length(DATA)) y=DATA a=apply(y,1,function(q) log(integrate(fnew,lower=0,upper=Inf,y=q,l=l)$value)) -sum(a) } __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html__ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] r: chinese installation of r
can any one help: A friends query: My pc is using the chinese version windows xp, so when I installed R Chinese was automatically selected as the default language.How can I change it? It brings a lot of trouble since some of the output is in chinese too.__ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] R: optim
hi all i dont understand the error message that is produced by the optim function. can anybody help??? ie: [[1]]$message [1] CONVERGENCE: REL_REDUCTION_OF_F = FACTR*EPSMCH can anyone help? ### SK.FIT(XDATA=a,XDATAname=a,PHI1=1,v=5,vlo=2,vhi=300,phi2lo=.01) [[1]] [[1]]$par [1] -0.01377906 0.83859445 0.34675230 300. [[1]]$value [1] 90.59185 [[1]]$counts function gradient 53 53 [[1]]$convergence [1] 0 [[1]]$message [1] CONVERGENCE: REL_REDUCTION_OF_F = FACTR*EPSMCH # i ghave included the function used in the optim call: SKEWMLE=function(l,DATA=XDATA,...) { #alpha = l[1] #beta = l[2] #phi2 = l[3] #v= l[4] phi1=PHI1 DATA-as.matrix(DATA) fnew-function(x,y,l,...) { #when we do not estimate phi1 t1=(1+((y-l[1]-l[2]*x)^2)/(l[4]*l[3]^2))^(-0.5*(1+l[4])) t2=(1+(x^2)/l[4])^(-0.5*(1+l[4])) t3=2*((gamma(0.5*(1+l[4]))/(gamma(0.5*l[4])*sqrt(l[4]*pi)))^2)/l[3] t1*t2*t3 } a-double(length(DATA)) y=DATA a=apply(y,1,function(q) log(integrate(fnew,lower=0,upper=Inf,y=q,l=l)$value)) -sum(a) }__ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] numerical intergation
how does one numerically intergate the following: A=function(x,y) { xy } over the range: 2x0 4y10 say. ie how would one set up the integrate function? i forgot!__ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] numerical intergation
found a solution: download the rmutil package from : http://popgen0146uns50.unimaas.nl/~jlindsey/rcode.html for those that are interested. note that only works for two dimensions! / allan (ranges was incorrect previously: should be:-2x0 4y10) Clark Allan wrote: i solved the problem: adapt(2, lo=c(2,4), up=c(0,10)) is there any package that allows one to have infinite limits?? when integrating over more than one variable? Clark Allan wrote: how does one numerically intergate the following: A=function(x,y) { xy } over the range: 2x0 4y10 say. ie how would one set up the integrate function? i forgot! __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html__ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] help
howzit dom i just saw your mail now! i tried the following and got an error: u=v=seq(1,3) u [1] 1 2 3 v [1] 1 2 3 f=function(x,y){max(x+y-1,0)} z=outer(u,v,f) Error in outer(u, v, f) : dim- : dims [product 9] do not match the length of object [1] it seems s if r is not performing elementwise maximisation!!! all you need is: f=function(x,y){pmax(x+y-1,0)} z=outer(u,v,f) ok lets try it!!! i used length =5 to save space u=v=seq(0,1,length=5) f=function(x,y){pmax(x+y-1,0)} z=outer(u,v,f) z [,1] [,2] [,3] [,4] [,5] [1,]0 0.00 0.00 0.00 0.00 [2,]0 0.00 0.00 0.00 0.25 [3,]0 0.00 0.00 0.25 0.50 [4,]0 0.00 0.25 0.50 0.75 [5,]0 0.25 0.50 0.75 1.00 think this works! check ?pmax see ya allan Dominique Katshunga wrote: Dear helpeRs, I seem to be a little bit confused on the result I am getting from the few codes below: u=v=seq(0,1,length=30) u [1] 0. 0.03448276 0.06896552 0.10344828 0.13793103 0.17241379 [7] 0.20689655 0.24137931 0.27586207 0.31034483 0.34482759 0.37931034 [13] 0.41379310 0.44827586 0.48275862 0.51724138 0.55172414 0.58620690 [19] 0.62068966 0.65517241 0.68965517 0.72413793 0.75862069 0.79310345 [25] 0.82758621 0.86206897 0.89655172 0.93103448 0.96551724 1. v [1] 0. 0.03448276 0.06896552 0.10344828 0.13793103 0.17241379 [7] 0.20689655 0.24137931 0.27586207 0.31034483 0.34482759 0.37931034 [13] 0.41379310 0.44827586 0.48275862 0.51724138 0.55172414 0.58620690 [19] 0.62068966 0.65517241 0.68965517 0.72413793 0.75862069 0.79310345 [25] 0.82758621 0.86206897 0.89655172 0.93103448 0.96551724 1. f=function(x,y){cp=max(x+y-1,0)} z=outer(u,v,f) z is a 30x30 matrix which is fine, but why all its entries are equal to 1? for example, the maximum between u[22]+v[22]-1 and 0 is not 1?? I don't really know where I went wrong! thanks, Dominique __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html__ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] R: stepwise procedures
hi all i found step(), stepAIC() and some other functions in leaps and subselect. is there a package/function that does the traditional stepwise regression procedures using F in and F out values? i know that step does the selctions based on AIC. / allan__ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] R: characters
hi all assume that i have the following table a=rbind(c(T,T,F),c(F,F,T)) a [,1] [,2] [,3] [1,] TRUE TRUE FALSE [2,] FALSE FALSE TRUE I would like to change all the FALSE entries to a blank. how can i do this? i could simply use a[a==F]= a but then how would i remove the from the entries. i know that this should be very easy!!! / allan__ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] sub set selection
hi all is there a package that undertakes subset selection but BASED ON AIC or any other information criteria. i've seen the subselect and the leaps package but i have not played around with them yet. thanx__ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] sub set selection
just normal linear model: multiple regression in particular Wensui Liu wrote: in what model, glm or gam? I believe you can use aic in both. On 8/11/05, Clark Allan [EMAIL PROTECTED] wrote: hi all is there a package that undertakes subset selection but BASED ON AIC or any other information criteria. i've seen the subselect and the leaps package but i have not played around with them yet. thanx __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- WenSui Liu, MS MA Senior Decision Support Analyst Division of Health Policy and Clinical Effectiveness Cincinnati Children Hospital Medical Center__ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] R: cbind
hi all are we able to combine column vectors of different lengths such that the result appears in matrix form? e.g. a=1 b=1:3 d=1:4 then z=CBIND(a,b,d) 1 1 1 2 2 3 3 4 i stil want the following! z[,1]=1 z[,2]=1:3 z[,3]=1:5 i made up the name of this function. we could use cbind but it does not seem to allows this! thanking you in advance. / allan__ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] R: matrix sizes
hi all assume that one is doing a simulation. in each iteration one produces a vector of results. this vectors length might change for each different iteration. how can one construct a matrix that contains all of the interation results in a matrix where each of the columns are the outputs from the different interations. how would have to define the output matrix initally? / thanking you in advance__ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] R: histograms and ylim
hi all a very simple question once again!!! can we change the y range in a histogram? e.g. x=rnorm(1000) hist(x,ylim=0.5,prob=T) #this does not work any suggestions???__ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] R: regression data set
hi all i am busy teaching a regression analysis course to second year science students. the course is fairly theoretical with all of the standard theorems and proofs... i would like to give the class a practical assignment as well. could you suggest a good problem and the location of the data set/s? it would be good if the data set has been analysed by a number of other people so that students can see the different ways of tackling a regression problem. some of the issues to be covered: estimation is there really a model variable selection ... outliers and influential observations interpreting the regression model / allan__ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] R: non parametric regression/kernels
hi all i have a another stats question. i would like to solve the following question: y(i)=a+b*x(i)+e(i) i.e. estimate a and b (they should be fixed) but i dont want to specify the standard density to the straight line. this can be done using kernel regression. the fitted line is however fitted locally. does anyone have a reference that will help me with my problem. i am still new to kernels/kernel regression and would like to get into the subject. / allan__ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] R: graphics devices
a simple question how does one produce plots on two different graphics devices? / allan__ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] R: graphics devices
one could use the par command to plot several plots on 1 graphics device. i would like to do the following: say plot(y~x) on one screen and then plot(q~w) on another screen so that one can see both of them together but not on the same graphics device. Sean O'Riordain wrote: Alan, I'm not sure what you mean... perhaps plot(y~x) # to the screen pdf(myplot.pdf) plot(y~x) # write the plot to the file dev.off() # close the file dev.off() # close the graphics window s/ On 29/07/05, Clark Allan [EMAIL PROTECTED] wrote: a simple question how does one produce plots on two different graphics devices? / allan __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] R:plot and dots
hi all a very simple question. i have plot(x,y) but i would like to add in on the plot the observation number associated with each point. how can this be done? / allan__ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] R: expression
hi all i am having a problem with the expression/paste command say we estimate a variable, named PHI it contains the value of say 2 and we want to display this value as hat(phi) = PHI onto a graphic i.e. hat(phi)=2 how does one do this? i've tried the following: 1. legend(-5,.3,expression(hat(phi)*=*PHI)) 2. legend(-5,.3,paste(expression(phi),=,PHI)) but they do not work. any help? / allan__ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] R: stats
for the stats gurus does anyone know if there exists a general formula relating the median of a continuous distribution to its moments. the distribution could be skewed or symmetric and is definitely not normal. the reason for asking is since the median of the particular distribution that i am interested in is difficult (probably impossible) to obtain. the median depends depends on an incomplete gamma distribution. the moments however can be obtained fairly easily. / allan__ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] r: LOOPING
hi all i know that one should try and limit the amount of looping in R programs. i have supplied some code below. i am interested in seeing how the code cold be rewritten if we dont use the loops. a brief overview of what is done in the code. == == == 1. the input file contains 120*500*61 cells. 120*500 rows and 61 columns. 2. we need to import the cells in 500 at a time and perform the same operations on each sub group 3. the file contais numeric values. there are quite a lot of missing values. this has been coded as NA in the text file (the file that is imported) 4. for each variable we check for outliers. this is done by setting all values that are greater than 3 standard deviations (sd) from the mean of a variable to be equal to the 3 sd value. 5. the data set has one response variable , the first column, and 60 explanatory variables. 6. we regress each of the explanatory variables against the response and record the slope of the explanatory variable. (i.e. simple linear regression is performed) 7. nsize = 500 since we import 500 rows at a time 8. nruns = how many groups you want to run the analysis on == == == TRY-function(nsize=500,filename=C:/A.txt,nvar=61,nruns=1) { #the matrix with the payoff weights fit.reg-matrix(nrow=nruns,ncol=nvar-1) for (ii in 1:nruns) { skip=1+(ii-1)*nsize #import the data in batches of nsize*nvar #save as a matrix and then delete dscan to save memory space dscan-scan(file=filename,sep=\t,skip=skip,nlines=nsize,fill=T,quiet=T) dm-matrix(dscan,nrow=nsize,byrow=T) rm(dscan) #this calculates which of the columns have entries in the columns #that are not NA #only perform regressions on those with more than 2 data points #obviously the number of points has to be much larger than 2 #col.points = the number of points in the column that are not NA col.points-apply(dm,2,function(x) sum(match(x,rep(NA,nsize),nomatch=0))) col.points #adjust for outliers dm.new-dm mean.dm.new-apply(dm.new,2,function(x) mean(x,na.rm=T)) sd.dm.new-apply(dm.new,2,function(x) sd(x,na.rm=T)) top.dm.new-mean.dm.new+3*sd.dm.new bottom.dm.new-mean.dm.new-3*sd.dm.new for (i in 1:nvar) { dm.new[,i][dm.new[,i]top.dm.new[i]]-top.dm.new[i] dm.new[,i][dm.new[,i]bottom.dm.new[i]]-bottom.dm.new[i] } #standardize the variables #we dont have to change the variable names here but i did! means.dm.new-apply(dm.new,2,function(x) mean(x,na.rm=T)) std.dm.new-apply(dm.new,2,function(x) sd(x,na.rm=T)) dm.new-sweep(sweep(dm.new,2,means.dm.new,-),2,std.dm.new,/) for (j in 2:nvar) { 'WE DO NOT PERFORM THE REGRESSION IF ALL VALUES IN THE COLUMN ARE NA if (col.points[j]!=nsize) { #fit the regression equations fit.reg[ii,j-1]-summary(lm(dm.new[,1]~dm.new[,j]))$coef[2,1] } else fit.reg[ii,j-1]-L } } dm.names-scan(file=filename,sep=\t,skip=0,nlines=1,fill=T,quiet=T,what=charachter) dm.names-matrix(dm.names,nrow=1,ncol=nvar,byrow=T) colnames(fit.reg)-dm.names[-1] output-c($fit.reg) list(fit.reg=fit.reg,output=output) } a=TRY(nsize=500,filename=C:/A.txt,nvar=61,nruns=1) == == == thanking you in advance / allan__ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] solving equation system
HI ALL i would like to solve a complex set of equations. i have four parameters and four equations. i could set up more equations since they are derived from the momnets of a particular distribution. the parameters are NON LINEAR!!! AND the eqautions are of the form: phi(i)=function(a,x,y,z) is there a package or group of commands that might be used in order to solve the system directly? thanking you in advance / allan Spencer Graves wrote: Have you considered writing a function to compute the sum of squares of deviations from equality and using optim? I use sum of squares not sum of absolute values, because if my functions are differentiable, the sum of squares will also be differentible while the sum of absolute values will not be. This means that sum of absolute values will not work well with a quasi-Newton algorithm. Also, have you considered making plots? If I understand your example, you can solve for lambda using (II) as lambda = x/mean(X). Then you can use (I) to solve for c. To understand this, it would help to plot the digamma function. If you do this (e.g., http://mathworld.wolfram.com/DigammaFunction.html), you will see that there are countably infinite solutions to this equation. If you want the positive solution, I suggest you try to solve for ln.c = log(c) rather than c directly, because that should make optim more stable. More generally, it often helps to make, e.g., contour or perspective plots and to try to find a parameterization that will make the sum of squares of errors approximatly parabolic in your parameters. My favorite reference on this is Bates and Watts (1988) Nonlinear Regression Analysis and Its Applications (Wiley). There may be better, more recent treatments of this subject, but I am not familiar with them. spencer graves p.s. I never (no never, not ever) use c as a variable name, because it is the name of a common R function. R is smart enough to distinguish between a function and a non-function in some contexts but not in all. When I want a name for a new object, I routinely ask R to print my proposed name. If it returns Error: object ... not found, I can use Carsten Steinhoff wrote: Hello, I want to solve some two dimensional equation system with R. Some systems are not solvable analytically. Here is an example: (I)1/n*sum{from_i=1_to_n}(Xi) = ln lambda + digamma(c) (II)mean(X) = x / lambda I want to find lambda and c, which R-function could do that task? Carsten [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- Spencer Graves, PhD Senior Development Engineer PDF Solutions, Inc. 333 West San Carlos Street Suite 700 San Jose, CA 95110, USA [EMAIL PROTECTED] www.pdf.com http://www.pdf.com Tel: 408-938-4420 Fax: 408-280-7915 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html__ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] r: integration question
hi all at the outset i must APOLOGIZE for sending the following mail. it is not R related but since there are many stats and maths buffs that use the list i decided to send the following question. integrate ((1+((y-bx)^2)/(av))*(1+(x^2)/(bv)))^(-0.5*(v+1)) over the interval 0 to inf a0, b0 and v4 y treated as a constant over the real line. i could integrate the function using integrate. do so for a large number of y values and plot the function BUT i would prefer an exact solution if possible. any help will be appreciated. i've attached a word file with the formula \ allan__ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] How to read a row dataset one by one
use a loop associated with the scan function. for (i in 1:9) { print(scan(file=c:/a.txt,sep=\t,skip=i,nlines=1,fill=T,quiet=T,what=raw)) } this works but there has to be a better solution Jan Sabee wrote: Dear all, How to read a row dataset one by one and then print it. x1 x2 x3 x4 x5 y a b a c cM1 c b b c cM4 c c a c cM2 c a c a aM2 c c a a aM1 c a b c aM3 c c a b cM3 c a c a bM2 c c a b aM1 I need a result like read row no 1, [1] a b a c cM1 read row no 2, [1] c b b c cM4 . . . the last row, [1] c c a b aM1 Kind regards, Jan Sabee __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html__ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] r: LEXICOGRAPHIC ORDERING
HI all i have a seemingly simple question. given a sequence of numbers say, 1,2,3,4,5. i would like to get all of the possible two number arrangments (combinations), all 3 number arrangents ... 5 number arrangements (combinations). i.e. in the 2 number case: 12,13,14,15,23,24,25,34,35,45 any ideas?__ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Dickey-Fuller Test
hello i ammended the code. it was in some package. dont know which? try tseries. this might be of help. adf.test.1-function (x,kind=3,k = trunc((length(x)- 1)^(1/3))) { #kind = the kind of test undertaken #kind = 1 == No constant no trend #kind = 2 == Constant #kind = 3 == Constant and trend #the null is ALWAYS non stationarity if (NCOL(x) 1) stop(x is not a vector or univariate time series) if (any(is.na(x))) stop(NAs in x) if (k 0) stop(k negative) DNAME - deparse(substitute(x)) k - k + 1 y - diff(x) n - length(y) z - embed(y, k) yt - z[,1] xt1 - x[k:n] tt - k:n if (kind==1) { table - cbind(c(2.66, 2.62, 2.6, 2.58, 2.58, 2.58), c(2.26, 2.25, 2.24, 2.23, 2.23, 2.23), c(1.95, 1.95, 1.95, 1.95, 1.95, 1.95), c(1.60, 1.61, 1.61, 1.62, 1.62, 1.62), c(0.92, 0.91, 0.90, 0.89, 0.89, 0.89), c(1.33, 1.31, 1.29, 1.29, 1.28, 1.28), c(1.70, 1.66, 1.64, 1.63, 1.62, 1.62), c(2.16, 2.08, 2.03, 2.01, 2.00, 2.00)) if (k 1) { yt1 - z[,2:k] res - lm(yt ~ xt1 - 1 + yt1) } else res - lm(yt ~ xt1-1) res.sum - summary(res) STAT - res.sum$coefficients[1,1]/res.sum$coefficients[1,2] } if (kind==2) { table - cbind(c(3.75, 3.58, 3.51, 3.46, 3.44, 3.43), c(3.33, 3.22, 3.17, 3.14, 3.13, 3.12), c(3.00, 2.93, 2.89, 2.88, 2.87, 2.86), c(2.62, 2.60, 2.58, 2.57, 2.57, 2.57), c(0.37, 0.40, 0.42, 0.42, 0.43, 0.44), c(0.00, 0.03, 0.05, 0.06, 0.07, 0.07), c(0.34, 0.29, 0.26, 0.24, 0.24, 0.23), c(0.72, 0.66, 0.63, 0.62, 0.61, 0.60)) if (k 1) { yt1 - z[,2:k] res - lm(yt ~ xt1 + 1 + yt1) } else res - lm(yt ~ xt1 + 1) res.sum - summary(res) STAT - res.sum$coefficients[2,1]/res.sum$coefficients[2,2] } if (kind==3) { table - cbind(c(4.38, 4.15, 4.04, 3.99, 3.98, 3.96), c(3.95, 3.8, 3.73, 3.69, 3.68, 3.66), c(3.6, 3.5, 3.45, 3.43, 3.42, 3.41), c(3.24, 3.18, 3.15, 3.13, 3.13, 3.12), c(1.14, 1.19, 1.22, 1.23, 1.24, 1.25), c(0.8, 0.87, 0.9, 0.92, 0.93, 0.94), c(0.5, 0.58, 0.62, 0.64, 0.65, 0.66), c(0.15, 0.24, 0.28, 0.31, 0.32, 0.33)) if (k 1) { yt1 - z[,2:k] res - lm(yt ~ xt1 + 1 + tt + yt1) } else res - lm(yt ~ xt1 + 1 + tt) res.sum - summary(res) STAT - res.sum$coefficients[2,1]/res.sum$coefficients[2,2] } table - -table tablen - dim(table)[2] tableT - c(25, 50, 100, 250, 500, 1e+05) tablep - c(0.01, 0.025, 0.05, 0.1, 0.9, 0.95, 0.975, 0.99) tableipl - numeric(tablen) for (i in (1:tablen)) tableipl[i] - approx(tableT, table[,i], n, rule = 2)$y interpol - approx(tableipl, tablep, STAT, rule = 2)$y if (is.na(approx(tableipl, tablep, STAT, rule = 1)$y)) if (interpol == min(tablep)) warning(p-value smaller than printed p-value) else warning(p-value greater than printed p-value) PVAL - interpol PARAMETER - k - 1 METHOD - Augmented Dickey-Fuller Test names(STAT) - Dickey-Fuller names(PARAMETER) - Lag order structure(list(statistic = STAT, parameter = PARAMETER,alternative = The series is stationary, p.value = PVAL, method = METHOD, data.name = DNAME),class = htest) } Amir Safari wrote: Hi All , Could you please tell using which library ,Dickey-Fuller Test can be run? Thanks a lot __ [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html__ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] R: looping
hi all i have a simple question. code is displayed below. how can i use a vectorised command in order to do this (ie replace the loop)? (ie apply, lapply, sweep, etc) z-matrix(c(1:9),3,3) top-c(1.5,5.5,9) for (i in 1:3) z[z[,i]top[i]]-top[i]__ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] R: looping
sorry everyone the previous code seems to have been wrong. this is the corrected code ie the last line z-matrix(c(1:9),3,3) top-c(1.5,5.5,9) for (i in 1:3) z[,i][z[,i]top[i]]-top[i] / allan Huntsinger, Reid wrote: Are you sure that's what you want to do? The subscript is a logical vector of length 3, subscripting a 3 x 3 matrix, so you're treating the matrix as a vector (stacked columns) and recycling the indices. The first iteration modifies 6 entries of the matrix. It looks like you want to replace the entries in the ith column which exceed top[i] by top[i] (lost the ,i in the subscript expression in copying, perhaps). That could be done in several ways. You can either create a matrix out of top of the same shape as z and then compare element-by-element, with pmin for example, or use the recycling rule. That latter is cleaner if z is transposed, but t(pmin(t(z),top)) works. You could use apply as well, like apply(z,1,function(x) pmin(x,top)) to compare each row with the vector top, but you have to transpose the result. I don't see any advantage to this, though. Reid Huntsinger -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Clark Allan Sent: Friday, May 20, 2005 10:01 AM To: r-help@stat.math.ethz.ch Subject: [R] R: looping hi all i have a simple question. code is displayed below. how can i use a vectorised command in order to do this (ie replace the loop)? (ie apply, lapply, sweep, etc) z-matrix(c(1:9),3,3) top-c(1.5,5.5,9) for (i in 1:3) z[,i][z[,i]top[i]]-top[i] -- Notice: This e-mail message, together with any attachment...{{dropped}} __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] R: function code
HI sorry to be a nuisance to all!!! how can i see the code of a particular function? e.g. nnet just as an example__ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] R: VAR package
hi all i would like to fit VAR, vector autoregressive models, to a data set. is there a package in R that does this?__ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] R:var models
HI ALL i have found two package: dse and dse2. are there others__ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] r: eviews and r // eigen analysis
hi all i have a question that about the eigen analysis found in R and in eviews. i used the same data set in the two packages and found different answers. which is incorrect? the data is: aa ( a correlation matrix) 1 0.9801 0.9801 0.9801 0.9801 0.9801 1 0.9801 0.9801 0.9801 0.9801 0.9801 1 0.9801 0.9801 0.9801 0.9801 0.9801 1 0.9801 0.9801 0.9801 0.9801 0.9801 1 now svd(aa) $d [1] 4.9204 0.0199 0.0199 0.0199 0.0199 $u [,1] [,2] [,3] [,4] [,5] [1,] -0.4472136 9.283999e-18 1.939587e-17 -2.101554e-15 0.8944272 [2,] -0.4472136 8.089763e-01 7.115435e-17 3.091235e-01 -0.2236068 [3,] -0.4472136 2.178563e-02 8.226578e-18 -8.657513e-01 -0.2236068 [4,] -0.4472136 -4.153810e-01 -7.071068e-01 2.783139e-01 -0.2236068 [5,] -0.4472136 -4.153810e-01 7.071068e-01 2.783139e-01 -0.2236068 $v [,1][,2] [,3] [,4] [,5] [1,] -0.4472136 0. 0.00e+00 0.000 0.8944272 [2,] -0.4472136 0.80897632 -4.976488e-17 0.3091235 -0.2236068 [3,] -0.4472136 0.02178563 1.077421e-17 -0.8657513 -0.2236068 [4,] -0.4472136 -0.41538097 -7.071068e-01 0.2783139 -0.2236068 [5,] -0.4472136 -0.41538097 7.071068e-01 0.2783139 -0.2236068 the results from Eviews is: eigenvectors = (note that Eviews arranges the eigen vectors in ascending order of the size of the eigen values) 0.305963 -0.266024 -0.219066 -0.7665690.447214 0.315257 -0.6038710.0757720.5746400.447214 0.4619580.7268610.1993850.1360620.447214 -0.4826090.185567 -0.7007050.2041240.447214 -0.600569 -0.0425340.644614 -0.1482580.447214 eigen values = 0.019900 0.019900 0.019900 0.019900 4.920400 NOTE THAT THE EIGEN VALUES ARE THE SAME BUT THE EIGEN VECTORS ARE NOT!!! why is this so? if one sets aa= 1.000.500.25 0.501.000.35 0.250.351.00 then both packages give the same answers.__ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] R: LIST function and LOOPS
hi thanx for the help. i dont want to use matrices. i solve my problem, see the example below. the set.seed is used because in my actual application i need to generate INDEPENDENT variables. will this ensure that the variables are independent? z3-function(w) { for (i in 1:w) { ss-0 for (j in 1:5) { set.seed(j+1+(i-1)*6) r-rnorm(1) ss-ss+r a-list(ss=ss,r=r) } print(paste( i=,i,)) print(a) } } z3(3) z3(3) [1] i= 1 $ss [1] -2.213343 $r [1] 0.269606 [1] i= 2 $ss [1] -2.904235 $r [1] -1.480568 [1] i= 3 $ss [1] -0.01516304 $r [1] 0.9264592 thanx again *** allan ### ### ### ### ### ### Adaikalavan Ramasamy wrote: You will need to capture the value of ss at the end of each 'i' as such z4 -function(w){ output - numeric(w) for (i in 1:w){ set.seed(i+6) # this is redundant line ss-0 for (j in 1:5){ set.seed(j+1+(i-1)*6) r-rnorm(1) ss-ss+r } output[i] - ss } return(output) } BTW, I do not think it is a good idea to set.seed() so many times. To answer you more general question, see if the following is useful. I am trying to simulate 'n' values from a standard normal distribution but 'n' is random variable itself. f -function(w, lambda=3){ tmp - list(NULL) for (i in 1:w){ n - 1 + rpois(1, lambda=lambda) # number of simulation required tmp[[ i ]] - rnorm(n) } # flatten the list into a ragged matrix out.lengths - sapply(tmp, length) out - matrix( nr=w, nc=max( out.lengths ) ) rownames(out) - paste(w =, 1:w) for(i in 1:w) out[i, 1:out.lengths[i] ] - tmp[[i]] return(out) } f(6, lambda=3) It is not very elegant but I hope that helps you out somehow. Regards, Adai On Thu, 2005-03-10 at 10:16 +0200, Clark Allan wrote: hi all another simple question. i've written a dummy program so that you get the concept. (the code could be simplfied such that there are no loops. but lets leave the loops in for now.) z1-function(w) { for (i in 1:w) { set.seed(i+6) ss-0 for (j in 1:5) { set.seed(j+1+(i-1)*6) r-rnorm(1) ss-ss+r } list(ss=ss) } } check.1-z1(3) check.1 the results is: $ss [1] -0.01516304 what i want is something that looks like this: j=1 $ss [1] -2.213343 j=2 $ss [1] -2.904235 j=3 $ss [1] -0.01516304 i know that i could use the print command. (see z2) z2-function(w) { for (i in 1:w) { set.seed(i+6) ss-0 for (j in 1:5) { set.seed(j+1+(i-1)*6) r-rnorm(1) ss-ss+r } print(ss) } } check.2-z2(3) check.2 check.2-z2(3) [1] -2.213343 [1] -2.904235 [1] -0.01516304 check.2 [1] -0.01516304 the problem with z2 is that only the last value is saved. what i could do is use matrices like the following: (but i dont want to do this AND WOULD PREFER TO USE list.) z3-function(w) { results.-matrix(nrow=w,ncol=1) colnames(results.)-c(ss) for (i in 1:w) { set.seed(i+6) ss-0 for (j in 1:5) { set.seed(j+1+(i-1)*6) r-rnorm(1) ss-ss+r } results.[i,1]-ss } results. } check.3-z3(3) check.3 check.3 ss [1,] -2.21334260 [2,] -2.90423463 [3,] -0.01516304 what if i have a new program (something different) and i want the following: j=1 $a 1 2 3 $b 1 2 3 4 5 $c 1 ### j=2 $a 11 21 31 $b 11 21 31 41 51 $c 11 ### j=3 $a 21 22 32 $b 21 22 32 42 52 $c 21 MATRICES SEEMS TO BE A GOOD WAY OF DOING THIS (but then you would have to set up three matrices, one for a,b and c). BUT WHAT IF I WANT TO USE THE LIST FUNCTION? i.e. there is a list in the first loop that i want to display! sorry for the long mail. *** ALLAN __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting
[R] R: generating independent vectors
hi all i would like to generate independent vectors. i have included the code below. i display the correlation matrix of the n*p (n=the number of samples, p= the number of variables) matrix. what i find is that as n increases, the correlation matrix tends to an identity matrix. i.e. independence. for small samples (see examples below, for n=20, p=5 ; n=50,p=5, n=100,p=5; n=1,p=5) the variables does not appear to be independent. note that i have not tested this statement statistically. ARE these variables independent? by setting the seed for each variable run i HOPE that the variables are now independent. IS this true??? if not does anyone know how to generate these independent variables? how does R generate its random variables? does it use the box muller technique? if so how does it generate the random uniform variables? thanking you in advance!!! *** allan IND-function(rows.=10,col.=3) { a-matrix(nrow=rows.,ncol=col.) for (j in 1:col.) { set.seed(j) r-rnorm(rows.) a[,j]-r } #list(a=a,cor=cor(a)) cor(a) } IND(rows.=10,col.=3) IND(rows.=20,col.=5) [,1][,2][,3][,4] [,5] [1,] 1. 0.25677165 -0.14882130 -0.09190797 0.1562481 [2,] 0.25677165 1. 0.02585515 0.13735712 -0.1443301 [3,] -0.14882130 0.02585515 1. -0.11311416 0.1437001 [4,] -0.09190797 0.13735712 -0.11311416 1. 0.1833647 [5,] 0.15624807 -0.14433011 0.14370006 0.18336467 1.000 IND(rows.=50,col.=5) [,1][,2] [,3][,4][,5] [1,] 1.00 0.07915025 0.0009239851 -0.14102117 -0.07335342 [2,] 0.0791502463 1. -0.1764530631 0.10021081 0.19742285 [3,] 0.0009239851 -0.17645306 1.00 0.02968062 0.14543350 [4,] -0.1410211698 0.10021081 0.0296806188 1. 0.07234953 [5,] -0.0733534183 0.19742285 0.1454335014 0.07234953 1. IND(rows.=100,col.=5) [,1] [,2] [,3] [,4] [,5] [1,] 1. -0.1537208 -0.023741715 -0.135245915 0.01961224 [2,] -0.15372076 1.000 -0.141796984 0.157219334 0.15518443 [3,] -0.02374171 -0.1417970 1.0 0.005865698 0.19118563 [4,] -0.13524592 0.1572193 0.005865698 1.0 0.07345299 [5,] 0.01961224 0.1551844 0.191185627 0.073452993 1. IND(rows.=1,col.=5) [,1] [,2] [,3] [,4] [,5] [1,] 1.0 0.015928444 -0.008288940 -0.005646904 0.006936662 [2,] 0.015928444 1.0 -0.005444611 0.005242395 -0.008246009 [3,] -0.008288940 -0.005444611 1.0 0.007277489 0.012299247 [4,] -0.005646904 0.005242395 0.007277489 1.0 0.001918704 [5,] 0.006936662 -0.008246009 0.012299247 0.001918704 1.0__ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] R: generating independent vectors
thanx. this function works and does exactly what i want Chuck Cleland wrote: You might try mvrnorm() in MASS. library(MASS) mvrnorm(n=10, mu=rep(0, 3), Sigma=diag(3), empirical=TRUE) Clark Allan wrote: hi all i would like to generate independent vectors. i have included the code below. i display the correlation matrix of the n*p (n=the number of samples, p= the number of variables) matrix. what i find is that as n increases, the correlation matrix tends to an identity matrix. i.e. independence. for small samples (see examples below, for n=20, p=5 ; n=50,p=5, n=100,p=5; n=1,p=5) the variables does not appear to be independent. note that i have not tested this statement statistically. ARE these variables independent? by setting the seed for each variable run i HOPE that the variables are now independent. IS this true??? if not does anyone know how to generate these independent variables? how does R generate its random variables? does it use the box muller technique? if so how does it generate the random uniform variables? thanking you in advance!!! *** allan IND-function(rows.=10,col.=3) { a-matrix(nrow=rows.,ncol=col.) for (j in 1:col.) { set.seed(j) r-rnorm(rows.) a[,j]-r } #list(a=a,cor=cor(a)) cor(a) } IND(rows.=10,col.=3) IND(rows.=20,col.=5) [,1][,2][,3][,4] [,5] [1,] 1. 0.25677165 -0.14882130 -0.09190797 0.1562481 [2,] 0.25677165 1. 0.02585515 0.13735712 -0.1443301 [3,] -0.14882130 0.02585515 1. -0.11311416 0.1437001 [4,] -0.09190797 0.13735712 -0.11311416 1. 0.1833647 [5,] 0.15624807 -0.14433011 0.14370006 0.18336467 1.000 IND(rows.=50,col.=5) [,1][,2] [,3][,4][,5] [1,] 1.00 0.07915025 0.0009239851 -0.14102117 -0.07335342 [2,] 0.0791502463 1. -0.1764530631 0.10021081 0.19742285 [3,] 0.0009239851 -0.17645306 1.00 0.02968062 0.14543350 [4,] -0.1410211698 0.10021081 0.0296806188 1. 0.07234953 [5,] -0.0733534183 0.19742285 0.1454335014 0.07234953 1. IND(rows.=100,col.=5) [,1] [,2] [,3] [,4] [,5] [1,] 1. -0.1537208 -0.023741715 -0.135245915 0.01961224 [2,] -0.15372076 1.000 -0.141796984 0.157219334 0.15518443 [3,] -0.02374171 -0.1417970 1.0 0.005865698 0.19118563 [4,] -0.13524592 0.1572193 0.005865698 1.0 0.07345299 [5,] 0.01961224 0.1551844 0.191185627 0.073452993 1. IND(rows.=1,col.=5) [,1] [,2] [,3] [,4] [,5] [1,] 1.0 0.015928444 -0.008288940 -0.005646904 0.006936662 [2,] 0.015928444 1.0 -0.005444611 0.005242395 -0.008246009 [3,] -0.008288940 -0.005444611 1.0 0.007277489 0.012299247 [4,] -0.005646904 0.005242395 0.007277489 1.0 0.001918704 [5,] 0.006936662 -0.008246009 0.012299247 0.001918704 1.0 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- Chuck Cleland, Ph.D. NDRI, Inc. 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 452-1424 (M, W, F) fax: (917) 438-0894__ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] R: LIST function and LOOPS
hi all another simple question. i've written a dummy program so that you get the concept. (the code could be simplfied such that there are no loops. but lets leave the loops in for now.) z1-function(w) { for (i in 1:w) { set.seed(i+6) ss-0 for (j in 1:5) { set.seed(j+1+(i-1)*6) r-rnorm(1) ss-ss+r } list(ss=ss) } } check.1-z1(3) check.1 the results is: $ss [1] -0.01516304 what i want is something that looks like this: j=1 $ss [1] -2.213343 j=2 $ss [1] -2.904235 j=3 $ss [1] -0.01516304 i know that i could use the print command. (see z2) z2-function(w) { for (i in 1:w) { set.seed(i+6) ss-0 for (j in 1:5) { set.seed(j+1+(i-1)*6) r-rnorm(1) ss-ss+r } print(ss) } } check.2-z2(3) check.2 check.2-z2(3) [1] -2.213343 [1] -2.904235 [1] -0.01516304 check.2 [1] -0.01516304 the problem with z2 is that only the last value is saved. what i could do is use matrices like the following: (but i dont want to do this AND WOULD PREFER TO USE list.) z3-function(w) { results.-matrix(nrow=w,ncol=1) colnames(results.)-c(ss) for (i in 1:w) { set.seed(i+6) ss-0 for (j in 1:5) { set.seed(j+1+(i-1)*6) r-rnorm(1) ss-ss+r } results.[i,1]-ss } results. } check.3-z3(3) check.3 check.3 ss [1,] -2.21334260 [2,] -2.90423463 [3,] -0.01516304 what if i have a new program (something different) and i want the following: j=1 $a 1 2 3 $b 1 2 3 4 5 $c 1 ### j=2 $a 11 21 31 $b 11 21 31 41 51 $c 11 ### j=3 $a 21 22 32 $b 21 22 32 42 52 $c 21 MATRICES SEEMS TO BE A GOOD WAY OF DOING THIS (but then you would have to set up three matrices, one for a,b and c). BUT WHAT IF I WANT TO USE THE LIST FUNCTION? i.e. there is a list in the first loop that i want to display! sorry for the long mail. *** ALLAN__ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] R: simulation
hi all a simple question i want to run simulations in r. i however want the experiments to be repeated at a later time with exactly the same numbers by other users. can i set the random number seed for rnorm in some way? e.g. is there some arguement that goes with rnorm? please supply an example regards Allan__ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] R: simulation
Hi thanx for the reply. i used your code and pasted it into R and ran it a few times. the output is below. what i want is to get the same output every time the program is run. is this possible? another question? x-rnorm(100) y-rnorm(100) is x and y independent? rnorm(1) [1] 0.4251004 rnorm(1) [1] -0.2386471 rnorm(1) [1] 1.058483 rnorm(1) [1] 0.8864227 rnorm(1) [1] -0.619243 rnorm(1) [1] 2.206102 rnorm(1) [1] -0.2550270 rnorm(1) [1] -1.424495 rnorm(1) [1] -0.1443996 rnorm(1) [1] 0.2075383 rnorm(1) [1] 2.307978 rnorm(1) [1] 0.1058024 Dimitris Rizopoulos wrote: look at ?set.seed, e.g., rnorm. - function(seed, ...){ set.seed(seed) rnorm(...) } # rnorm.(100, 1, 2) I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/16/336899 Fax: +32/16/337015 Web: http://www.med.kuleuven.ac.be/biostat/ http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm - Original Message - From: Clark Allan [EMAIL PROTECTED] To: r-help@stat.math.ethz.ch Sent: Friday, March 04, 2005 12:07 PM Subject: [R] R: simulation hi all a simple question i want to run simulations in r. i however want the experiments to be repeated at a later time with exactly the same numbers by other users. can i set the random number seed for rnorm in some way? e.g. is there some arguement that goes with rnorm? please supply an example regards Allan __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html__ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] r: functions
hi all i have a function that uses two inputs, say xdata and ydata. An example is the following, simple1-function(xdata,ydata) { ofit-lm(ydata~xdata) list(ofit) } say i use arbitray number for xdata and ydata such that D = x1 x2 y 1 1 10 2 6 6 3 10 7 x-D[,1:2] and y-D[,3] if one uses these inputs and rund the program we get the following: simple(xdata=x,ydata=y) Error in model.frame(formula, rownames, variables, varnames, extras, extranames, : invalid variable type why does this happen! i can get results if i change the program as follows: simple2-function(xdata,ydata) { ofit-lm(as.matrix(ydata)~as.matrix(xdata)) list(ofit) } but then the variable names, if they exist, are not preserved. how can i preserve these names. the results are now: simple2(xdata=x,ydata=y) [[1]] Call: lm(formula = as.matrix(ydata) ~ as.matrix(xdata)) Coefficients: (Intercept) as.matrix(xdata)x1 as.matrix(xdata)x2 -6 21 -5 i've tried converting xdata and ydata to data frames but i still get errors. simple3-function(xdata,ydata) { xdata-as.data.frame(xdata) ydata-as.data.frame(ydata) ofit-lm(ydata~xdata) list(ofit) } i.e. simple3(xdata=x,ydata=y) Error in model.frame(formula, rownames, variables, varnames, extras, extranames, : invalid variable type please help! thanking you in advance *** allan__ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] r: functions
hi i still get the same error. i must be doing something wrong. i have typed in all of the steps i used. D x1 x2 y 1 1 1 10 2 2 6 6 3 3 10 7 x-D[,1:2] y-D[,3] x x1 x2 1 1 1 2 2 6 3 3 10 y [1] 10 6 7 simple1 - function(xdata, ydata){ + ofit - substitute(lm(ydata~xdata)) + list(eval.parent(ofit)) + } simple1(xdata=x, ydata=y) Error in model.frame(formula, rownames, variables, varnames, extras, extranames, : invalid variable type I STILL GET THE ERROR. WHAT AM I DOING WRONG? Dimitris Rizopoulos wrote: There was a similar question about one week ago regarding the use of table(x,y). One approach could be to use the following: simple1 - function(xdata, ydata){ ofit - substitute(lm(ydata~xdata)) list(eval.parent(ofit)) } # simple1(xdata=x, ydata=y) lm(y~x) I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/16/336899 Fax: +32/16/337015 Web: http://www.med.kuleuven.ac.be/biostat/ http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm - Original Message - From: Clark Allan [EMAIL PROTECTED] To: r-help@stat.math.ethz.ch Sent: Thursday, February 24, 2005 10:16 AM Subject: [R] r: functions hi all i have a function that uses two inputs, say xdata and ydata. An example is the following, simple1-function(xdata,ydata) { ofit-lm(ydata~xdata) list(ofit) } say i use arbitray number for xdata and ydata such that D = x1 x2 y 1 1 10 2 6 6 3 10 7 x-D[,1:2] and y-D[,3] if one uses these inputs and rund the program we get the following: simple(xdata=x,ydata=y) Error in model.frame(formula, rownames, variables, varnames, extras, extranames, : invalid variable type why does this happen! i can get results if i change the program as follows: simple2-function(xdata,ydata) { ofit-lm(as.matrix(ydata)~as.matrix(xdata)) list(ofit) } but then the variable names, if they exist, are not preserved. how can i preserve these names. the results are now: simple2(xdata=x,ydata=y) [[1]] Call: lm(formula = as.matrix(ydata) ~ as.matrix(xdata)) Coefficients: (Intercept) as.matrix(xdata)x1 as.matrix(xdata)x2 -6 21 -5 i've tried converting xdata and ydata to data frames but i still get errors. simple3-function(xdata,ydata) { xdata-as.data.frame(xdata) ydata-as.data.frame(ydata) ofit-lm(ydata~xdata) list(ofit) } i.e. simple3(xdata=x,ydata=y) Error in model.frame(formula, rownames, variables, varnames, extras, extranames, : invalid variable type please help! thanking you in advance *** allan __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html__ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Re: r: functions
hi all i worked it out. the following code seems to work. thanx for those who replied to previous questions. simple1-function(xdata,ydata) { DATA-data.frame(ydata,xdata) ofit-summary(lm(ydata~.,data=DATA)) list(ofit) } simple1(x,y) simple1(x,y) [[1]] Call: lm(formula = ydata ~ ., data = DATA) Coefficients: (Intercept) x1 x2 -6 21 -5 *** allan Clark Allan wrote: hi all i have a function that uses two inputs, say xdata and ydata. An example is the following, simple1-function(xdata,ydata) { ofit-lm(ydata~xdata) list(ofit) } say i use arbitray number for xdata and ydata such that D = x1 x2 y 1 1 10 2 6 6 3 10 7 x-D[,1:2] and y-D[,3] if one uses these inputs and rund the program we get the following: simple(xdata=x,ydata=y) Error in model.frame(formula, rownames, variables, varnames, extras, extranames, : invalid variable type why does this happen! i can get results if i change the program as follows: simple2-function(xdata,ydata) { ofit-lm(as.matrix(ydata)~as.matrix(xdata)) list(ofit) } but then the variable names, if they exist, are not preserved. how can i preserve these names. the results are now: simple2(xdata=x,ydata=y) [[1]] Call: lm(formula = as.matrix(ydata) ~ as.matrix(xdata)) Coefficients: (Intercept) as.matrix(xdata)x1 as.matrix(xdata)x2 -6 21 -5 i've tried converting xdata and ydata to data frames but i still get errors. simple3-function(xdata,ydata) { xdata-as.data.frame(xdata) ydata-as.data.frame(ydata) ofit-lm(ydata~xdata) list(ofit) } i.e. simple3(xdata=x,ydata=y) Error in model.frame(formula, rownames, variables, varnames, extras, extranames, : invalid variable type please help! thanking you in advance *** allan__ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] r: ridge regression
hello all some help required once again! does anyone recall the equations for the following ridge constants? 1. hoerl and kennard (1970) 2. hoerl, kennard and baldwin (1975) 3. lawless and wang could you also specify whether or not one has to transform the X and Y variables. if so , how and in which cases. a worked example with a data set would be most helpful. thanking you in advance *** Allan__ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] R: ridge regression
hi all a technical question for those bright statisticians. my question involves ridge regression. definition: n=sample size of a data set X is the matrix of data with , say p variables Y is the y matrix i.e the response variable Z(i,j) = ( X(i,j)- xbar(j) / [ (n-1)^0.5* std(x(j))] Y_new(i)=( Y(i)- ybar(j) ) / [ (n-1)^0.5* std(Y(i))](note that i have scaled the Y matrix as well) k is the ridge constant the ridge estimate for the betas is = inverse(Z'Z+kI)*Z'Y_new=W*Z'Y_new the associated variance covariance matrix sigma*W*(Z'Z)*W where sigma is the residual variance based on the transformed variables if we transform the variables back to the original variables the beta estimates are now: beta(j)= std(y)*betaridge(j)/std(x(j)) but what is the covariance matrix of these estimates??? i know that this might not be the correct forum for this question, but since i know that many users are statisticians i know that i will get an informed response.__ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] R: ridge regression
hi Andy and other r users i never gave the full picture. beta(j)= std(y)*betaridge(j)/std(x(j)) for j=1,2,...p but beta(0) = ybar- sum( i= 1 to p, betaridge(i)*xbar(j) ) note that ybar and the xbars are estimated parameters. we can split the covariance matrix into three sections namely: 1. var(beta(0)) 2. covar(beta(0), other betas) and 3. covar(other betas) , (this is your answer, which was correct) but now i need var(beta(0)) and covar(beta(0), other betas) any suggestions! Liaw, Andy wrote: If I'm not mistaken, you only need to know that if V is the covariance matrix of a random vector X, then the covariance of the linear transformation AX + b is AVA'. Substitute betahat for X, and figure out what A is and you're set. (b is 0 in your case.) Andy From: Clark Allan hi all a technical question for those bright statisticians. my question involves ridge regression. definition: n=sample size of a data set X is the matrix of data with , say p variables Y is the y matrix i.e the response variable Z(i,j) = ( X(i,j)- xbar(j) / [ (n-1)^0.5* std(x(j))] Y_new(i)=( Y(i)- ybar(j) ) / [ (n-1)^0.5* std(Y(i))] (note that i have scaled the Y matrix as well) k is the ridge constant the ridge estimate for the betas is = inverse(Z'Z+kI)*Z'Y_new=W*Z'Y_new the associated variance covariance matrix sigma*W*(Z'Z)*W where sigma is the residual variance based on the transformed variables if we transform the variables back to the original variables the beta estimates are now: beta(j)= std(y)*betaridge(j)/std(x(j)) but what is the covariance matrix of these estimates??? i know that this might not be the correct forum for this question, but since i know that many users are statisticians i know that i will get an informed response. -- Notice: This e-mail message, together with any attachment...{{dropped}} __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] R: optimisation
hi all other than optim, optimise, and some other related optimisation functions are there any optimisation packages in R?__ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] R: functions problem
hi all how can i see the code inside a particular function? i know one can simply type the function, eg ls, but sometimes when this is done one will get UseMethod(some function name). (One could also use body but i have the same problem in this case. )How does one see the code in this case?__ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] R: optim problems and neural networks
hi all i have two questions: 1. i have been having problems with using the optim function. I have tried to define the matrix containing the parameters as a matrix, ie not simply p*1. The function does not allow this. Am i correct? 2. in the code below i have tried to calculate the weights of a basic feed forward neural network (I know that i could use the nnet package.). the aim is to learn how to code and become familiar with the language. note that the code still has to be generalised and does not allow for skip layers. No error checking on the parameter estimates are included yet. when i run the above code, i get the following error, Error in fn(par, ...) : recursive default argument reference . why does this happen? As a simple case, use x-c(1,2,3) and y-2+3*x. I know that there is no errors. I simply want the code to work at this stage. NNET-function(p=2,size=1,skip=T,x,y) { p-p x-x x-as.matrix(x) x-cbind(rep(1,nrow(x)),x) y-y size-size skip-skip betas-matrix(1:((p+1)*size),nrow=1+p,ncol=size) f3-function (betas,x,y,p=p) { #b1-matrix(betas,nrow=p,ncol=size) #the input to hidden layer section hl-x%*%betas[1:p,] hl_act-(exp(hl)-1)/(1+exp(hl)) #b2-matrix(betas[(1+p*size):((1+p)*size)],nrow=size) #the hidden layer to output section ol-hl_act%*%betas[p+1,] # the square of the residuals e-(y-ol) fit_nn-(ol) # the sums of squares / 2 E-sum(e*e)/2 } optim(c(rnorm((p+1)*size)),f3,x=x,y=y,hessian=T,method=c(BFGS)) } NNET(p=2,x=x,y=y)__ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] R: nnet questions
hi all i'm new to the area of neural networks. i've been reading some references and seem to understand some of the learning algorithms. i am very familiar with regression and would just like to see how neural nets handle this problem so i've been using the nnet package. i simply want to use a 3 layer neural net, ie 1 input, 1 hidden layer (where the hidden layer is linear, since i want to basically perform regression analysis by means of neural nets) and 1 output layer. the x and y vector was simulated as follows: x-1:100 x [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 [19] 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 [37] 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 [55] 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 [73] 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 [91] 91 92 93 94 95 96 97 98 99 100 y-2+5*x+rnorm(100)*5 y [1] 8.789605 11.151109 14.622276 30.381379 19.328647 29.317038 33.793720 39.557390 51.939294 45.045965 [11] 58.783991 63.191745 72.882202 79.184778 85.034551 94.446000 89.243004 88.223547 106.327683 104.424668 [21] 103.057648 112.855778 111.777823 108.359485 128.956152 127.369102 128.784481 139.760279 151.959887 152.014623 [31] 158.869586 167.030970 166.711160 177.415680 173.542293 182.484224 179.767128 192.284343 196.173830 202.353030 [41] 220.449623 213.410307 216.746041 219.812526 230.440402 230.759429 239.311279 244.151390 248.637023 254.648298 [51] 262.694237 253.619539 276.975714 280.395284 280.173787 286.813617 284.766870 296.705692 295.110064 304.709464 [61] 305.650793 310.128992 314.035624 314.649213 322.958865 333.640203 342.538307 340.546359 342.433629 344.720633 [71] 354.115051 363.631246 371.479886 367.066764 377.184512 386.634677 392.310577 386.151325 400.345393 408.831710 [81] 413.999148 405.009358 418.679828 418.388427 419.282955 432.329471 433.448313 444.166060 447.773185 455.103503 [91] 448.588598 464.410358 465.565875 478.677403 478.306390 479.565728 487.681689 491.422090 502.468491 500.385458 i then went about to use the nnet function: a.net-nnet(y~x,linout=T,size=1) # weights: 4 initial value 8587786.130082 iter 10 value 2086583.979646 final value 2079743.529111 converged NOTE: the function said that four weights were estimated. This is correct as shown below. the model can be represented as: input ---(w1)---hidden ---(w2)--- output x --a1+w1*x -- a2+w2*(a1+w1*x) where: wi are the weights, i=1,2 x is an input pattern further results were: summary(a.net) a 1-1-1 network with 4 weights options were - linear output units b-h1 i1-h1 -276.48 -295.11 b-o h1-o 254.92 764.72 is the following statement correct? (i think that it is!) a1= b-h1 w1= i1-h1 a2= b-o w2= h1-o If the hidden layer and the output layers are both LINEAR then the following should be true: 1. 2= a2+a1*w2 2. 5= w1*w2 THIS IS NOT THE CASE, see the results. The only thing that i can think of thats happening is that the activation function from the hidden layer is not linear. Is this correct since i used the linout=T arguement? are we able to change the activation function from the hidden layer? two other questions: 1. with regard to the size arguement, how does one know how many nodes are in the hidden layer? (this might be a silly question.) e.g we might have 2 hidden layers both with 3 nodes. 2. are we able to plot the drop in the error function as a function of the epochs? hope someone can help thanking you!!!__ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html