小编Sar*_*rah的帖子

如何在不计算标准误差的情况下打印R中的lm方差?

简单的问题真的!我正在运行大量的线性回归,y~x并希望获得每个回归的方差,而无需从summary.lm命令中给出的标准错误输出中手动计算.只是为了节省一点时间:-).执行此命令的任何想法?或者我是否必须自己编写一个函数来完成它?

m<-lm(Alopecurus.geniculatus~Year)
> summary(m)

Call:
lm(formula = Alopecurus.geniculatus ~ Year)

Residuals:
    Min      1Q  Median      3Q     Max 
-19.374  -8.667  -2.094   9.601  21.832 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)  
(Intercept) 700.3921   302.2936   2.317   0.0275 *
Year         -0.2757     0.1530  -1.802   0.0817 .
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 

Residual standard error: 11.45 on 30 degrees of freedom
  (15 observations deleted due to missingness)
Multiple R-squared: 0.09762,    Adjusted R-squared: 0.06754 …
Run Code Online (Sandbox Code Playgroud)

regression r variance

16
推荐指数
3
解决办法
3万
查看次数

ggplot2版本0.9.3.1不会加载到R 3.0.2

我不小心删除了我的旧版ggplot2,所以我下载了新版本,当我使用时

library(ggplot2)
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]) : 
  there is no package called ‘colorspace’
 Error: package or namespace load failed for ‘ggplot2’
Run Code Online (Sandbox Code Playgroud)

有谁知道如何解决这一问题?我尝试在R 3.0.2和R 3.0.1中重新安装旧版本的ggplot2(之前它曾经工作过!)并且它说该软件包不可用.

如果有人有解决方法如何解决新版本的加载或如何让旧版本再次工作,我将感激不尽 - 我真的需要用ggplot绘制一些东西!

干杯

r ggplot2

10
推荐指数
1
解决办法
1万
查看次数

可视化R中两个连续变量和一个分类变量之间的三向交互

我在R中有一个模型,它包括两个连续独立变量IVContinuousA,IVContinuousB,IVCategorical和一个分类变量(两个级别:控制和治疗)之间的显着三向相互作用.因变量是连续的(DV).

model <- lm(DV ~ IVContinuousA * IVContinuousB * IVCategorical)
Run Code Online (Sandbox Code Playgroud)

你可以在这里找到数据

我试图在R中找到一种可视化的方法来简化我对它的解释(也许在ggplot2?).

有点受到这篇博文的启发,我认为我可以将其IVContinuousB分为高值和低值(所以它本身就是一个两级因素:

IVContinuousBHigh <- mean(IVContinuousB) + sd (IVContinuousB) 
IVContinuousBLow <- mean(IVContinuousB) - sd (IVContinuousB)
Run Code Online (Sandbox Code Playgroud)

然后我计划绘制DV和IV ContinuousA之间的关系以及表示这种关系的斜率的拟合线,用于IVCategorical和我的新二分IVContinuousB的不同组合:

IVCategoricalControlIVContinuousBHigh
IVCategoricalControlIVContinuousBLow
IVCategoricalTreatmentIVContinuousBHigh
IVCategoricalTreatmentIVContinuousBLow

我的第一个问题是,这听起来像是一个可行的解决方案,可以产生这种三向互动的可解释图吗?我想尽可能避免3D情节,因为我发现它们不直观......或者还有另一种方法可以解决这个问题吗?也许上面不同组合的方面图?

如果它是一个好的解决方案,我的第二个问题是如何生成数据来预测拟合线来表示上面的不同组合?

第三个问题 - 有没有人对如何在ggplot2中编写代码有任何建议?

我在Cross Validated上发布了一个非常相似的问题,但因为它与代码有关,我想我会在这里尝试(如果这个与社区更相关,我将删除CV帖子:))

非常感谢,提前,

莎拉

请注意,NADV列中有s(左侧为空白)且设计不平衡 - 变量IVCategorical的Control vs Treatment组中的数据点数量略有不同.

仅供参考我有关于在IVContinuousA和IVCategorical之间进行双向互动的代码:

<-ggplot(data = data,aes(x = AOTAverage,y = SciconC,group = MisinfoCondition,shape = MisinfoCondition,col = MisinfoCondition,))+ geom_point(size = 2)+ …

interaction r predict ggplot2

5
推荐指数
2
解决办法
3252
查看次数

更改ggplot上的ablines颜色

使用这些数据我拟合一个情节:

p <- ggplot(dat, aes(x=log(Explan), y=Response)) + 
      geom_point(aes(group=Area, colour=Area))+
      geom_abline(slope=-0.062712, intercept=0.165886)+
      geom_abline(slope= -0.052300, intercept=-0.038691)+
      scale_x_continuous("log(Mass) (g)")+
      theme(axis.title.y=element_text(size=rel(1.2),vjust=0.2),
            axis.title.x=element_text(size=rel(1.2),vjust=0.2),
            axis.text.x=element_text(size=rel(1.3)),
            axis.text.y=element_text(size=rel(1.3)),
            text = element_text(size=13)) +
      scale_colour_brewer(palette="Set1")
Run Code Online (Sandbox Code Playgroud)

这两个斜线表示每个区域趋势的系统发生调整的关系.我想知道,是否有可能在相应的调色板中获得与其适当的区域数据相同的缩写?第一个指定用于区域A,第二个用于区域B.

我用了:

g <- ggplot_build(p) 
Run Code Online (Sandbox Code Playgroud)

找出第一种颜色是#E41A1C,第二种颜色是#377EB8,但是当我尝试在+ geom_abline命令中使用aes来指定这些颜色时

p <- ggplot(dat, aes(x=log(Explan), y=Response)) + 
      geom_point(aes(group=Area, colour=Area))+
      geom_abline(slope=-0.062712, intercept=0.165886,aes(colour='#E41A1C'))+
      geom_abline(slope= -0.052300, intercept=-0.038691,aes(colour=#377EB8))+
      scale_x_continuous("log(Mass) (g)")+
      theme(axis.title.y=element_text(size=rel(1.2),vjust=0.2),
            axis.title.x=element_text(size=rel(1.2),vjust=0.2),
            axis.text.x=element_text(size=rel(1.3)),
            axis.text.y=element_text(size=rel(1.3)),
            text = element_text(size=13)) +
      scale_colour_brewer(palette="Set1")
Run Code Online (Sandbox Code Playgroud)

它会改变点的颜色并添加到图例中,我不想这样做.

任何建议将不胜感激!

r ggplot2

3
推荐指数
2
解决办法
7140
查看次数

标签 统计

r ×4

ggplot2 ×3

interaction ×1

predict ×1

regression ×1

variance ×1