r

Extract posterior estimate and credible intervals for random effect for lme4 model in R

时光总嘲笑我的痴心妄想 提交于 2021-02-10 12:41:07
问题 I need to extract the posterior estimates and intervals for a random effect from my model. For illustrative purposes, a similar dataset to the one I am using would be the ChickWeight dataset in base R. The way I extract the posterior estimates and intervals for my fixed effects is like so: #load package library(lme4) #model m.surv<-lmer(weight ~ Time + Diet + (1|Chick), data=ChickWeight) #load packages library(MCMCglmm) library(arm) #set up for fixed effects sm.surv<-sim(m.surv) smfixef.surv

Filter one column by matching to another column

天大地大妈咪最大 提交于 2021-02-10 12:40:50
问题 I have a data frame with a variable containing elements to drop if they match to an element in another variable - see a small example below: df <- data.frame(pair = c(1, 1, 2, 2, 3, 3), animal = rep(c("dog", "cat"), 3), value = seq(1, 12, 2), drop = c("no", "no", "dog", "dog", "cat", "cat")) pair animal value drop 1 1 dog 1 no 2 1 cat 3 no 3 2 dog 5 dog 4 2 cat 7 dog 5 3 dog 9 cat 6 3 cat 11 cat I'm trying to want to filter the data frame according to whether the value of animal matches the

Extract posterior estimate and credible intervals for random effect for lme4 model in R

瘦欲@ 提交于 2021-02-10 12:40:00
问题 I need to extract the posterior estimates and intervals for a random effect from my model. For illustrative purposes, a similar dataset to the one I am using would be the ChickWeight dataset in base R. The way I extract the posterior estimates and intervals for my fixed effects is like so: #load package library(lme4) #model m.surv<-lmer(weight ~ Time + Diet + (1|Chick), data=ChickWeight) #load packages library(MCMCglmm) library(arm) #set up for fixed effects sm.surv<-sim(m.surv) smfixef.surv

R Plotly: subplot with table

你说的曾经没有我的故事 提交于 2021-02-10 12:39:20
问题 I can't figure out how to make a table subplot work properly using R and Plotly. The following demonstrates what I mean. I have two plots, one scatter and one table. Using the subplot function, the table plot does not behave as expected. I either lose interactivity on the scatter plot, or have overlapping scatter/table plots. Please let me know if I'm missing something or if this is a bug. I'm using plotly version 4.9.0 Thanks in advance! library(plotly) df <- data.frame(x = 1:10, y = 1:10)

How do ggplot stat_* functions work conceptually?

喜欢而已 提交于 2021-02-10 12:36:48
问题 I'm currently trying to get my head around the differences between stat_* and geom_* in ggplot2 . (Please note this is more of an interest/understanding based question than a specific problem I am trying solve). Introduction My current understanding is that is that the stat_* functions apply a transformation to your data and that the result is then passed onto the geom_* to be displayed. Most simple example being the identity transformation which simply passes your data untransformed onto the

Unequal horizontal adjustment to title lines in ggplot

微笑、不失礼 提交于 2021-02-10 12:13:03
问题 I've got a plot with a fairly wide y-axis label, so I want to adjust the title to the left so that it's flush with the label rather than the axis (like this question) but the twist is that I have a multiline title. I've been using hjust, but it adjusts the two lines differently. For example ggplot(mtcars,aes(x=wt,y=mpg))+ geom_point()+ ggtitle("Figure: My long and winding title\nthat goes on and on and on") + ylab("My long label") + theme_bw() + theme(plot.title = element_text(size=16, hjust=

Unequal horizontal adjustment to title lines in ggplot

烂漫一生 提交于 2021-02-10 12:09:04
问题 I've got a plot with a fairly wide y-axis label, so I want to adjust the title to the left so that it's flush with the label rather than the axis (like this question) but the twist is that I have a multiline title. I've been using hjust, but it adjusts the two lines differently. For example ggplot(mtcars,aes(x=wt,y=mpg))+ geom_point()+ ggtitle("Figure: My long and winding title\nthat goes on and on and on") + ylab("My long label") + theme_bw() + theme(plot.title = element_text(size=16, hjust=

Convert NULL from Python to R using rpy2

不问归期 提交于 2021-02-10 12:06:40
问题 In R often the NULL value is used as default. Using Python and RPy2, how can one explicitly provide a NULL argument? None is not convertible ( NotImplementedError ), a string 'NULL' will just be converted to a string and result in an error during execution. Take the following example using the tsintermittent package: import numpy as np from rpy2.robjects.packages import importr from rpy2.robjects import numpy2ri numpy2ri.activate() tsintermittent = importr('tsintermittent') crost =

Osmar package in R “Error in file(con, ”r“) : cannot open the connection”

一曲冷凌霜 提交于 2021-02-10 12:06:39
问题 I am trying to run the osmar package on my windows 10, R 3.4.2, and have correctly installed osmosis. However when I try to run the code: >library("osmar") > >src <- osmsource_osmosis(file = "c:/users/ben_c/Documents/FYP/FYP_NL_Map/muenchen.osm", osmosis = "osmosis") > > >nl_bbox <- center_bbox(11.575278, 48.137222, 3000, 3000) > >nl <- get_osm(nl_bbox, src) > >plot(nl) I get the warning, after osmosis has run: >Error in file(con, "r") : cannot open the connection >In addition: Warning

How to Create Table from text in R?

痴心易碎 提交于 2021-02-10 12:06:38
问题 In R, what would be the best way to separate the following data into a table with 2 columns? March 09, 2018 0.084752 March 10, 2018 0.084622 March 11, 2018 0.084622 March 12, 2018 0.084437 March 13, 2018 0.084785 March 14, 2018 0.084901 I considered using a for loop but was advised against it. I do not know how to parse things very well, so if the best method involves this process please be as clear as possible. The final table should look something like this: https://i.stack.imgur.com/u5hII