search for: liuyi

Displaying 20 results from an estimated 20 matches for "liuyi".

Did you mean: liuli
2010 Jun 24
2
count data with a specific range
I would like to prepare the data for barplot. But I only have the data frame now. x1=rnorm(10,mean=2) x2=rnorm(20,mean=-1) x3=rnorm(15,mean=3) data=data.frame(x1,x2,x3) If there a way to put data within a specific range? The expected result is as follows: range x1 x2 x3 -10-0 2 5 1 (# points in this
2010 Jun 21
2
How to predict the mean and variance of the dependent variable after regression
Hi, folks, As seen in the following codes: x1=rlnorm(10) x2=rlnorm(10,mean=2) y=rlnorm(10,mean=10)### Fake dataset linmod=lm(log(y)~log(x1)+log(x2)) After the regression, I would like to know the mean of y. Since log(y) is normal and y is lognormal, I need to know the mean and variance of log(y) first. I tried mean (y) and mean(linmod), but either one is what I want. Any tips? Thanks in
2012 Aug 29
3
Help on calculating spearman rank correlation for a data frame with conditions
Dear all, Suppose my data frame is as follows: id price distance 1 2 4 1 3 5 ... 2 4 8 2 5 9 ... n 3 7 n 8 9 I would like to calculate the rank-order correlation between price and distance for each id. cor(price,distance,method = "spearman") calculate a correlation for all. Then I tried to use apply(data,list='id',cor(price , distance , method =
2010 Jun 22
2
Verify the linear regression model used in R ( fundamental theory)
Hi, folks, As I understand, Least-squares Estimate (second-moment assumption) and the Method of Maximum Likelihood (full distribtuion assumption) are used for linear regression. I do >?lm, but the help file does not tell me the model employed in R. But in the book 'Introductory Statistics with R', it indicates R estimate the parameters using the method of Least-squares. However it
2010 Jul 21
2
Variance of the prediction in the linear regression model (Theory and programming)
Hi, folks, Here are the codes: ############## y=1:10 x=c(1:9,1) lin=lm(log(y)~x) ### log(y) is following Normal distribution x=5:14 prediction=predict(lin,newdata=x) ##prediction=predict(lin) ############### 1. The codes do not work, and give the error message: Error in eval(predvars, data, env) : numeric 'envir' arg not of length one. But if I use the code after the pound sign, it
2010 Jun 18
1
How to calculate the robust standard error of the dependent variable
Hi, folks linmod=y~x+z summary(linmod) The summary of linmod shows the standard error of the coefficients. How can we get the sd of y and the robust standard errors in R? Thanks! [[alternative HTML version deleted]]
2010 Sep 02
1
How to generate integers from uniform distribution with fixed mean
Hi, folks, runif (n,min,max) is the typical code for generate R.V from uniform dist. But what if we need to fix the mean as 20, and we want the values to be integers only? Thanks [[alternative HTML version deleted]]
2010 Jun 26
1
All a column to a data frame with a specific condition
Hi, folks, Please first look at the codes: plan_a=c('apple','orange','apple','apple','pear','bread') plan_b=c('bread','bread','orange','bread','bread','yogurt') value=1:6 data=data.frame(plan_a,plan_b,value) library(plyr) library(reshape) mm=melt(data, id=c('plan_a','plan_b'))
2010 Jun 23
1
How to 'understand' R functions besides reading R codes
Apologize for not being clearer earlier. I would like to ask again. Thank Joris and Markleeds for response. Two examples: 1. Function 'var'. In R, it is the sum of square divided by (n-1) but not by n. (I know this in R class) 2. Function 'lm'. In R, it is the residual sum of square divied by (n-2) not by n, the same as in the least squares estimate. But the assumption following
2010 Jun 25
2
Delete rows in the data frame by limiting values in two columns
Hi, folks, Finally Friday~~ Here comes the question: x=c('germany','poor italy','usa','england','poor italy','japan') y=c('Spain','germany','usa','brazil','england','chile') s=1:6 z=3:8 test=data.frame(x,y,s,z) #Now I only concern the countries ('germany','england','brazil').
2010 Jul 02
2
how to save summary(lm) and anova (lm) in format?
Hi, folks, I would like to copy the output of summary(lm) and anova (lm) in R to my word file. But the output will be a mess if I just copy after I call summary and anova. ##################### x=rnorm(10) y=rnorm(10,mean=3) lm=lm(y~x) summary(lm) Call: lm(formula = y ~ x) Residuals: Min 1Q Median 3Q Max -1.278567 -0.312017 0.001938 0.297578 1.310113
2010 Jun 29
3
How to delete the replicate rows by summing up the numeric columns
Hi, folks, I am sorry that I did not state the problem correctly yesterday. Please let me address the problem by the following codes: first=c('u','b','e','k','j','c','u','f','c','e')
2010 Jun 19
1
How to read data from this csv?
I am so frustrated about reading data from this sample csv file. My code is : >test=read.csv(file='test.csv',header=T) warning message: In read.table(file = file, header = header, sep = sep, quote = quote, : incomplete final line found by readTableHeader on 'test.csv' >test [1] ??.?.. <0 rows> (or 0-length row.names) What is the problem here? Thanks
2010 Jun 24
1
how to change the format of numeric variable
Hi, The format problem is really annoying. How to get rid of it? x [1] 1e+06 And also when I do barplot, x=rnorm(100,mean=1000) barplot(table(cut(x,breaks=c(0,50,100,150,200,250,300,350,400,450,500,1000,2000,5000,10000)))) The data will show as scientific format, when it is larger than 999 (1e+03, 5e+3). I would like all the data in the digit format (1000, 5000). Does any function works
2010 Jul 27
0
How to generate variance of a new observation based on a linear regression model
Hi, folks, x=1:10 y=rep(2:6,2) lin=lm(y~x) x=3:12 new=predict(lin,se.fit=T) #se.fit: the standard error of the predicted means, namely, the square root of Var( E[y|x] | x) # How can I generate the variances of the new observations? Namely the square root of var(y|x), ## Which I think should be much larger than the values from se.fit=T. The reason why I need to know the estimations of
2010 Aug 11
1
How to calculate the concentration
Hi, folks, ###### food=c('fruit','fruit','fruit','drink','drink','drink') type=c('apple','apple','orange','water','soda','soda') value=c(2,3,1,5,7,6) data=data.frame(food,type,value) share=c((2+3)/(2+3+1),5/6,1/6,5/(5+7+6),13/18,13/18)
2010 Jun 18
1
Read data from .csv file and regression on dummy variables
Hi, I need to regress the population on time slot and also days in advance. A sample dataset is like this. I do not know whether I can attach a file in this mailing list or not. If you know how to do it, I will be happy to send you my data file. time slot days in advance US EUR CHINA JAPAN 2 34 56 78 34 6:am-7am 5
2010 Jun 29
2
How to delete rows based on replicate values in one column with some extra calcuation
Hi, folks, Please let me address the problem by the following codes: first=c('u','b','e','k','j','c','u','f','c','e') second=c('usa','Brazil','England','Korea','Japan','China','usa','France','China','England') third=1:10
2010 Jun 17
2
how to 'average' one col wrt to another one
Hi, folks, test=matrix(rep(letters[1:3],6),nrow=6,byrow=T) test[2,]=letters[5:7] test[4,]=c('e','f','i') test[1,3]='i' colnames(test)=c('leave','arrive','line') The code will generate a sample dataset. I have thousands rows of data. For the same 'leave' and 'arrive', how can I get the sum of square of percentages of
2010 Aug 07
3
plot the dependent variable against one of the predictors with other predictors as constant
Hi, folks, Happy work in weekends >_< My question is how to plot the dependent variable against one of the predictors with other predictors as constant. Not for the original data, but after prediction. It means y is the predicted value of the dependent variables. The constane value of the other predictors may be the average or some fixed value. ####### y=1:10 x=10:1 z=2:11