glm 相关问题

有关广义线性模型的问题。有关GLM数学库,请参阅[tag:glm-math]。

如何绘制逻辑回归模型 (glm) 与多重插补数据 (MICE) 的交互作用?

我创建了一个与 iv*sex 的交互项,并将数据与小鼠进行插补。然后使用估算数据运行逻辑回归模型 (glm): 型号 <- with(data=imp, glm(dv~control+iv+sex+iv*s...

回答 1 投票 0

glm::yaw 如何获得 -180 到 180 或 360 度之间的范围

我有一个四元数,我绕 y 轴旋转这个四元数。 我尝试从这个四元数中获取偏航并转换为度数,它工作得很好......直到它超过 90。 之后...

回答 1 投票 0

如何在 GLM.jl/Effects.jl 中计算和编码边际预测的置信区间?

我正在寻求帮助,了解如何计算和编写代码,以便为Effects.jl为拟合的逻辑回归模型生成的边际预测生成95%的置信区间(例如u...

回答 1 投票 0

数据排列后的零膨胀 negbin 回归警告

我正在对我的数据应用 Zeroinfl negbin 回归。具体来说,我的因变量是计数变量(中心性度量),而我的自变量/控件都是二元和连续的。 我...

回答 1 投票 0

错误:矩阵相乘时没有用户提供的默认构造函数

我有一些非常基本的代码,我认为不会导致问题: #包括 ... mat4x4 m = mat4x4(1.0f); m = 旋转(m, (浮动) glfwGetTime(), vec3(0.0f, 0.0f, 1.0f)); 我...

回答 1 投票 0

在 openGL 中使用索引缓冲区绘制立方体

#包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #include <stdio.h> #include <stdlib.h> #include <string> #include <iostream> #include <fstream> #include <vector> #include <algorithm> #include <GL/glew.h> #include <GL/glut.h> #include <GL/glm/glm.hpp> #include <GL/glm/gtx/transform.hpp> // rotate(), scale(), translate() #include <GL/glm/gtc/quaternion.hpp> #include <GL/glm/gtc/type_ptr.hpp> using namespace std; GLuint VertexArrayID; GLuint programID; float sx = 0; float sy = 0; bool projMode = true; // true: perspective, false: ortho GLuint LoadShaders(const char* vertex_file_path, const char* fragment_file_path) { //create the shaders GLuint VertexShaderID = glCreateShader(GL_VERTEX_SHADER); GLuint FragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER); GLint Result = GL_FALSE; int InfoLogLength; //Read the vertex shader code from the file string VertexShaderCode; ifstream VertexShaderStream(vertex_file_path, ios::in); if (VertexShaderStream.is_open()) { string Line = ""; while (getline(VertexShaderStream, Line)) VertexShaderCode += "\n" + Line; VertexShaderStream.close(); } //Compile Vertex Shader printf("Compiling shader : %s\n", vertex_file_path); char const* VertexSourcePointer = VertexShaderCode.c_str(); glShaderSource(VertexShaderID, 1, &VertexSourcePointer, NULL); glCompileShader(VertexShaderID); //Check Vertex Shader glGetShaderiv(VertexShaderID, GL_COMPILE_STATUS, &Result); glGetShaderiv(VertexShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength); if (InfoLogLength > 0) { vector<char> VertexShaderErrorMessage(InfoLogLength); glGetShaderInfoLog(VertexShaderID, InfoLogLength, NULL, &VertexShaderErrorMessage[0]); fprintf(stdout, "%s\n", &VertexShaderErrorMessage[0]); } //Read the fragment shader code from the file string FragmentShaderCode; ifstream FragmentShaderStream(fragment_file_path, ios::in); if (FragmentShaderStream.is_open()) { string Line = ""; while (getline(FragmentShaderStream, Line)) FragmentShaderCode += "\n" + Line; FragmentShaderStream.close(); } //Compile Fragment Shader printf("Compiling shader : %s\n", fragment_file_path); char const* FragmentSourcePointer = FragmentShaderCode.c_str(); glShaderSource(FragmentShaderID, 1, &FragmentSourcePointer, NULL); glCompileShader(FragmentShaderID); //Check Fragment Shader glGetShaderiv(FragmentShaderID, GL_COMPILE_STATUS, &Result); glGetShaderiv(FragmentShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength); if (InfoLogLength > 0) { vector<char> FragmentShaderErrorMessage(InfoLogLength); glGetShaderInfoLog(FragmentShaderID, InfoLogLength, NULL, &FragmentShaderErrorMessage[0]); fprintf(stdout, "%s\n", &FragmentShaderErrorMessage[0]); } //Link the program fprintf(stdout, "Linking program\n"); GLuint ProgramID = glCreateProgram(); glAttachShader(ProgramID, VertexShaderID); glAttachShader(ProgramID, FragmentShaderID); glLinkProgram(ProgramID); // Check the program glGetProgramiv(ProgramID, GL_LINK_STATUS, &Result); glGetProgramiv(ProgramID, GL_INFO_LOG_LENGTH, &InfoLogLength); vector<char> ProgramErrorMessage(max(InfoLogLength, int(1))); glGetProgramInfoLog(ProgramID, InfoLogLength, NULL, &ProgramErrorMessage[0]); fprintf(stdout, "%s\n", &ProgramErrorMessage[0]); glDeleteShader(VertexShaderID); glDeleteShader(FragmentShaderID); return ProgramID; } void renderScene(void) { //Clear all pixels glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //Let's draw something here glBindVertexArray(VertexArrayID); //define the size of point and draw a point. glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0); //Double buffer glutSwapBuffers(); } void mouse(int button, int state, int x, int y) { if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) { projMode = !projMode; } } void init() { //initilize the glew and check the errors. GLenum res = glewInit(); if (res != GLEW_OK) { fprintf(stderr, "Error: '%s' \n", glewGetErrorString(res)); } //select the background color glClearColor(1.0, 1.0, 1.0, 1.0); glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); glDepthRange(0.0f, 1.0f); } GLfloat cubeVertices[] = { // front -0.1f, 0.1f, 0.1f, -0.1f,-0.1f, 0.1f, 0.1f,-0.1f, 0.1f, 0.1f, 0.1f, 0.1f, -0.1f, 0.1f, 0.1f, 0.1f,-0.1f, 0.1f, // back 0.1f, 0.1f,-0.1f, -0.1f,-0.1f,-0.1f, -0.1f, 0.1f,-0.1f, 0.1f, 0.1f,-0.1f, 0.1f,-0.1f,-0.1f, -0.1f,-0.1f,-0.1f, // left -0.1f,-0.1f,-0.1f, -0.1f,-0.1f, 0.1f, -0.1f, 0.1f, 0.1f, -0.1f,-0.1f,-0.1f, -0.1f, 0.1f, 0.1f, -0.1f, 0.1f,-0.1f, // right 0.1f, 0.1f, 0.1f, 0.1f,-0.1f,-0.1f, 0.1f, 0.1f,-0.1f, 0.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1.0, }; /* idx | coord: 0 | (1,1,1) 1 | (-1, 1, 1) 2 | (-1,-1,1) 3 | (1, -1, 1) 4 | (1, -1, -1) 5 | (1, 1, -1) 6 | (-1, 1, -1) 7 | (-1, -1, -1) */ GLfloat cubeIndices[] = { // front 0, 1, 2, 0, 1, 3, // back 5, 6, 7, 5, 6, 4, // left 1, 2, 6, 1, 2, 7, // right 0, 3, 4, 0, 4, 5, // top 0, 1, 5, 0, 1, 6, // bottom 2, 3, 4, 2, 4, 7, }; int main(int argc, char** argv) { //init GLUT and create Window //initialize the GLUT glutInit(&argc, argv); //GLUT_DOUBLE enables double buffering (drawing to a background buffer while the other buffer is displayed) glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH); //These two functions are used to define the position and size of the window. glutInitWindowPosition(200, 200); glutInitWindowSize(480, 480); //This is used to define the name of the window. glutCreateWindow("Simple OpenGL Window"); //call initization function init(); //0. programID = LoadShaders("VertexShader.txt", "FragmentShader.txt"); glUseProgram(programID); /**************************************************/ // model matrix glm::mat4 model = glm::mat4(1.0f); float rotateAngle = 45.0f; glm::vec3 rotateAxis(0.0f, 1.0f, 0.0f); model = glm::rotate(model, glm::radians(rotateAngle), rotateAxis); glm::vec3 scaleVec(5.0f, 5.0f, 5.0f); model = glm::scale(model, scaleVec); glm::vec3 translateVec(0.0f, 0.0f, 0.0f); model = glm::translate(model, translateVec); // view matrix glm::mat4 view = glm::lookAt(glm::vec3(5.0f, -5.0f, -5.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f)); // proj matrix glm::mat4 proj; int width = glutGet(GLUT_WINDOW_WIDTH); int height = glutGet(GLUT_WINDOW_HEIGHT); if (projMode) { float aspectRatio = float(width) / height; proj = glm::perspective(glm::radians(45.0f), aspectRatio, 0.1f, 100.0f); } else { float orthoSize = 5.0f; proj = glm::ortho(-orthoSize, orthoSize, -orthoSize, orthoSize, 0.1f, 0.6f); } // model, view, proj matrix to shader GLint modelLoc = glGetUniformLocation(programID, "model"); glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(model)); GLint viewLoc = glGetUniformLocation(programID, "view"); glUniformMatrix4fv(viewLoc, 1, GL_FALSE, glm::value_ptr(view)); GLint projLoc = glGetUniformLocation(programID, "proj"); glUniformMatrix4fv(projLoc, 1, GL_FALSE, glm::value_ptr(proj)); /**************************************************/ glGenVertexArrays(1, &VertexArrayID); glBindVertexArray(VertexArrayID); float vtxs[] = { -0.5, 0.0, 0.0, 0.5, 0.3, 0.0 }; GLuint VBOs[3]; glGenBuffers(3, VBOs); glBindBuffer(GL_ARRAY_BUFFER, VBOs[0]); glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 3 * 3 * 2 * 6, cubeVertices, GL_STATIC_DRAW); GLuint posAttribLoc = glGetAttribLocation(programID, "inPos"); glVertexAttribPointer(posAttribLoc, 3, GL_FLOAT, GL_FALSE, 0, (GLvoid*)(0)); glEnableVertexAttribArray(posAttribLoc); glBindBuffer(GL_ARRAY_BUFFER, VBOs[1]); glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 4 * 3 * 2 * 6, cubeColors, GL_STATIC_DRAW); GLuint colAttribLoc = glGetAttribLocation(programID, "color"); glVertexAttribPointer(colAttribLoc, 4, GL_FLOAT, GL_FALSE, 0, (GLvoid*)(0)); glEnableVertexAttribArray(colAttribLoc); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, VBOs[2]); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(float) * 6 * 6, cubeIndices, GL_STATIC_DRAW); GLuint idxAttribLoc = glGetAttribLocation(programID, "index"); glVertexAttribPointer(idxAttribLoc, 3, GL_FLOAT, GL_FALSE, 0, (GLvoid*)(0)); glEnableVertexAttribArray(idxAttribLoc); glutDisplayFunc(renderScene); glutMouseFunc(mouse); //enter GLUT event processing cycle glutMainLoop(); glDeleteVertexArrays(1, &VertexArrayID); return 1; } 我想用上面的代码绘制一个 3D 立方体,但我得到一个白色的窗口。如何在窗口上显示 3D 立方体? 如果我对 VBO 和 IBO 使用像“VBOs”这样的数组,如上面的代码所示,会出现问题吗? 另外,你能告诉我如何绘制多个立方体吗? 最后,如果您告诉我我的代码中还有其他问题,我将非常感谢您。 我是一个完全的初学者,说实话,我并不完全理解图形管道。但我真的很感谢你对我的作业的帮助。 type的参数glDrawElements为整数1。 您已将索引定义为实数数组: GLfloat cubeIndices[] = { // front 0, 1, 2, 因此,当 glDrawElements 工作并读取 cubeIndices 的内存时,它会遇到一些巨大的值(例如,整数值 1 作为浮点数为 0x3f80'0000)。您定义的索引完全不在顶点属性数组确定的范围内。

回答 1 投票 0

R中glm逻辑回归模型的决定阈值

我有一些带有预测变量和二元目标的数据。例如: df <- data.frame(a=sort(sample(1:100,30)), b= sort(sample(1:100,30)), target=c(rep(0,11),rep(1,4),rep(0,4),rep(1,11))...

回答 7 投票 0

包含交互的 GLM 中的相对重要性/变异划分

我有一个关于变量相对重要性的问题,在包含交互作用(连续 * 因子)的 GLM 中。 我正在尝试一种基于分区解释的方法

回答 3 投票 0

如何解决 ChatGLM-6b 中的这个问题? AttributeError:“ChatGLMTokenizer”对象没有属性“sp_tokenizer”

“https://github.com/THUDM/ChatGLM-6B”中的默认程序在我运行 api.py 时运行。 但最近当我尝试再次运行它时,它突然出现错误:“AttributeError:'

回答 1 投票 0

在R中是否可以使用MAE(平均绝对误差)而不是RMSE作为线性回归(lm/glm)的成本函数

我正在尝试对财务数据进行一些回归,财务数据的一个问题是它往往有很多极端异常值,这些异常值可能不那么具有信息性。在 R 里...

r glm lm
回答 2 投票 0

拟合具有多个依赖变量/LHS的逻辑模型

有没有办法使用glm()进行多元逻辑回归?我有几个二元结果,我知道你可以使用线性回归 (lm()) 和 cbind() 来做到这一点,但我似乎无法弄清楚......

回答 1 投票 0

逐步回归每一步的系数

我在 R 中使用逐步回归,代码如下: model_scicareer_all <- glm(scicareer ~ ., family = binomial(link = "logit"), data = clean_data) summary(

r glm
回答 3 投票 0

R 中逐步回归每一步的系数

我在 R 中使用逐步回归,代码如下: model_scicareer_all <- glm(scicareer ~ ., family = binomial(link = "logit"), data = clean_data) summary(

回答 1 投票 0

如何引导 glm 回归,估计 95% 置信区间并绘制它?

我正在使用 0-1 分布数据集进行 glm 回归。与 ggplot2::geom_smooth 配合得很好;这是我的代码: 库(ggplot2) 设置.种子(123) df = data.frame(Conc = runif(200, min = 200...

回答 1 投票 0

如何引导glm回归并估计95%置信区间?

我正在使用 0-1 分布数据集进行 glm 回归。与 ggplot2::geom_smooth 配合得很好;这是我的代码: 库(ggplot2) 设置.种子(123) df = data.frame(Conc = runif(200, min = 200...

回答 1 投票 0

caret train() 预测与 Predict.glm() 非常不同

我正在尝试使用 10 倍交叉验证来估计逻辑回归。 #导入库 图书馆(汽车);库(插入符号);图书馆(e1071);库(验证) #数据导入和准备...

回答 1 投票 0

根据 glm 输出计算优势比

这是我第一次进行逻辑回归,我目前正在尝试自学如何找到优势比。我从 r 中得到了系数,如下所示。 (拦截)总计分钟 ...

回答 1 投票 0

“$ 运算符对于原子向量无效”错误如何解决?

我正在尝试使用贝叶斯 GLM 执行 CAPM 回归分析。我已经开发了下面的 R 代码,但是当我尝试拟合后验预测检查后验截距的模型时 <-

回答 1 投票 0

尝试在 R 中使用泊松分布拟合 glmer 时出错:PIRLS 步骤减半未能减少 pwrssUpdate 中的偏差

我运行的模型不会收敛/显示错误。您对使用非正态焦点数据有什么建议吗?大多数数据都是零膨胀或高度倾斜的。 我想要运行的模型是

回答 1 投票 0

如何从glm等模型中提取系数表的相关性?

在 R 中运行统计模型(例如,glm、lm、lme4::lmer 等)后,我使用 corr=TRUE 运行summary() 命令来获取系数相关性表。它具有相关矩阵...

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.