[R] ifelse command
hello people, I want to make a biased dice using the sample() function and print out the results after n number of runs, I've successfully generated the dice using the following command: mydie2-function(n=1000,y=NULL,...){ for(i in 1:n){ x-sample(1:6,n,replace=TRUE,prob=c(1,1,2,3,2,1)/10) x=runif(n) if(x=1/10){y[i]=1} else if(x=2/10){y[i]=2} else if(x=4/10){y[i]=3} else if(x=7/10){y[i]=4} else if(x=9/10){y[i]=5} else{y[i]=6} } bar-barplot(table(y)) table-table(y) return(list(bar,table)) } mydie2() but I also want to try to create the same dice stimulation using ifelse() statement, but all hell break loose when I attempt to use the command below (the barplot only shows the results to be 6), can anyone tell me what went wrong please: mydie2-function(n=1000,y=NULL,...){ for(i in 1:n){ x-sample(1:6,n,replace=TRUE,prob=c(1,1,2,3,2,1)/10) x=runif(n) ifelse((x=1/10),{y[i]-1}, ifelse((x=2/10),{y[i]-2}, ifelse((x=4/10),{y[i]-3}, ifelse((x=7/10),{y[i]-4}, ifelse((x=9/10),{y[i]-5},{y[i]-6}) } bar-barplot(table(y)) table-table(y) return(list(bar,table)) } mydie2() -- View this message in context: http://r.789695.n4.nabble.com/ifelse-command-tp2329538p2329538.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] ifelse command
well to be honest, it is a assignment for the Bayesian statistic paper I wish to take later in the academic year. But I'm a slow learner, so I'm going to try out some of the assignments posted in the university forum hoping to get some practice in advance. Could you please elaborate more on the set.seed() function, I understood from the ?set.seed the general idea of set.seed (if I didn't misunderstood it). I could stimulate a six side dice by set.seed(1:6) with n number of runs using runif(), does that meant if I use set.seed() I don't need to use the prob=c(1,1,2,3,2,1)/10) to create my bias dice? -- View this message in context: http://r.789695.n4.nabble.com/ifelse-command-tp2329538p2330591.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] ifelse command
Hi Josh, I think I know where does the 50+ warning is coming from, because I used n in runif(n), similarly I get 50+ warnings if I use runif(1000). Yet if I use runif(1) the warnings() doesn't show. -- View this message in context: http://r.789695.n4.nabble.com/ifelse-command-tp2329538p2330597.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] ifelse command
Hi Dennis, I see your point about using a different name for the runif() functions, other then the one I used to stimulate the bias coins. I start to get what you and David meant after thinking it through for a while regarding with comparison the biased dice and the uniform distribution, but the difficulty I'm experiencing now is how? How, as in how should I write it in R to make such comparison. Can you please make more suggestions or elaborate more to guide me on how to make it work? thanks! -- View this message in context: http://r.789695.n4.nabble.com/ifelse-command-tp2329538p2330617.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] what command to use for standization
what command to use to standardize my data to mean = 0, and SD=1. the data I want to standardize/centroid is in column format. So I'm thinking of using: col.mean.stdised=apply(data.df,2,function(z){z-mean(z)}) but, what command should I use to put my SD =1? Thanks! -- View this message in context: http://r.789695.n4.nabble.com/what-command-to-use-for-standization-tp2236074p2236074.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Scree diagram,
hello, I've two questions today. 1) I'm trying to do a scree diagram, I did a Google for a specific command I could used to do so. All I could find is a screeplot. Are they the same command? 2) what command can I used to present a PC scores, eigenvectors of the PC scores, and component correlations? thanks! -- View this message in context: http://r.789695.n4.nabble.com/Scree-diagram-tp2122453p2122453.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] how can I stop getting email from every comment posted in this forum?
hello people, I didn't know where should post this thread, I asked Hugo the nabble administrator and his response was I should be able to unsubscribed from getting an email from every comment or response posted here. Yet I couldn't find the method nor the button to click to do so. I even change the email address to one of my sub-main email account that every threads will sent to there, but every day my mail email (which I originally subscribe the mailing list to) still receive at least over 100 emails from this forum. It starts to get on my nerves now, having to delete over 100 emails every day. what can I do? thanks! -- View this message in context: http://n4.nabble.com/how-can-I-stop-getting-email-from-every-comment-posted-in-this-forum-tp1755835p1755835.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] producing a QQ plot.
Hello everyone I'm a beginner in Stats and R, I'm using R 2.10.1. I need to create a multivariate qq plot, there is 8 variable group with each has 55 number of input. An example of what I did so far, just to get my point out: data=read.csv(file.choose(),header=T) data country village groupav_expen P2ary_ed no_fisher 1 Cook IslandsAitutaki D 5239.12747 0.667 666.99986 2 Cook Islands Mangaia C 4587.36188 0.6021505 207.69228 3 Cook Islands Palmerston B 7784.31874 0.167 24.0 ... 53 Wallis And Futuna All Futuna D 11023.30674 0.2789855 1056.63143 54 Wallis And Futuna Halalo B 8783.54979 0.2794118 153.51715 55 Wallis And Futuna Vailala A 12231.95400 0.2395833 100.0 The problem I'm having starts now. I use the following command trying to work out the mahalanobis before plotting the QQ plot, but the following error is prompt: mah=mahalanobis(data,apply(data,2,mean),var(data)) Error in FUN(x, aperm(array(STATS, dims[perm]), order(perm)), ...) : non-numeric argument to binary operator In addition: Warning messages: 1: In mean.default(newX[, i], ...) : argument is not numeric or logical: returning NA 2: In mean.default(newX[, i], ...) : argument is not numeric or logical: returning NA 3: In mean.default(newX[, i], ...) : argument is not numeric or logical: returning NA 4: In mean.default(newX[, i], ...) : argument is not numeric or logical: returning NA 5: In mean.default(newX[, i], ...) : argument is not numeric or logical: returning NA 6: In mean.default(newX[, i], ...) : argument is not numeric or logical: returning NA 7: In mean.default(newX[, i], ...) : argument is not numeric or logical: returning NA 8: In mean.default(newX[, i], ...) : argument is not numeric or logical: returning NA 9: In mean.default(newX[, i], ...) : argument is not numeric or logical: returning NA 10: In mean.default(newX[, i], ...) : argument is not numeric or logical: returning NA Then I thought to myself, maybe the error I got the wrong input for variable. So I adjust the variable to see is my assumption was correct to the command below, but I still got the same error: mah=mahalanobis(data,apply(data,2,mean),var(no_fisher)) I absolutely got no clue where I got wrong and don't know how to fix it. Anyways I thought to myself, no worries I don't use mahalanobis then I'll still try the QQ plot and see what happen. This is the command and the error I got from it: qqplot(qchisq(ppoints(data),ncol(data),data) Error in qchisq(p, df, lower.tail, log.p) : Non-numeric argument to mathematical function -- View this message in context: http://n4.nabble.com/producing-a-QQ-plot-tp1693228p1693228.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] producing a QQ plot.
Hello, this is the first 10 data of the population. country village group av_expenP2ary_edno_fisher B_Leth B_LutjanWt_Leth Wt_Lutjan Cook IslandsAitutakiD 5239.127472 0.7 666.9998558 3.286283997 1.971519001 520.6454552 126.2441843 Cook IslandsMangaia C 4587.361877 0.602150538 207.69228 0.3302481.8467950 0 Cook IslandsPalmerston B 7784.318736 0.16667 24.0002 1.384456001 0.2337460 57.76351477 Cook IslandsRarotonga A 8793.256543 0.764285714 223.8639163 6.790178998 0.75135851.51418019 30.5970125 French PolynesiaFakaravaB 7937.3952 0.36 255.362 7.485009002 6.282185007 62.28921398 60.39332797 French PolynesiaMaatea D 12135.840.316455696 293.748 1.2707810.526468 1002.39553 648.4578044 French PolynesiaMataiea D 12718.57548 0.341880342 2082.386008 2.117207998 0.3408521830.16527 4239.861263 French PolynesiaRaivavaeB 8741.5104 0.285714286 325.0665956 20.121207 4.458011998 63.49777279 0 French PolynesiaTikehau D 6295.66 0.240384615 114.0832839 5.183129001 7.178272997 900.4192224 935.3617853 -- View this message in context: http://n4.nabble.com/producing-a-QQ-plot-tp1693228p1693245.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] producing a QQ plot.
Aha! I see now! thanks guys! really helpful! -- View this message in context: http://n4.nabble.com/producing-a-QQ-plot-tp1693228p1693259.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Problems faced with Levene Test using R
Hello everyone, I'm trying to build Levene's test. The below command is what I used to do the test, I also included the error it prompts up and some data example that I used when trying to build the test. Can someone please tell me what did I do wrong? thanks in advance! res=lm(as.matrix(xx$B_Leth)~as.factor(xx$Wt_Leth)) resid=abs(res$residuals) lev=lm(resid~as.factor(xx$Wt_Leth)) mvlev=manova(lev) Error in manova(lev) : need multiple response B_Leth Wt_Leth 3.286283997 520.6454552 0.3302480 1.384456001 0 6.790178998 51.51418019 7.485009002 62.28921398 1.2707811002.39553 2.117207998 1830.16527 20.121207 63.49777279 -- View this message in context: http://n4.nabble.com/Problems-faced-with-Levene-Test-using-R-tp1693699p1693699.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.