Re: [R] Fast tau-estimator line does ot appear on the plot
Many thanks Duncun, Best, Le samedi 31 mars 2018 à 18:05:53 UTC+2, Duncan Murdoch a écrit : On 31/03/2018 11:57 AM, varin sacha via R-help wrote: > Dear R-experts, > > Here below my reproducible R code. I want to add many straight lines to a > plot using "abline" > The last fit (fast Tau-estimator, color yellow) will not appear on the plot. > What is going wrong ? > Many thanks for your reply. > It's not quite reproducible: you forgot the line to create Dataset. It's probably something like Dataset <- data.frame(Y, Z) > ## > > Y=c(2,4,5,4,3,4,2,3,56,5,4,3,4,5,6,5,4,5,34,21,12,13,12,8,9,7,43,12,19,21) > Z=c(43,2,1,2,34,4,3,4,5,30,4,5,4,3,4,5,56,6,43,21,34,19,12,11,9,34,21,23,2,19) > reg1<-lm(Z ~ Y) > plot(Y,Z) > abline(reg1, col="black") > > install.packages("robustbase") > library (robustbase) > reg=lmrob(Z ~ Y, data = Dataset) > abline(reg, col="green") > > install.packages("MASS") > library(MASS) > Huber=rlm(Z ~ Y, data = Dataset) > abline(Huber,col="red") > > Tukey=rlm(Z ~ Y, data = Dataset,psi=psi.bisquare) > abline(Tukey,col="purple") > > install.packages("quantreg") > library(quantreg) > L1=rq(Z ~ Y, data = Dataset,tau=0.5) > abline(L1,col="blue") > > install.packages("RobPer") > library(RobPer) > FastTau(Z,Y) > fast=FastTau(Z,Y) > abline(fast, col="yellow") abline() doesn't know what to do with the "fast" object. It isn't a vector containing intercept and slope, it's a list containing them. So you'll need something like abline(unlist(fast), col="yellow") Duncan Murdoch > > ## > > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] Names of variables needed in newdata for predict.glm
> On Mar 31, 2018, at 8:48 AM, Bendix Carstensen > wrote: > > all.vars works fine, EXCEPT, it give a bit too much. > I only want the regression variables, but in the following example I also get > "k" the variable holding the chosen knots. Any machinery to find only "real" > regression variables? > cheers, Bendix > > library( splines ) > y <- rnorm(100) > x <- rnorm(100) > k <- -1:1 > ml <- lm( y ~ bs(x,knots=k) ) > mg <- glm( y ~ bs(x,knots=k) ) > all.vars(ml$terms) > all.vars(mg$terms) > all.vars(mg$formula) If you allowed a requirement that "real" regression variables have been passed in a data argument, then this might succeed: > ml <- lm( y ~ bs(x,knots=k), data=dat ) > all.vars(ml$terms) [1] "y" "x" "k" > all.vars(ml$formula) character(0) > all.vars(ml$terms)[ all.vars(ml$terms) %in% names(dat)] [1] "y" "x" -- David. > > > Fra: Marc Girondot > Sendt: 8. marts 2018 06:26 > Til: Bendix Carstensen; r-help@r-project.org > Emne: Re: [R] Names of variables needed in newdata for predict.glm > > Hi, > > Some try: >> names(mi$xlevels) > [1] "f" >> all.vars(mi$formula) > [1] "D" "x" "f" "Y" >> names(mx$xlevels) > [1] "f" >> all.vars(mx$formula) > [1] "D" "x" "f" > > When offset is indicated out of the formula, it does not work... > > Marc > > Le 07/03/2018 à 06:20, Bendix Carstensen a écrit : >> I would like to extract the names, modes [numeric/factor] and levels >> of variables needed in a data frame supplied as newdata= argument to >> predict.glm() >> >> Here is a small example illustrating my troubles; what I want from >> (both of) the glm objects is the vector c("x","f","Y") and an >> indication that f is a factor: >> >> library( splines ) >> dd <- data.frame( D = sample(0:1,200,rep=T), >> x = abs(rnorm(200)), >> f = factor(sample(letters[1:4],200,rep=T)), >> Y = runif(200,0.5,10) ) >> mx <- glm( D ~ ns(x,knots=1:2,Bo=c(0,5)) + f:I(x^2) , offset=log(Y) , >> family=poisson, data=dd) >> mi <- glm( D ~ ns(x,knots=1:2,Bo=c(0,5)) + f:I(x^2) + offset(log(Y)), >> family=poisson, data=dd) >> >> attr(mx$terms,"dataClasses") >> attr(mi$terms,"dataClasses") >> mi$xlevels >> mx$xlevels >> >> ...so far not quite there. >> >> Regards, >> >> Bendix Carstensen >> >> Senior Statistician >> Steno Diabetes Center >> Clinical Epidemiology >> Niels Steensens Vej 2-4 >> DK-2820 Gentofte, Denmark >> b...@bxc.dk >> bendix.carsten...@regionh.dk >> http://BendixCarstensen.com >> >> >> >> >> Denne e-mail indeholder fortrolig information. Hvis du ikke er den rette >> modtager af denne e-mail eller hvis du modtager den ved en fejltagelse, >> beder vi dig venligst informere afsender om fejlen ved at bruge >> svarfunktionen. Samtidig bedes du slette e-mailen med det samme uden at >> videresende eller kopiere den. >> >> __ >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >> 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. >> > > > > > > Denne e-mail indeholder fortrolig information. Hvis du ikke er den rette > modtager af denne e-mail eller hvis du modtager den ved en fejltagelse, beder > vi dig venligst informere afsender om fejlen ved at bruge svarfunktionen. > Samtidig bedes du slette e-mailen med det samme uden at videresende eller > kopiere den. > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. David Winsemius Alameda, CA, USA 'Any technology distinguishable from magic is insufficiently advanced.' -Gehm's Corollary to Clarke's Third Law __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] Fast tau-estimator line does ot appear on the plot
On 31/03/2018 11:57 AM, varin sacha via R-help wrote: Dear R-experts, Here below my reproducible R code. I want to add many straight lines to a plot using "abline" The last fit (fast Tau-estimator, color yellow) will not appear on the plot. What is going wrong ? Many thanks for your reply. It's not quite reproducible: you forgot the line to create Dataset. It's probably something like Dataset <- data.frame(Y, Z) ## Y=c(2,4,5,4,3,4,2,3,56,5,4,3,4,5,6,5,4,5,34,21,12,13,12,8,9,7,43,12,19,21) Z=c(43,2,1,2,34,4,3,4,5,30,4,5,4,3,4,5,56,6,43,21,34,19,12,11,9,34,21,23,2,19) reg1<-lm(Z ~ Y) plot(Y,Z) abline(reg1, col="black") install.packages("robustbase") library (robustbase) reg=lmrob(Z ~ Y, data = Dataset) abline(reg, col="green") install.packages("MASS") library(MASS) Huber=rlm(Z ~ Y, data = Dataset) abline(Huber,col="red") Tukey=rlm(Z ~ Y, data = Dataset,psi=psi.bisquare) abline(Tukey,col="purple") install.packages("quantreg") library(quantreg) L1=rq(Z ~ Y, data = Dataset,tau=0.5) abline(L1,col="blue") install.packages("RobPer") library(RobPer) FastTau(Z,Y) fast=FastTau(Z,Y) abline(fast, col="yellow") abline() doesn't know what to do with the "fast" object. It isn't a vector containing intercept and slope, it's a list containing them. So you'll need something like abline(unlist(fast), col="yellow") Duncan Murdoch ## __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] Names of variables needed in newdata for predict.glm
all.vars works fine, EXCEPT, it give a bit too much. I only want the regression variables, but in the following example I also get "k" the variable holding the chosen knots. Any machinery to find only "real" regression variables? cheers, Bendix library( splines ) y <- rnorm(100) x <- rnorm(100) k <- -1:1 ml <- lm( y ~ bs(x,knots=k) ) mg <- glm( y ~ bs(x,knots=k) ) all.vars(ml$terms) all.vars(mg$terms) all.vars(mg$formula) Fra: Marc Girondot Sendt: 8. marts 2018 06:26 Til: Bendix Carstensen; r-help@r-project.org Emne: Re: [R] Names of variables needed in newdata for predict.glm Hi, Some try: > names(mi$xlevels) [1] "f" > all.vars(mi$formula) [1] "D" "x" "f" "Y" > names(mx$xlevels) [1] "f" > all.vars(mx$formula) [1] "D" "x" "f" When offset is indicated out of the formula, it does not work... Marc Le 07/03/2018 à 06:20, Bendix Carstensen a écrit : > I would like to extract the names, modes [numeric/factor] and levels > of variables needed in a data frame supplied as newdata= argument to > predict.glm() > > Here is a small example illustrating my troubles; what I want from > (both of) the glm objects is the vector c("x","f","Y") and an > indication that f is a factor: > > library( splines ) > dd <- data.frame( D = sample(0:1,200,rep=T), >x = abs(rnorm(200)), >f = factor(sample(letters[1:4],200,rep=T)), >Y = runif(200,0.5,10) ) > mx <- glm( D ~ ns(x,knots=1:2,Bo=c(0,5)) + f:I(x^2) , offset=log(Y) , > family=poisson, data=dd) > mi <- glm( D ~ ns(x,knots=1:2,Bo=c(0,5)) + f:I(x^2) + offset(log(Y)), > family=poisson, data=dd) > > attr(mx$terms,"dataClasses") > attr(mi$terms,"dataClasses") > mi$xlevels > mx$xlevels > > ...so far not quite there. > > Regards, > > Bendix Carstensen > > Senior Statistician > Steno Diabetes Center > Clinical Epidemiology > Niels Steensens Vej 2-4 > DK-2820 Gentofte, Denmark > b...@bxc.dk > bendix.carsten...@regionh.dk > http://BendixCarstensen.com > > > > > Denne e-mail indeholder fortrolig information. Hvis du ikke er den rette > modtager af denne e-mail eller hvis du modtager den ved en fejltagelse, beder > vi dig venligst informere afsender om fejlen ved at bruge svarfunktionen. > Samtidig bedes du slette e-mailen med det samme uden at videresende eller > kopiere den. > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. > Denne e-mail indeholder fortrolig information. Hvis du ikke er den rette modtager af denne e-mail eller hvis du modtager den ved en fejltagelse, beder vi dig venligst informere afsender om fejlen ved at bruge svarfunktionen. Samtidig bedes du slette e-mailen med det samme uden at videresende eller kopiere den. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] Fast tau-estimator line does ot appear on the plot
Dear R-experts, Here below my reproducible R code. I want to add many straight lines to a plot using "abline" The last fit (fast Tau-estimator, color yellow) will not appear on the plot. What is going wrong ? Many thanks for your reply. ## Y=c(2,4,5,4,3,4,2,3,56,5,4,3,4,5,6,5,4,5,34,21,12,13,12,8,9,7,43,12,19,21) Z=c(43,2,1,2,34,4,3,4,5,30,4,5,4,3,4,5,56,6,43,21,34,19,12,11,9,34,21,23,2,19) reg1<-lm(Z ~ Y) plot(Y,Z) abline(reg1, col="black") install.packages("robustbase") library (robustbase) reg=lmrob(Z ~ Y, data = Dataset) abline(reg, col="green") install.packages("MASS") library(MASS) Huber=rlm(Z ~ Y, data = Dataset) abline(Huber,col="red") Tukey=rlm(Z ~ Y, data = Dataset,psi=psi.bisquare) abline(Tukey,col="purple") install.packages("quantreg") library(quantreg) L1=rq(Z ~ Y, data = Dataset,tau=0.5) abline(L1,col="blue") install.packages("RobPer") library(RobPer) FastTau(Z,Y) fast=FastTau(Z,Y) abline(fast, col="yellow") ## __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] R help
A. On Sat, 2018-03-31 at 15:45 +0200, Henri Moolman wrote: > Could you please provide help with something from R that I find rather > puzzling? In the small program below x[1]=1, . . . , x[5]=5. R also > finds that x[1]<=5 is TRUE. Yet when you attempt to execute while, R does > not seem to recognize the condition. Any thoughts on why this happens? > > Regards > > Henri Moolman > > > x=c(1,2,3,4,5) > > x[1] > [1] 1 > > i=1 > > x[1]<=5 > [1] TRUE > > while(x[i]<=5){ > + i=i+1 > + } > Error in while (x[i] <= 5) { : missing value where TRUE/FALSE needed If you run the following you should understand why (the only change is to include "print(i)" in the loop, so you can see what is happening): x=c(1,2,3,4,5) x[1] # [1] 1 i=1 x[1]<=5 # [1] TRUE while(x[i]<=5){ i = i+1 ; print(i) } # [1] 3 # [1] 4 # [1] 5 # [1] 6 # Error in while (x[i] <= 5) { : missing value where TRUE/FALSE needed So everything is fine so long as i <= 5 (i.e. x[i] <= 5), but then the loop sets i = 6. and then: i # [1] 6 x[i] # [1] NA x[i] <= 5 # [1] NA Helpful? Best wishes, Ted. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] R help
Hello, Maybe you want while(x[i] < 5) not <= Hope this helps, Rui Barradas On 3/31/2018 2:45 PM, Henri Moolman wrote: Could you please provide help with something from R that I find rather puzzling? In the small program below x[1]=1, . . . , x[5]=5. R also finds that x[1]<=5 is TRUE. Yet when you attempt to execute while, R does not seem to recognize the condition. Any thoughts on why this happens? Regards Henri Moolman x=c(1,2,3,4,5) x[1] [1] 1 i=1 x[1]<=5 [1] TRUE while(x[i]<=5){ + i=i+1 + } Error in while (x[i] <= 5) { : missing value where TRUE/FALSE needed [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] R help
When i increments to 6 (during the fifth iteration) the subsequent test of x[i]<=5 will produce an error since x has only five elements. > On 31 Mar 2018, at 14:45, Henri Moolman wrote: > > Could you please provide help with something from R that I find rather > puzzling? In the small program below x[1]=1, . . . , x[5]=5. R also > finds that x[1]<=5 is TRUE. Yet when you attempt to execute while, R does > not seem to recognize the condition. Any thoughts on why this happens? > > Regards > > Henri Moolman > >> x=c(1,2,3,4,5) >> x[1] > [1] 1 >> i=1 >> x[1]<=5 > [1] TRUE >> while(x[i]<=5){ > + i=i+1 > + } > Error in while (x[i] <= 5) { : missing value where TRUE/FALSE needed > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] R help
The condition is true all the way until you index outside the vector... Cheers On 31 Mar 2018, 17.29 +0200, Henri Moolman , wrote: > Could you please provide help with something from R that I find rather > puzzling? In the small program below x[1]=1, . . . , x[5]=5. R also > finds that x[1]<=5 is TRUE. Yet when you attempt to execute while, R does > not seem to recognize the condition. Any thoughts on why this happens? > > Regards > > Henri Moolman > > > x=c(1,2,3,4,5) > > x[1] > [1] 1 > > i=1 > > x[1]<=5 > [1] TRUE > > while(x[i]<=5){ > + i=i+1 > + } > Error in while (x[i] <= 5) { : missing value where TRUE/FALSE needed > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] R help
Could you please provide help with something from R that I find rather puzzling? In the small program below x[1]=1, . . . , x[5]=5. R also finds that x[1]<=5 is TRUE. Yet when you attempt to execute while, R does not seem to recognize the condition. Any thoughts on why this happens? Regards Henri Moolman > x=c(1,2,3,4,5) > x[1] [1] 1 > i=1 > x[1]<=5 [1] TRUE > while(x[i]<=5){ + i=i+1 + } Error in while (x[i] <= 5) { : missing value where TRUE/FALSE needed [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] R and Java 10 ➜ rJava not able to build
Don't waste too much time on this. It is due to a change introduced in Java 10 at short notice. I believe the rJava maintainers are working on a fix/workaround. -pd > On 31 Mar 2018, at 10:22 , John wrote: > > On Tue, 27 Mar 2018 22:25:33 +0300 > Luis Puerto wrote: > > I don't run a Mac so this may not help. Did you install java 10 as > user or as root? Using linux, applications installed as user will be > inserted into your user space under /home/. As root the > application will located where any user of the system with permission > to run the application can access it. I ran into a problem similar to > this with packages, some installed as root and some installed locally > in my user directory. > > JWDougherty > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Office: A 4.23 Email: pd@cbs.dk Priv: pda...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] R and Java 10 ➜ rJava not able to build
On Tue, 27 Mar 2018 22:25:33 +0300 Luis Puerto wrote: I don't run a Mac so this may not help. Did you install java 10 as user or as root? Using linux, applications installed as user will be inserted into your user space under /home/. As root the application will located where any user of the system with permission to run the application can access it. I ran into a problem similar to this with packages, some installed as root and some installed locally in my user directory. JWDougherty __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.