Re: [R] Interactions in regression
Hi Rolf, No it is not. I don't know to which question did you want to respond ? I desribed everything in my first email and attached links from SO with pictures included, which are quite understandable. Cheers, Jacek śr., 28 lut 2024 o 19:42 Jacek Kownacki napisał(a): > Hi Rolf, > No it is not. > I don't know to which question did you want to respond ? > I desribed everything in my first email and attached links from SO with > pictures included, which are quite understandable. > > Cheers, > Jacek > > wt., 27 lut 2024 o 02:29 Rolf Turner napisał(a): > >> >> I have no real idea what you are trying to do, but if a table is >> what you want, you can probably get it using the table() function. >> Or, more likely, the xtabs() function. >> >> Using your example from an earlier post (adjusted to make it >> comprehensible to the human mind): >> >> set.seed(1000) >> time <- factor(rep(c("Pre","Post"),each=200)) >> treatment <- factor(rep(rep(c("Control","Treatment"),each=100),2)) >> mu<- rep(rep(1:2,each=100),2) >> response <- rnorm(400,mean=mu) >> xmpldata <- data.frame(time=time,treatment=treatment,response) >> mod <- lm(response~time*treatment,data=xmpldata) >> yhat <- fitted(mod) >> xtb <- with(xmpldata,xtabs(yhat ~ time+treatment)) >> >> print(xtb) >> >> > treatment >> > time Control Treatment >> > Post 94.10501 201.99112 >> > Pre 101.63792 210.04248 >> >> Is that (something like) what you want? >> >> cheers, >> >> Rolf Turner >> >> P.S. You said: "I usually use GUI software". Now *there* lies your >> problem. A GUI is a black box that removes all control over what is >> going on, from your hands. >> >> R. T. >> >> >> >> >> -- >> Honorary Research Fellow >> Department of Statistics >> University of Auckland >> Stats. Dep't. (secretaries) phone: >> +64-9-373-7599 ext. 89622 >> Home phone: +64-9-480-4619 >> > [[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] Interactions in regression
Hi Rolf, No it is not. I don't know to which question did you want to respond ? I desribed everything in my first email and attached links from SO with pictures included, which are quite understandable. Cheers, Jacek wt., 27 lut 2024 o 02:29 Rolf Turner napisał(a): > > I have no real idea what you are trying to do, but if a table is > what you want, you can probably get it using the table() function. > Or, more likely, the xtabs() function. > > Using your example from an earlier post (adjusted to make it > comprehensible to the human mind): > > set.seed(1000) > time <- factor(rep(c("Pre","Post"),each=200)) > treatment <- factor(rep(rep(c("Control","Treatment"),each=100),2)) > mu<- rep(rep(1:2,each=100),2) > response <- rnorm(400,mean=mu) > xmpldata <- data.frame(time=time,treatment=treatment,response) > mod <- lm(response~time*treatment,data=xmpldata) > yhat <- fitted(mod) > xtb <- with(xmpldata,xtabs(yhat ~ time+treatment)) > > print(xtb) > > > treatment > > time Control Treatment > > Post 94.10501 201.99112 > > Pre 101.63792 210.04248 > > Is that (something like) what you want? > > cheers, > > Rolf Turner > > P.S. You said: "I usually use GUI software". Now *there* lies your > problem. A GUI is a black box that removes all control over what is > going on, from your hands. > > R. T. > > > > > -- > Honorary Research Fellow > Department of Statistics > University of Auckland > Stats. Dep't. (secretaries) phone: > +64-9-373-7599 ext. 89622 > Home phone: +64-9-480-4619 > [[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] Interactions in regression
I have no real idea what you are trying to do, but if a table is what you want, you can probably get it using the table() function. Or, more likely, the xtabs() function. Using your example from an earlier post (adjusted to make it comprehensible to the human mind): set.seed(1000) time <- factor(rep(c("Pre","Post"),each=200)) treatment <- factor(rep(rep(c("Control","Treatment"),each=100),2)) mu<- rep(rep(1:2,each=100),2) response <- rnorm(400,mean=mu) xmpldata <- data.frame(time=time,treatment=treatment,response) mod <- lm(response~time*treatment,data=xmpldata) yhat <- fitted(mod) xtb <- with(xmpldata,xtabs(yhat ~ time+treatment)) print(xtb) > treatment > time Control Treatment > Post 94.10501 201.99112 > Pre 101.63792 210.04248 Is that (something like) what you want? cheers, Rolf Turner P.S. You said: "I usually use GUI software". Now *there* lies your problem. A GUI is a black box that removes all control over what is going on, from your hands. R. T. -- Honorary Research Fellow Department of Statistics University of Auckland Stats. Dep't. (secretaries) phone: +64-9-373-7599 ext. 89622 Home phone: +64-9-480-4619 __ 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] Interactions in regression
Hi, I do not want to make a plot, I try to make an output table in R, (in GUI like Stata this is trivially easy task) with regard to SO OP question. As I mentioned, in paper I would not do this, but out of curiosity I use R this time trying to create it. If in R this is trivial task as well, could you please show how to do it ? After googling a lot I did not find solution. regards, Jacek niedz., 25 lut 2024 o 17:00 Bert Gunter napisał(a): > It is trivial in R to add whatever decorations to a plot that you would > like, but that requires that you go beyond point and click production of > graphics and write actual code. If you are unwilling or unable to do this, > you are stuck with whatever various packaged graphics functionality > provides.So you might want to search on "interaction plots for linear > models in R" or similar at rseek.org or in your favorite web search > engine if you haven't already done so. My minimal efforts brought up lots > of hits, though none may be useful for your concerns, especially, as has > already been pointed out, as your query doesn't seem to make much sense > statistically. > > Cheers, > Bert > > > On Sun, Feb 25, 2024 at 7:46 AM Jacek Kownacki > wrote: > >> Hi All, >> I stumbled upon some topics regarding interactions in anova and regression >> and packages for tabulating and visualizations the results of them. >> Here we are: >> >> https://stackoverflow.com/questions/77933272/how-to-add-a-reference-level-for-interaction-in-gtsummary-and-sjplot/77935742#77935742 >> , >> >> https://stackoverflow.com/questions/78016795/how-to-add-reference-levels-for-interaction-in-r?noredirect=1&lq=1 >> . >> I was wondering because I usually use GUI software and these questions did >> not get answers, if from a technical point of view >> how to do it, using these (sjPlot, gtsummary) or other ways to make such >> tables, inserting the reference levels of these mentioned interactions. >> This is not likely to be used in publications (including three base >> levels), but from the point of view of solving the topics this questions >> have interested me. >> I tried myself to make it happen, but so far without success. >> I recall this reprex based on SO: >> >> set.seed(1000) >> my_data <- rbind( >> data.frame(time = "Pre", treatment = "Control", response = >> rnorm(100, mean=1)), >> data.frame(time = "Pre", treatment = "Treatment", response = >> rnorm(100, mean=2)), >> data.frame(time = "Post", treatment = "Control", response = >> rnorm(100, mean=1)), >> data.frame(time = "Post", treatment = "Treatment", response = >> rnorm(100, mean=2)) >> ) %>% mutate(time = factor(time, levels = c("Pre", "Post"))) >> %>%mutate(treatment = factor(treatment, levels = c("Control", >> "Treatment"))) >> model3 <- lm(response ~ time * treatment, data = my_data) >> >> Thanks, >> Jacek >> >> [[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.
Re: [R] Interactions in regression
It is trivial in R to add whatever decorations to a plot that you would like, but that requires that you go beyond point and click production of graphics and write actual code. If you are unwilling or unable to do this, you are stuck with whatever various packaged graphics functionality provides.So you might want to search on "interaction plots for linear models in R" or similar at rseek.org or in your favorite web search engine if you haven't already done so. My minimal efforts brought up lots of hits, though none may be useful for your concerns, especially, as has already been pointed out, as your query doesn't seem to make much sense statistically. Cheers, Bert On Sun, Feb 25, 2024 at 7:46 AM Jacek Kownacki wrote: > Hi All, > I stumbled upon some topics regarding interactions in anova and regression > and packages for tabulating and visualizations the results of them. > Here we are: > > https://stackoverflow.com/questions/77933272/how-to-add-a-reference-level-for-interaction-in-gtsummary-and-sjplot/77935742#77935742 > , > > https://stackoverflow.com/questions/78016795/how-to-add-reference-levels-for-interaction-in-r?noredirect=1&lq=1 > . > I was wondering because I usually use GUI software and these questions did > not get answers, if from a technical point of view > how to do it, using these (sjPlot, gtsummary) or other ways to make such > tables, inserting the reference levels of these mentioned interactions. > This is not likely to be used in publications (including three base > levels), but from the point of view of solving the topics this questions > have interested me. > I tried myself to make it happen, but so far without success. > I recall this reprex based on SO: > > set.seed(1000) > my_data <- rbind( > data.frame(time = "Pre", treatment = "Control", response = > rnorm(100, mean=1)), > data.frame(time = "Pre", treatment = "Treatment", response = > rnorm(100, mean=2)), > data.frame(time = "Post", treatment = "Control", response = > rnorm(100, mean=1)), > data.frame(time = "Post", treatment = "Treatment", response = > rnorm(100, mean=2)) > ) %>% mutate(time = factor(time, levels = c("Pre", "Post"))) > %>%mutate(treatment = factor(treatment, levels = c("Control", > "Treatment"))) > model3 <- lm(response ~ time * treatment, data = my_data) > > Thanks, > Jacek > > [[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] Interactions in regression
Hi All, I stumbled upon some topics regarding interactions in anova and regression and packages for tabulating and visualizations the results of them. Here we are: https://stackoverflow.com/questions/77933272/how-to-add-a-reference-level-for-interaction-in-gtsummary-and-sjplot/77935742#77935742 , https://stackoverflow.com/questions/78016795/how-to-add-reference-levels-for-interaction-in-r?noredirect=1&lq=1 . I was wondering because I usually use GUI software and these questions did not get answers, if from a technical point of view how to do it, using these (sjPlot, gtsummary) or other ways to make such tables, inserting the reference levels of these mentioned interactions. This is not likely to be used in publications (including three base levels), but from the point of view of solving the topics this questions have interested me. I tried myself to make it happen, but so far without success. I recall this reprex based on SO: set.seed(1000) my_data <- rbind( data.frame(time = "Pre", treatment = "Control", response = rnorm(100, mean=1)), data.frame(time = "Pre", treatment = "Treatment", response = rnorm(100, mean=2)), data.frame(time = "Post", treatment = "Control", response = rnorm(100, mean=1)), data.frame(time = "Post", treatment = "Treatment", response = rnorm(100, mean=2)) ) %>% mutate(time = factor(time, levels = c("Pre", "Post"))) %>%mutate(treatment = factor(treatment, levels = c("Control", "Treatment"))) model3 <- lm(response ~ time * treatment, data = my_data) Thanks, Jacek [[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.