Re: [R] How to divide each column with its own value

2012-09-17 Thread Daniel Malter
It's not quite clear what you want to do. Is it just this? a-c(1,2,3,4) dim(a)-c(2,2) a/a This gives the element by element ratio. HTH, Daniel shukor wrote Hi, I have a matrix as below: mat= [,1] [,2] [,3] [1,]147 [2,]258 [3,]369 What

Re: [R] Cragg-Donald Wald F statistic (weak instruments)

2012-09-17 Thread Daniel Malter
in Stock and Yogo (2005). dm. Daniel Malter wrote You find code to compute the Cragg-Donald Wald F test statistic to test for weak instruments (e.g., Stock and Yogo, 2005) below with a working example. The code reproduces the results from Stata 12 using the same data (see bottom of this email

Re: [R] Help: a matrix exponential

2012-09-08 Thread Daniel Malter
This is a matrix algebra problem, not an R problem. ej fails because betaligne and ZIcolone are not conformable matrices. dim(betaligne) 1 2 dim(ZIcolone) 76 1 Let a matrix be m x n, then you can only matrix multiply it with a matrix that is n x k (where m and k are arbitrary positive

[R] Cragg-Donald Wald F statistic (weak instruments)

2012-09-06 Thread Daniel Malter
. The Cragg-Donald Wald F statistic is the smallest of the eigenvalues of G (see the output of eigen(G) below). Critical values are found in Stock and Yogo (2005). HTH, Daniel Malter -- View this message in context: http://r.789695.n4.nabble.com/Cragg-Donald-Wald-F-statistic-weak-instruments

Re: [R] a newbie seeking for a simple problem

2012-09-02 Thread Daniel Malter
As df2 has only one column and is thus effectively a variable in this case, you don't even need to merge. df1[df1$gene_name%in%df2$gene_name , ] should do. HTH, Daniel wong, honkit (Stephen) wrote Dear Experienced R users, I have a looks-like simple but complicated problem urgently

Re: [R] how to append datasets with the same name pattern as they are created within a for loop

2012-08-26 Thread Daniel Malter
Hi, You can use rbind(). E.g., id-rep(1:10,each=10) x-rnorm(100) y-rnorm(100) d-data.frame(id,x,y) rm(id,x,y) newdata-data.frame() for(i in 1:10){ newdata-rbind(newdata,split(d,d$id)[[i]]) print(newdata) } The resulting data.frame newdata has rbind-ed all split elements of d (in this case

Re: [R] vectors as function input

2012-08-24 Thread Daniel Malter
The function you programed expects you to provide 7 arguments. In the first case, you explicitly specify each of the seven arguments, i.e., you tell the function: this is yu, this is yf, and so forth. In the second case, you only specify 2 arguments, t and par[1,1:16]. So the function thinks that

Re: [R] apply a function separately on each element of a list

2012-08-24 Thread Daniel Malter
The easiest way may be to use lmList in the nlme library: #simulate data d-rep(1:10,each=10) x-rnorm(100) e-rnorm(100) y-2*x+e require(nlme) #or install and load package lmList(y~x|d) #predicted values are obtained with: predict(lmList(y~x|d) HTH, Daniel jeff6868 wrote Hi everybody,

[R] Retrieve autocorrelation-corrected errors from gls (nlme) or gamm (mgcv)

2012-08-21 Thread Daniel Malter
Hi, In the example below, I am modeling the dependent variable Y as a function of X when the errors are autoregressive at the first lag. There is a number of ways/functions with which to model this. arima (tseries), gls (nlme), and gamm should produce similar results in the simulated example

[R] Consolidate column contents of equally named columns

2012-04-28 Thread Daniel Malter
Hi, I have a data frame whose first row (not the header) contains the true column names. The same column name can occur multiple times in the dataset. Columns with equal names are not adjacent, and for each observation only one of the equally named columns contains the actual data (see the

Re: [R] Remove leading and trailing white spaces

2012-03-20 Thread Daniel Malter
This just saved me a lot of time. Thank you! Daniel -- View this message in context: http://r.789695.n4.nabble.com/Remove-leading-and-trailing-white-spaces-tp907851p4489725.html Sent from the R help mailing list archive at Nabble.com. __

Re: [R] Extracting numbers from a character variable of different types

2012-03-18 Thread Daniel Malter
Assume your year value is x-007/A You want to replace all non-numeric characters (i.e. letters and punctuation) and all zeros with nothing. gsub('[[:alpha:]]|[[:punct:]]|0','',x) Let's say you have a vector with both month and year values (you can separate them). Now we need to identify the

Re: [R] Siegel-Tukey test for equal variability (code)

2012-03-09 Thread Daniel Malter
#The code of rank 1 in the previous post should have read #rank1-apply(iterator1,1,function(x) x+base1) #corrected code below siegel.tukey=function(x,y,id.col=TRUE,adjust.median=F,rnd=-1,alternative=two.sided,mu=0,paired=FALSE,exact=FALSE,correct=TRUE,conf.int=FALSE,conf.level=0.95){

Re: [R] Siegel-Tukey test for equal variability (code)

2012-02-28 Thread Daniel Malter
The previously posted code contains bugs. The code below should work: x: a vector of data y: Group indicator (if id.col=TRUE); data of the second group (if id.col=FALSE). If y is the group indicator it MUST take 0 or 1 to indicate the groups, and x must contain the data for both groups.

[R] How do I get the CEM (coarsened exact matching) package to run?

2012-02-06 Thread Daniel Malter
Hi, I am running a MacBook Pro with OS X 10.6.8. When I try to load library(cem) and run any function, R crashes. Any suggestions as to why this is? Thanks in advance. I think the problem is that I don't have all the infrastructure I need to run CEM, but I have no clue what to do either...

Re: [R] Matching

2011-10-29 Thread Daniel Malter
Your post is unlikely to solicit a helpful response. As you do not adhere to the posting guide, it is quite impossible for us to figure out from your description what is going wrong. Please provide a self-contained example that reproduces the problem (i.e., code with simulated or actual data that

Re: [R] Contrasts with an interaction. How does one specify the dummy variables for the interaction

2011-10-28 Thread Daniel Malter
)-contr.treatment(levels(row)) contrasts(column)-contr.treatment(levels(column)) # Works for Terps fit.terp-glm(counts ~ row + column + row*column, family=poisson(link=log)) summary(fit.terp) HTH, Daniel Malter University of Maryland, College Park John Sorkin wrote: Forgive my resending

Re: [R] Error in optim

2011-10-28 Thread Daniel Malter
The likelihood function is a product. Thus, the log likelihood function is a sum. Your log.lik statement, however, fails to compute the sum, which it should minimize. Hence your optim statement does not know what to optimize because log.lik is a vector of the length of the number of observations

Re: [R] Performing a non parametric Friedman Test

2011-10-25 Thread Daniel Malter
There is a friedman.test() function. Any reason you want to do it by hand? If so, you can do: #Simulated data matrix x-matrix(rnorm(9),3,3,byrow=T) x #Rank matrix r-matrix(rank(x),dim(x)) HTH, Daniel JohnnyJames wrote: My data looks like this: (treatments)

Re: [R] Turning Data Frame Columns into Vectors

2011-10-15 Thread Daniel Malter
You access columns of a data.frame by column indices as in: X[ ,1], X[ ,2], etc. The index before the comma would stand for the row if you wanted to restrict those. The index after the comma captures the column. That said, you typically would not extract rows from the data frame but draw directly

Re: [R] function for handling time

2011-10-15 Thread Daniel Malter
I find your question impossible to answer as you do not provide any description of what the matrix columns actually capture and how the variable in your proposed function relate to the columns of this matrix. Best, Daniel alaios wrote: Dear all I have the following time stamps (in the

Re: [R] Counting the number of integers at one swoop

2011-10-13 Thread Daniel Malter
I think there must be an easier solution, but this works: y - c(0,1,1,3,3,3,5,5,6) x-matrix(0:6,ncol=1) apply(x,1,function(x){length(y[y==x])}) HTH, Daniel Kathie wrote: Dear R users, I'd like to count the number of integers in a vector y. Here is an example. y -

Re: [R] Question about GAMs

2011-10-13 Thread Daniel Malter
I am not an expert on this, but there is a way to check this. You can predict from a gam using predict(ozonea, newdata=...). In the newdata argument you can specify the X-values of interest to you. Thus, you can compare if your predictions are the same when predicted directly from the gam or when

Re: [R] correlation matrix

2011-10-10 Thread Daniel Malter
What a pleasant post to respond to - with self-contained code. :) heat-matrix(0,nrow=dim(xa)[1],ncol=dim(xa)[2]) heat[lower.tri(heat)]-xa[lower.tri(xa)] heat[upper.tri(heat)]-xb[upper.tri(xb)] diag(heat)-1 heat HTH, Daniel 1Rnwb wrote: Hello Gurus I have two correlation matrices 'xa' and

Re: [R] factors in probit regression

2011-10-07 Thread Daniel Malter
You can get an estimate for the omitted baseline category by not estimating the intercept. To do that, type -1 on the right-hand side of the regression statement. If that was your actual question, the simple question, How can I omit the baseline in a regression?, would have sufficed. Moreover, it

Re: [R] Coefficients for lagged plm model variables not calculated

2011-10-06 Thread Daniel Malter
You probably should not do panel data analysis but multiple time series analysis as your T is much larger than N. You only have seven units of observation but some 150 observations on each unit. Also, if the values on each unit of observation are very close to each other between t and t-1, then

Re: [R] ANOVA/ANCOVA Repeated Measure Mixed Model

2011-10-06 Thread Daniel Malter
You are modeling Condition * Stimulus * Group as fully interacted fixed effects. I do not actually think that you would need a complex random effect structure for this. A simple random effect for the individual might suffice. You could try to model this with lmer (in the lme4 library) and inspect

Re: [R] factors in probit regression

2011-10-06 Thread Daniel Malter
I need to quote David Winsemius on this one again: The advancement of science would be safer if you knew what you were doing. Note that the whole model screams at you that it is wrongly modeled. You are running a fully interacted model with factor variables. Thus, you have 19 regressors plus the

Re: [R] how do i put two scatterplots on same graph

2011-10-04 Thread Daniel Malter
?plot ?points You will probably need to get some R basics down as to how to index certain subsets of your data. This you find in any introductory R manual. HTH, Daniel -- View this message in context:

Re: [R] inconsistent behavior of summary function

2011-10-04 Thread Daniel Malter
I have not read the manual, but I drew 1 random normal vectors and 1 random Poisson vectors of length 1 and was unable to reproduce this behavior. Can you provide an example (self-contained code) that reproduces this problem? Thanks, Daniel Jeanne M. Spicer wrote: The summary

Re: [R] Poor performance of Optim

2011-10-02 Thread Daniel Malter
. Further, only numerical optimization will show the behavior discussed in this post for the given reasons. (I hope this post isn't yet another blooper of mine at 5 a.m. in the morning). Best, Daniel Daniel Malter wrote: With respect, your statement that R's optim does not give you a reliable

Re: [R] Poor performance of Optim

2011-10-02 Thread Daniel Malter
And there I caught myself with the next blooper: it wasn't Ben Bolker, it was Bert Gunter who pointed that out. :) Daniel Malter wrote: Ben Bolker sent me a private email rightfully correcting me that was factually wrong when I wrote that ML /is/ a numerical method (I had written sloppily

Re: [R] Help with cast/reshape

2011-10-01 Thread Daniel Malter
df2-melt(df1) df3-cast(df2,Index~Name) df3 HTH, Daniel Dana Sevak wrote: I realize that this is terribly basic, but I just don't seem to see it at this moment, so I would very much appreciate your help. How shall I transform this dataframe: df1   Name Index Value 1    a 1  

Re: [R] Poor performance of Optim

2011-10-01 Thread Daniel Malter
With respect, your statement that R's optim does not give you a reliable estimator is bogus. As pointed out before, this would depend on when optim believes it's good enough and stops optimizing. In particular if you stretch out x, then it is plausible that the likelihood function will become flat

Re: [R] GAMs in R : How to put the new data into the model?

2011-09-27 Thread Daniel Malter
Your questions is pretty opaque. Please adhere to the posting guide. Provide a self-contained (!) example (i.e., code) that reproduces your problem. Generally, you would predict like this: x-rnorm(100) e-rnorm(100) y-x+x^2+e reg-gam(y~s(x)) plot(reg) predict(reg,newdata=data.frame(x=2)) where

Re: [R] Data transformation cleaning

2011-09-27 Thread Daniel Malter
On a methodological level, if the choices do not correspond on a cardinal or at least ordinal scale, you don't want to use correlations. Instead you should probably use Cramer's V, in particular if the choices are multinomial. Whether the wide format is necessary will depend on the format the

Re: [R] survival analysis: interval censored data

2011-09-26 Thread Daniel Malter
Please adhere to the posting guide (i.e., provide a sample of self contained code and provide the error message). And what does but it is not working mean? Is there an error code? rueu wrote: hello: my data looks like: time1  time2   event  catagoria 2004    2006        1            C

Re: [R] Trouble creating and adjacency matrix

2011-09-25 Thread Daniel Malter
x-rnorm(25,1.5,1) dim(x)=c(5,5) x y-ifelse(c(x)1.5,1,0) dim(y)-dim(x) HTH, Daniel Spartina wrote: Hello all, I'm having trouble creating an adjacency matrix. Basically, I need to turn the following distance matrix into an adjacency matrix based on whether values are 1.5 or not. If

Re: [R] Data import

2011-09-25 Thread Daniel Malter
Why would that be preferable to dropping the variables after importing the whole dataset? Daniel sassorauk wrote: Is it possible to import only certain variables from a SPSS file. I know that read.spss in the foreign library will bring the data into R but can I choose to important only

Re: [R] Tobit Fixed Effects

2011-09-15 Thread Daniel Malter
Not satisfactory in which sense? The survreg(Surv(Value,Censoring)~indvars+strata(id)) should/may work. For a discussion of Tobit fixed effects, see also Greene's website: http://pages.stern.nyu.edu/~wgreene/publications.htm under Fixed Efects and Bias Due to the Incidental Parameters Problem in

Re: [R] function to include factors in summary data frame

2011-09-12 Thread Daniel Malter
I have read it three times and still no concrete idea what you are actually trying to do, mainly because there is no information as to which level/variable you are aggregating on. It'd help if you provided the aggregated data (or sample rows thereof) so that we know what you want the result to be.

Re: [R] creating a new column with values from another

2011-09-12 Thread Daniel Malter
You can do this using ifelse(). See example below. x-rpois(100,100) NA.x-sample(1:100,40) x[NA.x]=NA y-rpois(100,100) NA.y-sample(1:100,40) y[NA.y]=NA z-ifelse(!is.na(y),y,ifelse(!is.na(x),x,NA)) HTH, Daniel holly shakya wrote: I have 2 columns for weight. There are NAs in each column

Re: [R] Multiple regression intercept

2011-09-12 Thread Daniel Malter
This suggests that this is a dangerous office to be in because this is a basic question. I am sure somebody in your office knows this. Anyway, the baseline gives you the average value of the group that constitutes the baseline when all other covariates are zero. Let's say you measure whether men

Re: [R] Multi-output regression

2011-09-11 Thread Daniel Malter
I am not a Bayesian. In the non-Bayesian case you would use SUR to model both equations simultaneously. If both use the exact same matrix of data, X (i.e., the value are numerically absolutely identical), then SUR will collapse to OLS. In that sense you get a combined estimate using SUR that

Re: [R] simple t test for multiple colimns

2011-09-10 Thread Daniel Malter
It will never hurt your chances to get an answer if you tell what the code in the different language actually does. Is it doing t-est for all of the variables and the group indicators are in a separate column? If, imagine you have the following data: id-rep(c(1,2),each=100)

Re: [R] Passing in Condtions into Object

2011-09-08 Thread Daniel Malter
Would: tapply(mpg,list(year,manufacturer), function(x) length(unique(x))) do what you are trying to accomplish? Or do you need very specific subsets? If so, you can do: year-c(rep(1980,4),rep(1981,4)) manufacturer-rep(c('A','B'),4) mpg-sample(c(1:2),8,replace=T)

Re: [R] reporting ANOVA for nested models

2011-09-07 Thread Daniel Malter
fit1, the unrestricted model, includes 1 more regressor than fit2, the restricted model. Testing the models against each other means that fit2 is equal to fit1, assuming that the coefficient on the additional regressor that is included in fit1 is restricted to zero. Your F-test is thus whether

Re: [R] glm

2011-09-06 Thread Daniel Malter
y is the dependent variable, not a predictor or independent variable. since this is a binomial model, y should be 0/1 or, atypically, a proportion. HTH, Daniel Samuel Okoye wrote: Dear all, I am using glm with quasibinomial. What does the following error message mean: Error in

Re: [R] Dealing with NA's in a data matrix

2011-09-06 Thread Daniel Malter
Please provide the data as self-contained code, as requested in the posting guide, so that helpers can directly paste it into R. Alternatively, you can provide the dilomaaethiops.txt. Best, Daniel Watching19 wrote: hello... I am trying to get this code to work, but as I get to the predict

Re: [R] bootstrap function

2011-09-06 Thread Daniel Malter
install.packages(bootstrap) library(bootstrap) ? -- View this message in context: http://r.789695.n4.nabble.com/bootstrap-function-tp3794224p3795264.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list

Re: [R] plm package, R squared, dummies in panel data

2011-09-05 Thread Daniel Malter
Hi, I answered this question before in this post: http://r.789695.n4.nabble.com/Regressions-with-fixed-effect-in-R-td2173314.html , specifically in my message from May 11, 2010; 4:30pm. However, I believe the newer version of plm shows an R-squared, which should be the within R-squared. Why the

Re: [R] Classifying large text corpora using R

2011-09-03 Thread Daniel Malter
Take a look here: http://www.jstatsoft.org/v25/i05/paper HTH, Da. andy1234 wrote: Dear everyone, I am new to R, and I am looking at doing text classification on a huge collection of documents (500,000) which are distributed among 300 classes (so basically, this is my training data).

Re: [R] execute R commands from Matlab

2011-08-30 Thread Daniel Malter
They seem to have a workaround. I don't know whether anything better is available by now. http://www.mathworks.com/matlabcentral/newsreader/view_thread/163726 HTH, Daniel sarak wrote: Is it possible for anyone to upload a youtube video showing how to execute R commands in Matlab , it's so

Re: [R] execute R commands from Matlab

2011-08-30 Thread Daniel Malter
This seems to work, as well: http://www.mathworks.com/matlabcentral/fx_files/5051/1/content/Rdemo.html -- View this message in context: http://r.789695.n4.nabble.com/execute-R-commands-from-Matlab-tp3778263p3778282.html Sent from the R help mailing list archive at Nabble.com.

Re: [R] ARMA show different result between eview and R

2011-08-30 Thread Daniel Malter
In your first line, you write ARMA(2,2). However, what you fit in R is ARIMA(2,1,2). What you fit in eview, I can't tell. Could that explain the difference? HTH, Daniel Young Gyu Park wrote: When I do ARMA(2,2) using one lag of LCPIH data This is eview result *Dependent Variable:

Re: [R] weird apply() behavior

2011-08-30 Thread Daniel Malter
#Do apply(y,1,print) #Note the space that is inserted before the 1. If you insert this space in your function apply(y,1,function(x){x-unlist(x); if (!is.na(x[2]) x[2]=='2k' !is.na(x[1]) x[1]==' 1') 1 else 0} ) #you get the result you expect. #Also, note that your !is.na conditions are

Re: [R] Function won't permanently assign values to a vector

2011-08-28 Thread Daniel Malter
It will greatly help if you provide a self-contained example, as requested in the posting guide. Most of the times this will in fact lead to you figuring out your problem yourself, but if not it will greatly enhance your chances that we can help you in a meaningful, unambiguous way. Best, Daniel

Re: [R] all combinations of the elements of two vectors

2011-08-27 Thread Daniel Malter
x-letters[1:3] y-1:3 d-expand.grid(x,y) g-apply(d,1,function(x) paste(x[1],x[2],sep=)) HTH, Daniel Campbell, Desmond-2 wrote: Dear R-help readers, I'm sure this problem has been answered but I can't find the solution. I have two vectors v1 - c(a,b) v2 - c(1,2,3) I want an easy way

Re: [R] within-groups variance and between-groups variance

2011-08-25 Thread Daniel Malter
#Here is I think an easier way of coding all the components you need. #The within-group variances, you get with this function: apply(iris[,1:4],2,function(x) tapply(x,iris$Species,var)) #You can get what you computed by taking the column means. apply(apply(iris[,1:4],2,function(x)

Re: [R] Efficient way to Calculate the squared distances for a set of vectors to a fixed vector

2011-08-24 Thread Daniel Malter
Let's say your fixed vector is x, and y is the list of vectors that you want to create the squared distance to x with, then: x-c(1:5) y-list() y[[1]]-sample(c(1:5),5) y[[2]]-sample(c(1:5),5) y[[3]]-sample(c(1:5),5) y distances-lapply(y,function(a,b) crossprod(a-b), b=x) #lapply goes over the

[R] Efficiency of random and fixed effects estimator

2011-08-22 Thread Daniel Malter
Hi all, I am statistically confused tonight. When the assumptions to a random effects estimator are warranted, random effects should be the more efficient estimator than the fixed effects estimator because it uses fewer degrees of freedom (estimating just the variance parameter of the normal

Re: [R] Efficiency of random and fixed effects estimator

2011-08-22 Thread Daniel Malter
) Daniel Malter wrote: Hi all, I am statistically confused tonight. When the assumptions to a random effects estimator are warranted, random effects should be the more efficient estimator than the fixed effects estimator because it uses fewer degrees of freedom (estimating just the variance

Re: [R] COXPH TIME-DEPENDENT

2011-08-19 Thread Daniel Malter
B is the specification for time-varying covariates. Otherwise, your model will think that each row is one independent observation that either had an event or was censored at time or total_time. HTH, Daniel javier palacios wrote: Dear R-community, which of the following two formats is

Re: [R] how to analysis a dataset with some missing value?

2011-08-18 Thread Daniel Malter
if your vector of data is x, use x[x!=-]. Subseting entire data frames works analogously. HTH, Daniel -- View this message in context: http://r.789695.n4.nabble.com/how-to-analysis-a-dataset-with-some-missing-value-tp3751940p3752003.html Sent from the R help mailing list archive at

Re: [R] How to get the descriptive statistic of the whole dataframe?

2011-08-18 Thread Daniel Malter
look into the *apply series of functions. In your case apply(name.of.your.data.frame,2,min) or apply(name.of.your.data.frame,2,max) will do. You can also put any summary function to your liking instead of min/max. Best, Daniel Lao Meng wrote: Hi all: If I have a dataframe of N

Re: [R] a question about lm on t-test.

2011-08-18 Thread Daniel Malter
Pick up a book or the like on ordinary least squares regression, which is what lm() in its plain vanilla application does. The t-value is the estimated coefficient divided by the standard error. The standard errors of the coefficients are the diagonal entries of the variance-covariance matrix.

Re: [R] How to use PC1 of PCA and dim1 of MCA as a predictor in logistic regression model for data reduction

2011-08-18 Thread Daniel Malter
Pooling nominal with numeric variables and running pca on them sounds like conceptual nonsense to me. You use PCA to reduce the dimensionality of the data if the data are numeric. For categorical data analysis, you should use latent class analysis or something along those lines. The fact that

Re: [R] a question about lm on t-test.

2011-08-18 Thread Daniel Malter
I should have written the standard errors of the coefficients are the SQUARE ROOT of the diagonal entries of the variance-covariance matrix, as I programmed it in the code. Daniel Malter wrote: Pick up a book or the like on ordinary least squares regression, which is what lm() in its plain

Re: [R] Using mixed models to analyze Longitudinal intervention

2011-08-18 Thread Daniel Malter
It looks like it. However, you provide very little information. Do you have measurements before and after the intervention and did the intervention occur at the same point in time for all treated? If so, you could do a simple difference in differences estimation. HTH, Daniel Troy S wrote:

Re: [R] Best way/practice to create a new data frame from two given ones with last column computed from the two data frames?

2011-08-18 Thread Daniel Malter
The problem with your first solution is that it relies on that the each 'year x group' combination is present in both data frames. To avoid this, I would recommend to use merge() df3-merge(df1,df2,by.x=c(Year,Group),by.y=c(Year,Group)) df3$ratio-with(df3,Value.x/Value.y) df3 HTH, Daniel

Re: [R] Speeding nested loops up

2011-08-17 Thread Daniel Malter
General suggestions: avoid cbind() and avoid accessing data frames. Convert data frames to matrices before accessing them. Also, why do you print? You don't really want to print(t) for every iteration of the loop, do you? Also avoid defining elements within the loop that need to be defined only

Re: [R] Plotting and quantiles

2011-08-12 Thread Daniel Malter
Q1 is very opaque because you are not even saying what kind of plot you want. For a regular scatterplot, you have multiple options. a.) select only the data in the given intervals and plot the data b.) plot the entire data, but restrict the graph region to the intervals you are interested in, or

Re: [R] sapply( ) a loop function

2011-08-11 Thread Daniel Malter
I am not sure what purpose the while loop has. However, the main problem seems to be that you need to put: i-sample(1:(n-40),1) #This sample from 1 to n-40 rather than i-sample(1:n-40,1) #this samples one 1:n and then subtracts 40 Otherwise, you may get negative index values Best, Daniel

Re: [R] Mixed effect models

2011-08-11 Thread Daniel Malter
I am afraid this is one of these posts where I have to quote David Winsemius: The advancement of science would be safer if you knew what you were doing. Moreover, these are questions best addressed to your local statistician rather than the R-help list. With exceptions, the R-help list helps to

Re: [R] Different approach to set up Cohen Kappa

2011-08-10 Thread Daniel Malter
The kappa2() function in the irr library takes an n x 2 matrix as input, where the two columns are the ratings by two raters. Let x and y below be the ratings of the two raters: x-sample(c(0,1,2),100,replace=T) x o-sample(c(0,0,0,1),100,replace=T) y-x+o y #Then kappa is computed as:

Re: [R] Extend my code to run several data at once.

2011-07-28 Thread Daniel Malter
. It is calculating the estimates for one row. How do I incorporate the other data that has all other columns? Thanks Ed Sent from BlackBerry® wireless device -Original Message- From: Daniel Malter [via R] lt;ml-node+3689534-1114015792-247...@n4.nabble.comgt; Date: Sat, 23 Jul 2011 14

Re: [R] Big data and column correspondence problem

2011-07-27 Thread Daniel Malter
If A has more columns than in your example, you could always try to only merge those columns of A with B that are relevant for the merging. You could then cbind the result of the merging back together with the rest of A as long as the merged data preserved the same order as in A. Alternatively,

Re: [R] Big data and column correspondence problem

2011-07-26 Thread Daniel Malter
For question (a), do: which(AA%in%BB) Question (b) is very ambiguous to me. It makes little sense for your example because all values of BB are in AA. Therefore I am wondering whether you meant in question (a) that you want to find all values in BB that are in AA. That's not the same thing. I am

Re: [R] Selecting unique values

2011-07-26 Thread Daniel Malter
Steven's solution is great, but it will only work if the rows are really duplicates. If the data frame contains another variable whose values vary, it will not work because then the rows are obviously unique. df-data.frame(df,value=rnorm(11)) unique(df) You would then have to make a decision,

Re: [R] Beta distribution- help needed

2011-07-26 Thread Daniel Malter
This is a theoretical issue. It is impossible for beta-distributed values to take the value of 0 or 1. Hence, an attempt to fit a beta distribution to a vector containing these values fails. HTH, Daniel baxy77 wrote: Hi, Well, i need some help, practical and theoretical. I am wondering

Re: [R] Beta distribution- help needed

2011-07-26 Thread Daniel Malter
This is not very confusing. It is the exact same error in the sense that this time the values of x1 are not only outside the interval (0-1) but within [0-1] as in your first example, but this time they are also outside [0-1]. The reason is that you did not divide x1 by sum(x1) this time. In other

Re: [R] Big data and column correspondence problem

2011-07-26 Thread Daniel Malter
This is much clearer. So here is what I think you want to do. In theory and practice: Theory: Check if AA[i] is in BB If AA[i] is in BB, then take the row where BB[j] == AA[i] and check whether A1 and A2 are in B1 to B3. Is that right? Only if both are, you want the indicator to take 1. Here

Re: [R] Finding/identifying a value within a factor

2011-07-25 Thread Daniel Malter
b-c(1,2,3,4,1) grep('',b) HTH, Daniel Ryan Utz-2 wrote: Hi all, I'm trying to identify a particular digit or value within a vector of factors. Specifically, this is environmental data where in some cases the minimum value reported is a particular number (and I want to manipulate

Re: [R] Trouble with line of best fit

2011-07-25 Thread Daniel Malter
Hi, I hope this is for private purposes. Otherwise, I may cite David Winsemius: The advancement of science would be safer if you knew what you were doing. First, your regression command is inverted. You ought to regress SoloKills on range, not vice versa. abline(lm(graph~range)) #does the trick

Re: [R] split data frame temporary and work with only part of it?

2011-07-24 Thread Daniel Malter
My recommendation would be to not subset out the data, because you are introducing a potential source of error when binding the new data back together with the old data. Preferably, I would work on selecting subsets of the dataset using indices (as suggested in the previous post) and just do the

Re: [R] analizing .txt file with R or an other program

2011-07-23 Thread Daniel Malter
Hi, The blunt answer is: by learning R. In particular, you will need pattern matching techniques as in ?grep and (somewhat advanced, some would call it basic) knowledge of R. So if you aren't familiar with either, I would suggest an introductory manual or one of the many websites you find online

Re: [R] Extend my code to run several data at once.

2011-07-23 Thread Daniel Malter
If you just want to apply the function over successive columns of a data frame use apply(name.of.data.frame, 2 , llik) Daniel EdBo wrote: Hi I have a code that calculate maximisation using optimx and it is working just fine. I want to extend the code to run several colomns of R_j where

Re: [R] help on panel.superpose

2011-07-22 Thread Daniel Malter
For the first part, use the col and pch arguments: id-rep(c(0,2),each=50) e-rnorm(100) x-rnorm(100) y-id+x+e xyplot(y~x,groups=id,col=c(3,4),pch=c(12,13)) For the second part, I do not know what exactly mean by superimpose the mean level? Should the mean for each group be displayed as a

Re: [R] Trouble getting plot to appear

2011-07-22 Thread Daniel Malter
Typically not, unless the device has not closed properly. Does the second plot show up in the pdf? Daniel cherron wrote: Hello, I am currently working on a script and I output plots to pdf using pdf(...) plot(...) dev.off() then later I was trying to plot something and when I run

Re: [R] Calculating the mean of values in tables using formulae

2011-07-22 Thread Daniel Malter
Check the *apply() series of functions. tapply() will do what you want. attach(mtcars) tapply(hp,list(cyl,gear),mean) HTH, Daniel Mark Alen wrote: I know commands like xtabs and table allow a user to do cross-tabulation For example the following command generates a pivot table that

Re: [R] loops and simulation

2011-07-20 Thread Daniel Malter
From: David Winsemius [dwinsem...@comcast.net] Sent: Wednesday, July 20, 2011 9:01 AM To: Daniel Malter Cc: r-help@r-project.org Subject: Re: [R] loops and simulation On Jul 20, 2011, at 1:34 AM, Daniel Malter wrote: snipped requests, except that you were

Re: [R] Centering data frame by factor

2011-07-19 Thread Daniel Malter
P1-tapply(P1,Experiment,mean)[Experiment] HTH, Daniel ronny wrote: Hi, I would like to center P1 and P2 of the following data frame by the factor Experiment, i.e. substruct from each value the average of its experiment, and keep the original data structure, i.e. the experiment and the

Re: [R] How to get predicted values of y for different x values?

2011-07-19 Thread Daniel Malter
Please read the posting guide (requires a self-contained example of code) and consult the help pages before posting. If you type ?predict.lm the help page clearly states that the argument 'newdata' takes [a]n optional data frame in which to look for variables with which to predict...

Re: [R] loops and simulation

2011-07-19 Thread Daniel Malter
I dare the conjecture that if you had written the code, you would know how to do this. This suggests that you are asking us to do your homework, which is not the purpose of this list. A simple inclusion of the code in a for or while loop and storing the estimated parameters with the index of the

Re: [R] Different result of multiple regression in R and SPSS

2011-07-19 Thread Daniel Malter
First, it would have helped if you had posted the actual results for us to see how far they are off (and, more specifically, by which factor). Second, given your epiphany, you will find that that's exactly what David (and others before him) said or suggested. It is not about standardizing a

Re: [R] loops and simulation

2011-07-19 Thread Daniel Malter
Yes, there are in Europe. And there are summer classes in the US, as well. And no, this list is not so much about helping beginners to learn R. For that, there is a myriad of online sources. Rather, this list is for people who have exhausted their ability to (elegantly) solve a problem. Also, it

Re: [R] Tukey HSD with repeated measure ANOVA

2011-07-13 Thread Daniel Malter
Try TukeyHSD(anova). TukeyHSD is implemented in the base package, i.e., ready to use with the base installation of R. Also, the TukeyHSD for the interaction term should have a colon : not a *. The which argument in TukeyHSD() must be identical to the name of the coefficient in the summary table.

Re: [R] Using str() in a function.

2011-07-13 Thread Daniel Malter
As long as you just want to display it, use print() GG- c(1,2,3) print(summary(GG),str(GG)) Output: num [1:3] 1 2 3 Min. 1st Qu. MedianMean 3rd Qu.Max. 1.0 1.5 2.0 2.0 2.5 3.0 HTH, Daniel andrewH wrote: Using str() in a function. I am in the

Re: [R] How to smoothen a geodata set in R

2011-07-12 Thread Daniel Malter
To answer your questions: Yes, yes, and probably no. You will have to pick up any introductory manual of R where questions 1 and 2 will be discussed. For 1: you index x as in x[452,682]. For 2: there are ways to write (and avoid) loops in R (e.g. for or while loops). Often avoidance is

Re: [R] fixed effects Tobit, Honore style?

2011-07-12 Thread Daniel Malter
Not that I know of, but the paper says that they are easy to compute. If you did, you could contribute the code. Best, Daniel David Hugh-Jones-3 wrote: Hi all, Is there any code to run fixed effects Tobit models in the style of Honore (1992) in R? (The original Honore article is here:

  1   2   3   4   5   >